iceblox Posted May 19, 2009 Share Posted May 19, 2009 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 Link to comment https://forums.phpfreaks.com/topic/158753-solved-get-contents-of-an-array-from-database/ Share on other sites More sharing options...
Ken2k7 Posted May 19, 2009 Share Posted May 19, 2009 $arr = array( You left that opened. Also, what are you trying to do? Link to comment https://forums.phpfreaks.com/topic/158753-solved-get-contents-of-an-array-from-database/#findComment-837281 Share on other sites More sharing options...
iceblox Posted May 19, 2009 Author Share Posted May 19, 2009 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 Link to comment https://forums.phpfreaks.com/topic/158753-solved-get-contents-of-an-array-from-database/#findComment-837288 Share on other sites More sharing options...
Ken2k7 Posted May 19, 2009 Share Posted May 19, 2009 $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? Link to comment https://forums.phpfreaks.com/topic/158753-solved-get-contents-of-an-array-from-database/#findComment-837297 Share on other sites More sharing options...
iceblox Posted May 19, 2009 Author Share Posted May 19, 2009 Hi Ken, Thanks for that query, worked a treat!! Thanks again for your help!! Phil Link to comment https://forums.phpfreaks.com/topic/158753-solved-get-contents-of-an-array-from-database/#findComment-837309 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.