Solved

PHP: Convert 2 Field Recordset to an Array

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
restriction of entering a a page 5 44
Find RGB colors from a screen. 2 39
phpmyadmin memory error 55 91
How to open a new browser tab after executing php script 20 46
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

737 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