Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outputting all id's

Status
Not open for further replies.

7724

Programmer
Feb 25, 2005
28
GB
Bit stuck here!!!!!!

I have an admin section which has a table with 'events' listings in them. Now each listing which has it's own individual ID:

Now what I want my php page to do is to look in this 'events' table and output each of the records in the table for each id in date order on one page.

Those records will contain data for three variable $name, $date, $details which will be outputted on the page in a table each time there is an id.

But i'm not sure bout doing this - anyone help?

Ta

Chris
 
What do you mean by 'table'?
a) HTML <table>
b) a table in a database

Assuming b) should be output into a) and that db server is MySQL:
Code:
<?
# select all records ordered by date
$SQL = "SELECT * FROM `events` ORDER BY date";

# make the query (assume connection is there)
$result = mysql_query($SQL) OR die(mysql_error())l

# iterate the result set
while ($row = mysql_fetch_assoc($result)){
   # build display rows by concatenation
   $output .= "<tr>\n";
   $output .= "<td>".$row['date']."</td>\n";
   $output .= "<td>".$row['name']."</td>\n";
   $output .= "<td>".$row['details']."</td>\n";
   $output .= "</tr>\n";
}
# check if anything is in output
if (!$output){
   $output = "<tr><td>No events found</td></tr>\n":
}
# print the table
echo "<table>\n".$output."</table>";
# done
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top