Jump to content

Archived

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

defcon2000

Putting Data into a Multi-Dimentional Array

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 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 "192.168.0.10" using "serveraddress" in an array type format.

Thanks in advance for your help.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

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.