Jump to content

[SOLVED] if array has info echo


adam291086

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/80473-solved-if-array-has-info-echo/
Share on other sites

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.

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

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.

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

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?

 

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.

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']

 

 

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.

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.