adam291086 Posted December 6, 2007 Share Posted December 6, 2007 I have a query and i store some information into an array $arrDays = array(); $arrEvent = array(); while($row = mysql_fetch_array($result)) { $arrDays[] = $row['Day'] ; $Month = $row['Month'] ; $Year = $row['Year'] ; $arrEvent[] = $row['Event Details']; } How do i go about echoing all information in arrEvent[] while there is information in it? Quote Link to comment https://forums.phpfreaks.com/topic/80473-solved-if-array-has-info-echo/ Share on other sites More sharing options...
kenrbnsn Posted December 6, 2007 Share Posted December 6, 2007 You can use the print_r() function to dump it: <?php echo '<pre>' . print_r($arrEvent,true) . '</pre>'; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/80473-solved-if-array-has-info-echo/#findComment-407973 Share on other sites More sharing options...
adam291086 Posted December 6, 2007 Author Share Posted December 6, 2007 that hasn't work. What i want to do is set a variable to = a result in an array. Then echo out this variable. I am trying to make a popup for my calendar. So when a user hovers over an event date the event details are displayed in the pop up. I have the pop up working but no data from my database. Quote Link to comment https://forums.phpfreaks.com/topic/80473-solved-if-array-has-info-echo/#findComment-407986 Share on other sites More sharing options...
revraz Posted December 6, 2007 Share Posted December 6, 2007 If you have ever used PHPBB, there is a Calendar Mod that someone made for it. It may be worth looking an his source code because he also has pop ups like that. Quote Link to comment https://forums.phpfreaks.com/topic/80473-solved-if-array-has-info-echo/#findComment-407988 Share on other sites More sharing options...
adam291086 Posted December 6, 2007 Author Share Posted December 6, 2007 i have never used phpbb, my script is so close, just need this last method Quote Link to comment https://forums.phpfreaks.com/topic/80473-solved-if-array-has-info-echo/#findComment-407995 Share on other sites More sharing options...
kenrbnsn Posted December 6, 2007 Share Posted December 6, 2007 That's not what you asked in your original question. I answered your original question How do i go about echoing all information in arrEvent[] while there is information in it? What you really need to do is identify which event goes with which day, so change your code to be something like: <?php $arrDays = array(); $arrEvent = array(); while($row = mysql_fetch_array($result)) { $arrDays[] = $row['Day'] ; $Month = $row['Month'] ; $Year = $row['Year'] ; $arrEvent[$month . $row['Day'] . $Year] = $row['Event Details']; } ?> Then when you want an event, just get the date and use the date as the index into the $arrEvent array. Ken Quote Link to comment https://forums.phpfreaks.com/topic/80473-solved-if-array-has-info-echo/#findComment-408004 Share on other sites More sharing options...
adam291086 Posted December 6, 2007 Author Share Posted December 6, 2007 sorry for ths confusion before, just getting excited as i have been working on this for a few days. I am still learning php and dont understand how to index into the array. Could you possibly help? i need to index into an array and set that result as a varible i can echo. Quote Link to comment https://forums.phpfreaks.com/topic/80473-solved-if-array-has-info-echo/#findComment-408010 Share on other sites More sharing options...
adam291086 Posted December 6, 2007 Author Share Posted December 6, 2007 ok i now have the date searching the array, but how do i get a bit of information from the array $arrEvent echoed out? if (in_array($arrEvent[$thismonth . $counter . $thisyear])); echo "blah"; Quote Link to comment https://forums.phpfreaks.com/topic/80473-solved-if-array-has-info-echo/#findComment-408037 Share on other sites More sharing options...
revraz Posted December 7, 2007 Share Posted December 7, 2007 I would like to see this when you are done. I'm still working on mine as well. Quote Link to comment https://forums.phpfreaks.com/topic/80473-solved-if-array-has-info-echo/#findComment-408598 Share on other sites More sharing options...
revraz Posted December 7, 2007 Share Posted December 7, 2007 Looks like Adam and I are at the same spot. If he's doing it along the same lines I am, we have more than 1 event for a day. So I do have an event array like this: $reservations[7122007] = array(array ("time"=>"7:00am", "desc"=>"Description"), array("time"=>"7:00pm", "desc"=>"Description2")); And my echo echo "<td width='14%'>$day_num<br /> <font size='-1'>{$reservations[$day_num.$month.$year][$x]['time']['desc']}</font></td>"; But how do I know how many times to move the $x above? I could have 1 or 4 events in that index. That's not what you asked in your original question. I answered your original question How do i go about echoing all information in arrEvent[] while there is information in it? What you really need to do is identify which event goes with which day, so change your code to be something like: <?php $arrDays = array(); $arrEvent = array(); while($row = mysql_fetch_array($result)) { $arrDays[] = $row['Day'] ; $Month = $row['Month'] ; $Year = $row['Year'] ; $arrEvent[$month . $row['Day'] . $Year] = $row['Event Details']; } ?> Then when you want an event, just get the date and use the date as the index into the $arrEvent array. Ken Quote Link to comment https://forums.phpfreaks.com/topic/80473-solved-if-array-has-info-echo/#findComment-408659 Share on other sites More sharing options...
revraz Posted December 7, 2007 Share Posted December 7, 2007 This may do it $ac = count ($reservations[$day_num.$month.$year]); Quote Link to comment https://forums.phpfreaks.com/topic/80473-solved-if-array-has-info-echo/#findComment-408662 Share on other sites More sharing options...
adam291086 Posted December 7, 2007 Author Share Posted December 7, 2007 ok that tells me there are three bits of information in the array. $result = mysql_query( " SELECT * FROM `table` WHERE `Month` = $thismonth AND `Year` = $thisyear") or die('Query failed. ' . mysql_error()); $arrDays = array(); $arrEvent = array(); while($row = mysql_fetch_array($result)) { $arrDays[] = $row['Day'] ; $Month = $row['Month'] ; $Year = $row['Year'] ; $arrEvent[] = $row['Event Details']; $adam = $row['Event Details']; } $ac = count ($arrEvent); echo $ac; how do i get it to echo the actual database information? Quote Link to comment https://forums.phpfreaks.com/topic/80473-solved-if-array-has-info-echo/#findComment-408678 Share on other sites More sharing options...
revraz Posted December 7, 2007 Share Posted December 7, 2007 I didn't do it his way, this is how I'm doing it $ac = count ($reservations[$day_num.$month.$year]); //count how many reservations for today for ($x=0;$x < $ac;$x++) { echo "<font size='-2'>{$reservations[$day_num.$month.$year][$x]['desc']}</font><br />"; //echo each reservation for the day } echo "</td>"; //close the day when done Of course, this is after loading the Array from the database. Quote Link to comment https://forums.phpfreaks.com/topic/80473-solved-if-array-has-info-echo/#findComment-408687 Share on other sites More sharing options...
adam291086 Posted December 7, 2007 Author Share Posted December 7, 2007 i now have no hair :-\ :-\ Ok i have this code and it works fine $arrDays = array(); $arrEvent = array(); while($row = mysql_fetch_array($result)) { $arrDays[] = $row['Day'] ; $Month = $row['Month'] ; $Year = $row['Year'] ; $arrEvent[$row['Day']] = $row['Event Details']; $adam = $row['Event Details']; } if (in_array($counter,$arrEvent)); { } What i need to do is echo out the $arrEvent information when the counter = $row['Day'] Quote Link to comment https://forums.phpfreaks.com/topic/80473-solved-if-array-has-info-echo/#findComment-408711 Share on other sites More sharing options...
revraz Posted December 7, 2007 Share Posted December 7, 2007 What was easier for me to do was in the first array index, my index number is the day.month.year, so for today, my array is $reservation[7122007]. Inside that array, I have another array for how may reservations are for today. $reservation[7122007][0][description]. I set [0] to a variable and go through it as many time as there are indexes and echo them. Quote Link to comment https://forums.phpfreaks.com/topic/80473-solved-if-array-has-info-echo/#findComment-408914 Share on other sites More sharing options...
adam291086 Posted December 7, 2007 Author Share Posted December 7, 2007 i am confused, can you some me some code Quote Link to comment https://forums.phpfreaks.com/topic/80473-solved-if-array-has-info-echo/#findComment-408918 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.