Page 1 of 1

Array issue, help needed plz

Posted: Fri Apr 06, 2007 11:42 am
by ianhull
I have this

Code: Select all


$myName = $_SESSION['user']['firstname'] . " " . $_SESSION['user']['lastname'];
	include_once("../connection.php");
	$calendarAppointments = mysql_query("SELECT id, name, appointment_day, appointment_month, appointment_year FROM currentappointments WHERE name = '$myName'")or die(mysql_error());
	
	
	while ($calendarList = mysql_fetch_array($calendarAppointments))    
    {
    extract($calendarList);
}
    $time = time(); 
    $today = date('j',$time);
    $days = array(
    2=>array('/calendar_day.php?id='.$id.'','linked-day'),
		$today=>array(NULL,NULL,'<span class="warning">'.$today.'</span>'));
	echo generate_calendar(date('Y', $time), date('n', $time), $days);

it all works great as it is but I need to somehow change the number 2 on the array for the number from that database which is stored in a vriable called $appointment_day

I have tried allsorts with no luck..

Anyone got any ideas?

thanks

Posted: Fri Apr 06, 2007 11:57 am
by bubblenut
The issue lies in how you're handling the loop. What you're doing in the code you provided is running the query, looping over the results extracting the variables, each iteration overwriting the previous, then building an array based on the last line and generating the calendar. What you need to be doing is adding to the days array each iteration. Take a look at the code below, you can see that I have moved the code for the $days array inside while loop.

Code: Select all

$myName = $_SESSION['user']['firstname'] . " " . $_SESSION['user']['lastname'];
include_once("../connection.php");
$calendarAppointments = mysql_query("SELECT id, name, appointment_day, appointment_month, appointment_year FROM currentappointments WHERE name = '$myName'")or die(mysql_error());


$time  = time();
$today = date('j', $time);
$days  = array();
while ($calendarList = mysql_fetch_array($calendarAppointments))
{
    extract($calendarList);
    $days[ $appointment_day ] = array(
        '/calendar_day.php?id=' . $id, 'linked-day',
        $today => array(
            null, null, '<span class="warning">' . $today . '</span>'
        )
    );
}
echo generate_calendar( date('Y', $time), date('n', $time), $days );

Posted: Fri Apr 06, 2007 12:00 pm
by ianhull
bubblenut your a superstart :D

Thanks very much,

Hugely appreciated