Jump to content

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.
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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.