Solved

PHP: Convert 2 Field Recordset to an Array

Posted on 2009-04-03
2
757 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
2 Comments
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now