Array issue, help needed plz

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Array issue, help needed plz

Post 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
bubblenut
Forum Newbie
Posts: 20
Joined: Sat Feb 03, 2007 4:16 am
Location: London

Post 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 );
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Post by ianhull »

bubblenut your a superstart :D

Thanks very much,

Hugely appreciated
Post Reply