[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

PHP: Convert 2 Field Recordset to an Array

Posted on 2009-04-03
2
Medium Priority
?
770 Views
Last Modified: 2013-12-12
Using PHP MySQL

I'm looking to convert a 2 field recordset into an array.

The recordset simply contains RecordID, RecordName with around 50 records.

I want to create an array with IDs and Names from the recordset so they link to the records name, like this...

$Array[RecordID] = RecordName

I then want to list a set of values on my page that link the value from a url parameter to the array.

echo $Array[ $URL_Value01 ]
echo $Array[ $URL_Value02 ]
echo $Array[ $URL_Value03 ]
etc...

The code i'm currently using doesn't quite work.

do {
$NewArray = array();
$NewArray = array($row_rs['rs_field_ID'], $row_rs['rs_field_name']);
echo $NewArray[$URL_Param01]." <br/>";
echo $NewArray[$URL_Param02]." <br/>";
echo $NewArray[$URL_Param03]." <br/>";
} while ($row_rs = mysql_fetch_array($rs));

Only URL values of 0 or 1 return a result value - either a complete list of RecordID's or RecordName's.

Thanks for any help.

0
Comment
Question by:ticallian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 2000 total points
ID: 24058290
To create the array, something like this will do it

$NewArray = array();
$rs = mysql_query("select RecordID, RecordName from myTable where ..... ");
if ( $rs )
     while ( $rw = mysql_fetch_assoc($rs) )
          $NewArray [ $rw['RecordId'] ] = $rw['RecordName'];


I don't understand what you are trying to do with the URLs. Could you clarify that for me?
     
0
 

Author Comment

by:ticallian
ID: 24058414
Thank you very much! That done the trick perfectly.

Basically i've created a search facility for a site, the URL parameters are used by a different recordset to filter the actual results.

The array above is linked to a seperate recordset i've created just to add some user-friendly options to manipulate the search results.

Cheers!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question