make html tables after getting the query!

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
rwahdan
Forum Newbie
Posts: 23
Joined: Thu Feb 12, 2009 1:49 am

make html tables after getting the query!

Post by rwahdan »

dear all,

i am newbie in php. i got some code written in php and its working fine but i dont know the logic of having html headings and the results of my sql query!

here is the code:

<?php

$host="11111.com";
$db_name="mydb";
$username="mydb";
$password="2008";

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$theday=date("d") + 1;
$themonth=date("n");
$theyear=date("Y");
$nameday = date("l");

$sql= "SELECT * FROM calendar_events WHERE day='$theday' and month='$themonth' and year='$theyear' and approved=1" or die(mysql_error());
$result = mysql_query($sql) or die('Query failed. ' . mysql_error());

if (mysql_num_rows($result) > 0) {

echo "there are some records!";

}

else {

echo "there are no events for $nameday $theday/$themonth/$theyear" ;

}
?>
instead of the messages that is colored i need to have the results in html table. i will appreciate all the help and thanks guys alot.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: make html tables after getting the query!

Post by jayshields »

There are a million examples of this. Any open source code you find on the net will probably have it.

Basically just:

Code: Select all

 
echo '<table>';
while($row = mysql_fetch_assoc($result))
{
  echo '<tr><td>'.$row['day'].'</td><td>'.$row['month'].'</td><td>'.$row['year'].'</td></tr>';
}
echo '</table>';
 
rwahdan
Forum Newbie
Posts: 23
Joined: Thu Feb 12, 2009 1:49 am

Re: make html tables after getting the query!

Post by rwahdan »

i really appreciate you help but can we make neat looking? i need to show the results in a like table such as attached.
Event name Description Start time End time
Event value 100 people 12 pm 3pm
thanks again
Last edited by rwahdan on Wed Mar 11, 2009 2:05 pm, edited 1 time in total.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: make html tables after getting the query!

Post by jayshields »

All you have to do is adapt the code that I've given you. If you want a table header look at the <th> HTML element.
Post Reply