MySQL Arrays and reading through the data.

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
4_D
Forum Newbie
Posts: 2
Joined: Thu Jun 03, 2004 7:40 am

MySQL Arrays and reading through the data.

Post by 4_D »

Hi.

I'm very new to PHP, and apologies if this is covered elsewhere.

I'm not getting any errors, it's just not doing what I would like it to.

I have some PHP that generates a monthly calendar table, depending on month and year selections from a drop down box.

The page also runs an SQL query to retieve event information from a MySQL database. The info is stored in an array.

What I'm trying to do is when it creates the table cell for a day, it checks the array to see if there is an event for that day and puts the title in if there is. I managed to make it work by running the query for each day, but this presents the database with 30/31 queries for a month, not a good way to do it.

It creates the full month, it just doesn't place any event info in the days.

This is part of the SQL Query (generated in Dreamweaver)

Code: Select all

mysql_select_db($database_calendar, $calendar);
$query_events = sprintf("SELECT event_id, Username, ent_title, MONTH(date), RIGHT(date,2) FROM calendar WHERE Username = '%s' AND MONTH(date) = '%s' ", $colname_events,$eventMonth_events);
$query_limit_events = sprintf("%s LIMIT %d, %d", $query_events, $startRow_events, $maxRows_events);
$events = mysql_query($query_limit_events, $calendar) or die(mysql_error());
$row_events = mysql_fetch_assoc($events);
This is the code where the even infoe should be placed when it creates the day cells.

Code: Select all

//Setup event array.
$event_array = array($newDay, $entry);

//Link added to pass url parameters to add event page.

		print ">$daycount<br><a href="add_event.php?eventDate=$year-$month-$daycount">Add</a><br>\n";
		
	 	if ($newDay == $daycount) {
		while ($row = mysql_fetch_array($row_events)) {
		print "<a href="event_details?event_id=$event_id">$entry</a></td>\n";}
	 }
		Else {print "</td>\n";}

	}
		
	// close table row if it is saturday
any ideas to what I'm doing wrong?

Thanks in advance for any help and advice.
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

You could try to remove the last line from the SQL Query (generated in Dreamweaver)

Code: Select all

$row_events = mysql_fetch_assoc($events);
and change the while statement from

Code: Select all

while ($row = mysql_fetch_array($row_events)) {
    print "<a href="event_details?event_id=$event_id">$entry</a></td>\n";}
to

Code: Select all

while ($row_events = mysql_fetch_assoc($events)) // [php_man]mysql_fetch_assoc[/php_man]()
    print "<a href="event_details?event_id=" . $row_events['event_id'] . "">" . $row_events['ent_title'] . "</a></td>\n";
and tell us what you get.

-- Scorphus
4_D
Forum Newbie
Posts: 2
Joined: Thu Jun 03, 2004 7:40 am

Post by 4_D »

Hi.

It's not actually displaying anything now, I have some code at the bottom, out of the table, just to show the results of the query and that it's bringing back results and that's showing nothing.
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

4_D, could you please post the entire code, if you can. I would like to have a better idea of what is going on. Also this would be nice if you show us the structure of the db tables (fields and types), the design of your database.

Thanks,
Scorphus.
Post Reply