Jump to content

[SOLVED] Get contents of an array from database


iceblox

Recommended Posts

Hi Guys.

 

I have an array in my script and id like to get the data from a table in my database. Im having difficulties with this and was looking for some help.

 

This is what the array looks like;

 

$arr = array("E63" => "78",
"Bold" => "" );

 

This is currently what i have

 

$query = "SELECT * FROM errordata WHERE MerchantID = '98'";
$result = mysql_query($query);
if (mysql_num_rows($result) > 0)
{
$arr = array(
while($row = mysql_fetch_array($result))
{
echo "\"$row[error_text]\" => \"$row[correct_id]\", ";
}

}
else
{
echo 'No rows found!';
}

echo "\"\" => \"\");";

 

Im getting an error from this line $arr = array( which i think is because i have left the brackets open but im not sure where i should put this. Or am i doing it all wrong?

 

Any ideas would be greatly appreciated.

 

Thanks, Phil

Hi Ken thanks for you reply.

 

I have created a database table with the data that id like in that array, so rather than having 

 

$arr = array("E63" => "78",
"Bold" => "" );

 

in my code. I would like to change it so that it grabs that information in the array from a database.

 

That is what i tried to achieve with the query.

 

Does what im trying to achieve make sense?

 

Thanks, Phil

$arr = array();
$query = "SELECT * FROM errordata WHERE MerchantID = 98";
$result = mysql_query($query);
if (mysql_num_rows($result) > 0) {
     while($row = mysql_fetch_array($result)) $arr[$row['error_text']] = $row['correct_id'];
} else {
   echo 'No rows found!';
}

 

Understand that?

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.