hi experts,
i have a mysql table that holds information of events like name, date, location, etc. so each mysql table row is one event with its details.
now i want to output each event in its own html table (with 2 columns) that has the name of the fields like Name, Date, Location, etc in its left column and the respective data from the mysql table in the right column.
what i got now is this code which has 2 drawbacks.
1. it is bloated
2. it displays fields even if there is no data inside ( e.g. when i leave the field "info" blank it still displays Info:
<?php
/* Connecting, selecting database */
$link = @mysql_connect("localhost", "root", "") or die("Error connecting to database");
mysql_select_db("mydatabase") or die("Database mydatabase not found.");
?>
<h4 class="events">This is the Headline for all events.</h4>
<?php
$sql = "SELECT * FROM eventstable";
$result = mysql_query($sql,$link);
$numRows = mysql_num_rows($result);
/* Printing results in HTML */
if ($numRows == 0){
echo "<br><table width='664' border='0' cellspacing='0' cellpadding='5px'>
<tr>
<td colspan='2'>No events found.</td>
</tr></table>";}
else {
for($i=0;$i<mysql_num_rows($result);$i++){
$date_today = date("Y-m-d");
$date = mysql_result($result, $i, "date");
$title = mysql_result($result, $i, "title");
$location = mysql_result($result, $i, "location");
$start = mysql_result($result, $i, "start");
$topic = mysql_result($result, $i, "topic");
$info = mysql_result($result, $i, "info");
$speaker = mysql_result($result, $i, "speaker");
$contact = mysql_result($result, $i, "contact");
$homepage = mysql_result($result, $i, "homepage");
$email = mysql_result($result, $i, "email");
$entry_fee = mysql_result($result, $i, "entry_fee");
if($date >= $date_today){
echo
"<br><table width='664' border='0' cellspacing='0' cellpadding='5px'>
<tr>
<td class='title' colspan='2'>$titel</td>
</tr>
<tr>
<td width='70' align='left' valign='top'><strong>Location:</strong></td>
<td width='530' align='left' valign='top'>$location</td>
</tr>
<tr>
<td align='left' valign='top'><strong>Date:</strong></td>
<td align='left' valign='top'>$date</td>
</tr>
<tr>
<td align='left' valign='top'><strong>Start:</strong></td>
<td align='left' valign='top'>$start</td>
</tr>
<tr>
<td align='left' valign='top'><strong>Topic:</strong></td>
<td align='left' valign='top'>$topic</td>
</tr>
<tr>
<td align='left' valign='top'><strong>Info:</strong></td>
<td align='left' valign='top'>$info</td>
</tr>
<tr>
<td align='left' valign='top'><strong>Speaker:</strong></td>
<td align='left' valign='top'>$speaker</td>
</tr>
<tr>
<td align='left' valign='top'><strong>Contackt:</strong></td>
<td align='left' valign='top'>$contact</td>
</tr>
<tr>
<td align='left' valign='top'><strong>Homepage:</strong></td>
<td align='left' valign='top'><a href='http://$homepage' target='blank'>$homepage</a></td>
</tr>
<tr>
<td align='left' valign='top'><strong>E-Mail:</strong></td>
<td align='left' valign='top'><a href='mailto:$email'>$email</a></td>
</tr>
<tr>
<td align='left' valign='top'><strong>Entry Fee:</strong></td>
<td align='left' valign='top'>$entry_fee</td>
</tr>
<tr>
<td colspan='2'><hr class='seperator'></td>
</tr>
</table>";
}
}
}
?>
what i am looking for is a way to dynamically generate <table>, <tr> and <td>s when needed.
as i am a total noob i ask you to be as specific with your answers, codes as possible.
thanks in advance,
jogol