Page 1 of 1

make html tables after getting the query!

Posted: Wed Mar 11, 2009 1:13 pm
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.

Re: make html tables after getting the query!

Posted: Wed Mar 11, 2009 1:47 pm
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>';
 

Re: make html tables after getting the query!

Posted: Wed Mar 11, 2009 1:58 pm
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

Re: make html tables after getting the query!

Posted: Wed Mar 11, 2009 2:01 pm
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.