Jump to content

Putting Data into a Multi-Dimentional Array


defcon2000

Recommended Posts

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:

[b]Id parameter detail[/b]
1 smtpserveraddress blowfish.com
2 serveraddress 192.168.0.10
3 copyinvoiceto [email protected]
4 billingemailaddress [email protected]
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 "192.168.0.10" using "serveraddress" in an array type format.

Thanks in advance for your help.
Try
[code]
$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'];
}[/code]


Now

[code]echo $param['serveraddress'];[/code]

--> 192.168.0.10

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.