Page 1 of 1

listing results?

Posted: Fri Apr 23, 2010 10:04 pm
by me!
I know this is a stupid question but how do I make this work like I want it to. I know I have done it before but for some reason I cant see it tonight. :crazy:

What I want is to get the event_id and event name from the events table and list them as ID event. (only two things in the table)
This is what i have but is does not exactly work.

Code: Select all

//get events from db
		$results = mysql_query("SELECT * FROM events");
			while ($mysql = mysql_fetch_array($results)) 
						{
						foreach( $mysql as $id => $event){
								echo "ID: $id, Event: $event <br />";
							}

						}

Re: listing results?

Posted: Sat Apr 24, 2010 8:42 am
by social_experiment
Try :

Code: Select all

<?php $results = mysql_query("SELECT * FROM events");
 while ($mysql = mysql_fetch_array($results)) {
  echo 'ID : '.$mysql['id'];
  echo 'Event : '.$mysql['event'];
  echo '<br />';
 }
 ?>
You should also check if there are actually data inside the table and depending on that result either echo the data or a message indicating 0 rows in the table.

Re: listing results?

Posted: Sat Apr 24, 2010 9:24 am
by me!
Yep it's amazing how sleep can help with things, just look at this again and came up with:

Code: Select all

//get events from db
		$results = mysql_query("SELECT * FROM events");
			while ($mysql = mysql_fetch_array($results)) 
						{
						echo "ID: ".$mysql["id"]." and the event is ".$mysql["event"]." <br />";
						}
I kept looking at this last night and it was not coming to me, but I knew I had done it hundreds of times before! :wink:

Thanks for the reply social_experiment.