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
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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.