Forum Moderators: coopster

Message Too Old, No Replies

problems with loops + database + arrays + indexes

         

furtivefelon

5:21 pm on Aug 15, 2004 (gmt 0)

10+ Year Member



$monthN = '0'.$month;
$index = array;
if (!isset ($counter))
{
$counter = 0;
}
while ($dbRow = mysql_fetch_assoc($dbResult))
{
$date = $dbRow['date'];
$date = explode("-", $date, 3);
if ($date[0] == $year)
{
if ($date[1] == $monthN)
{
$counter++
$index = array(
array($counter, $dbRow['date'], $dbRow['topic'], $dbRow['description'], $dbRow['content']);
print ("<tr><table><td>{$dbRow['date']} :: </td><td><a href='{$dbRow['topic']}'>{$dbRow['topic']}</a></td><table></tr>\n");

}
}
}

ok, there is several problems in this.. i'm trying to access the database and telling the database to put one row at a time into the array $dbRow, and then display each element of the array after a specific condition is met.. the problem is, this is a calender's notes program, so i only want it to display the date ::: topic, and not to display the description and content, though both discription and content are part of the array i took from the database.. so i want to display the description upon request, and when user clicks on one of the topics, it will automatically find and display rest of the content associating to the topic.. i tried to achieve that with a index of all the useful rows i took from the database, and store them at a array, and take them upon request.. but i met several blunders, so can someone guide me as to how to fix this? thank you very much!

ps, if you need any clearfication on anything, feel free to ask...

coopster

8:07 pm on Aug 16, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I've cleaned things up to get you started. Note: I've added comments to show where your initial errors are...
// unnecessary, PHP will convert before comparing... 
//$monthN = '0'.$month;
$index = array(); // parse error if you forget parentheses
if (!isset ($counter)) {
$counter = 0;
}
while ($dbRow = mysql_fetch_assoc($dbResult)) {
$date = $dbRow['date'];
$date = explode("-", $date, 3);
if ($date[0] == $year) {
//unnecessary, PHP will convert before comparing...
// if ($date[1] == $monthN) {
if ($date[1] == $month) {
$counter++; // forgot the terminating semicolon...
$index = array(
// array( // you doubled the array keyword...
$counter, $dbRow['date'], $dbRow['topic'],
$dbRow['description'], $dbRow['content']);
print ("<tr><table><td>{$dbRow['date']} :: </td>
<td><a href='{$dbRow['topic']}'>{$dbRow['topic']}</a></td><table></tr>\n");
}
}
}