The Midnighter Posted December 15, 2008 Share Posted December 15, 2008 Good day, I'm having trouble putting data from MySQL into my array. Here's what I've got: <?php require("../api/cal.api"); $connect = db_connect(); mysql_select_db($GLOBALS["db"]); $query = "SELECT * FROM calendar_messages WHERE msg_id='$id'"; $result = mysql_query($query); if( !$result ){ echo mysql_error() . ": " . mysql_errno(); } $event = mysql_fetch_array($result); $event["msg_text"] = str_replace("<br> <br>\n" , "\n\n" , $event["msg_text"]); mysql_close($connect); $splashtext = "Modify <b>" . $event["msg_title"] . "</b> for " . $event["msg_month"] . "/" . $event["msg_day"] . "/" . $event["msg_year"]; if( $event["msg_recurring"] ) $splashtext .= " (and associated recurring events)"; ?> My problem is, $event seems to come out as an empty array. Any idea why? Quote Link to comment https://forums.phpfreaks.com/topic/137057-solved-php-mysql-question/ Share on other sites More sharing options...
webref.eu Posted December 15, 2008 Share Posted December 15, 2008 Check that you don't have a problem with array types. There are two types of array, associative and numeric. If you have an associative array you have to use field names to display data, if numeric then you have to use field array positions. http://www.w3schools.com/PHP/func_mysql_fetch_array.asp So check that the type of array you are calling and the technique to display your data (field name or field array positions) match. Rgds Quote Link to comment https://forums.phpfreaks.com/topic/137057-solved-php-mysql-question/#findComment-715819 Share on other sites More sharing options...
mmarif4u Posted December 15, 2008 Share Posted December 15, 2008 Try this: $msg = str_replace("<br> <br>\n" , "\n\n" , $event["msg_text"]); Change the remaining variables. But if you want to loop your values. you can use while loop for it. Quote Link to comment https://forums.phpfreaks.com/topic/137057-solved-php-mysql-question/#findComment-715822 Share on other sites More sharing options...
The Midnighter Posted December 15, 2008 Author Share Posted December 15, 2008 Actually, the problem was quite silly, I'm surprised no one else caught on. Look at the variable $id, it's coming from thin air! .. I forgot the $id = $_POST["id"]; Quote Link to comment https://forums.phpfreaks.com/topic/137057-solved-php-mysql-question/#findComment-715823 Share on other sites More sharing options...
premiso Posted December 15, 2008 Share Posted December 15, 2008 $query = "SELECT * FROM calendar_messages WHERE msg_id='$id'"; Where is $id being set? I do not see it anywhere in the code? Quote Link to comment https://forums.phpfreaks.com/topic/137057-solved-php-mysql-question/#findComment-715824 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.