thomasw_lrd Posted November 4, 2011 Share Posted November 4, 2011 Here is my code // Show the events for this day: $getEvent_sql = "SELECT cal_title, cal_description, date_format(cal_start_time, '%l:%i %p') as fmt_date FROM calendar WHERE month(cal_start_time) = '".$m."' AND dayofmonth(cal_start_time) = '".$d."' AND year(cal_start_time)= '".$y."' ORDER BY cal_start_time"; $getEvent_res = myload($getEvent_sql); echo "<pre>"; print_r($getEvent_res); echo "</pre>"; if (count($getEvent_res) > 0){ $event_txt = "<ul>"; while($ev = mysql_fetch_array($getEvent_res)){ echo "Inside"; echo $ev; $event_title = stripslashes($ev["cal_title"]); $event_shortdesc = stripslashes($ev["cal_description"]); $fmt_date = $ev["fmt_date"]; $event_txt .= "<li><strong>".$fmt_date."</strong>: ".$event_title."<br/>".$event_shortdesc."</li>"; echo $event_title; } $event_txt .="</ul>"; mysql_free_result($getEvent_res); } else { $event_txt = ""; } if ($event_txt != ""){ echo "<p><strong>Today's Events:</strong></p> $event_txt <hr/>"; } I can't get inside the while loop. The array is populated, I've checked that. The count of $getEvent_res = 3. echo "Inside", and echo $ev give me nothing. Any ideas what I'm doing wrong? $getEvent_res = myload($getEvent_sql); The myload is a custom function that just works, I didn't write it, but I know it works. Quote Link to comment https://forums.phpfreaks.com/topic/250443-mysql_fetch_array-help/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 4, 2011 Share Posted November 4, 2011 $getEvent_res is (likely) an array. You cannot use mysql_ functions on it because it is not a mysql result resource. What exactly does echo "<pre>"; print_r($getEvent_res); echo "</pre>"; show? And you should have error_reporting set to E_ALL and display_errors set to ON so that php will report and display all the errors it detects. You would be getting an error at the mysql_fetch_array() statement alerting you to the fact that $getEvent_res isn't a mysql result resource. Quote Link to comment https://forums.phpfreaks.com/topic/250443-mysql_fetch_array-help/#findComment-1284930 Share on other sites More sharing options...
thomasw_lrd Posted November 4, 2011 Author Share Posted November 4, 2011 Yeah, I keep forgetting about the error reporting. I really need to turn that on. I found the problem. My date is not being selected correctly. Out of $getEvent_res is Array ( [0] => Array ( [0] => Test [cal_title] => Test [1] => Tesing [cal_description] => Tesing [2] => 1:00 AM [fmt_date] => 1:00 AM ) [1] => Array ( [0] => 1 [cal_title] => 1 [1] => 1 [cal_description] => 1 [2] => 1:00 AM [fmt_date] => 1:00 AM ) [2] => Array ( [0] => 1 [cal_title] => 1 [1] => 1 [cal_description] => 1 [2] => 1:00 AM [fmt_date] => 1:00 AM ) [3] => Array ( [0] => 1 [cal_title] => 1 [1] => 1 [cal_description] => 1 [2] => 4:00 AM [fmt_date] => 4:00 AM ) $getEvent_sql = "SELECT cal_title, cal_description, date_format(cal_start_time, '%l:%i %p') as fmt_date FROM calendar WHERE month(cal_start_time) = '".$m."' AND dayofmonth(cal_start_time) = '".$d."' AND year(cal_start_time)= '".$y."' ORDER BY cal_start_time"; The preceding code is supposed to select the date, but it only selects the time. I'm starting on it right now, but any suggestions are greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/250443-mysql_fetch_array-help/#findComment-1284945 Share on other sites More sharing options...
PFMaBiSmAd Posted November 4, 2011 Share Posted November 4, 2011 You would use a foreach loop to iterate over an array. Quote Link to comment https://forums.phpfreaks.com/topic/250443-mysql_fetch_array-help/#findComment-1284951 Share on other sites More sharing options...
thomasw_lrd Posted November 4, 2011 Author Share Posted November 4, 2011 You are correct. Once I chagned it to a foreach loop, it displays just like it should. Thank you very much for all your help. Quote Link to comment https://forums.phpfreaks.com/topic/250443-mysql_fetch_array-help/#findComment-1284959 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.