Jump to content


Putting Data into a Multi-Dimentional Array

  • Please log in to reply
1 reply to this topic

#1 defcon2000

  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 29 March 2006 - 08:22 AM

Hello All,

We have a table in MySQL that we extract into an array as follows:

$tmpdetails = mysql_query("SELECT * FROM params", $conn) or die('Query failed: ' . mysql_error());

$details = mysql_fetch_array($tmpdetails, MYSQL_ASSOC);

The table is called params and has the following fields and data:

Id parameter detail
1 smtpserveraddress blowfish.com
2 serveraddress
3 copyinvoiceto jane@blowfish.com
4 billingemailaddress billing@blowfish.com
5 localcurrencysymbol GMD

We want to be able to access the result without having to loop through the array. We want to use the results of parameter as a reference point to access detail.

For example, we want to access the result "" using "serveraddress" in an array type format.

Thanks in advance for your help.

#2 Barand

  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 29 March 2006 - 07:50 PM

$tmpdetails = mysql_query("SELECT * FROM params", $conn) or die('Query failed: ' . mysql_error());

$param = array();
while ($details = mysql_fetch_array($tmpdetails, MYSQL_ASSOC)) {
       $param[$details['parameter']] = $details['detail'];


echo $param['serveraddress'];

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received


|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users