Solved

PHP: Convert 2 Field Recordset to an Array

Posted on 2009-04-03
2
755 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

759 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

18 Experts available now in Live!

Get 1:1 Help Now