Forum Moderators: coopster
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$dbday=$row['day'];
$dbmonth=$row['month'];
$dbyear=$row['year'];
$link = "";
if ($day == $dbday && $month == $dbmonth && $year == $dbyear)
{
$link = "displaymatches.php?day=$day&month=$month&year=$year";
}
return $link;
}
include 'close.php';
}
The value that works is the first record in my table of "29". So 29 links correctly on the calendar, but my DB wont show the other days as a link. Any ideas please?!
Thanks
Try to see how many times loop is done:
cnt = 0;
while(...)
{
...
cnt++;
}echo "<br>Counter: ".$cnt;
Also see, if you're correctly entering into the if clause. Why do you display only one displaylink? Where are you "return"ing from, when you don't have any function?
Hope these questions add some light to what you're trying to achieve.
function getDateLink($day, $month, $year)
{
include 'open.php';
$query="Select * From challenge";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$dbday=$row['day'];
$dbmonth=$row['month'];
$dbyear=$row['year'];
$link = "";
if ($day == $dbday && $month == $dbmonth && $year == $dbyear)
{
$link = "displaymatches.php?day=$day&month=$month&year=$year";
}
return $link;
}
include 'close.php';
}
This code should be linking dates on the calendar, where there is an entry in the DB. It only links the first result (29th jan 2005) But there are other entries such as (17th jan 2005) which are not appearing on my calendar! :(
I think its the while loop only returning the first record over and over. How can i make it return them all!
thankyou for your time
The real thing why it isn't working is that variables $day are not being changed in the loop.
eg at first "while" you got $dbday = 29;, and $day id 29;, so you enter the if statement, and write the link.
on the second loop you get $dbday = 17;, but $day is still unchanged and equals 29, so the loop doesn't enter if.
If that's not the problem, then check as I suggested how many times the loop is being done. And also good idea would be to see what the loop is writing under $dbday, $dbmonth and $dbyear
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$dbday .= $row['day']."; ";
$dbmonth .= $row['month']."; ";
$dbyear .= $row['year']."; ";
}
echo $dbday."<br>".$dbmonth."<br>".$dbyear
If i echo dbday."<br>".$dbmonth."<br>".$dbyear ;
It displays
29; 17; 13; 13; 28; <------ days
1; 1; 1; 1; 1; <------- month
2005; 2005; 2005; 2005; 2005; <--- year
So the following days should be lighting up, 29th 17th 13th 13th and 28th but only the 29th lights up! Therefore it is only allowing the 1st record to light up on my calendar. Would this require a new if statement?
Thanks again
(im new to using '.' )
Thanyou!
edit.... i got a bit excited :( that didnt work at all. It lit up every single day! DOH!
Ah the $link variable is storing the same value over and over again..
displaymatches.php?day=29&month=1&year=2005displaymatches.php?day=29& month=1&year=2005displaymatches.php?day=29&month=1& year=2005displaymatches.php?day=29&month=1& year=2005displaymatches.php?day=29&month=1&year=2005
hmmm! How do i change it to store the other values? Is a . needed?
[edited by: jatar_k at 5:56 pm (utc) on Jan. 25, 2005]
[edit reason] fixed sidescroll [/edit]