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
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Wed Apr 20, 2005 6:52 pm
Im using this piece of code to read from the database and show the information. However at the moment it shows it as:
Code: Select all
<tr>
<td>ENTRY</td>
</tr>
<tr>
<td>ENTRY</td>
</tr>
<tr>
<td>ENTRY</td>
</tr>
<tr>
<td>ENTRY</td>
</tr>Now i wanted to know how can i make it so it uses the </tr> tag every 2 results? So it shows this:
Code: Select all
<tr>
<td>ENTRY</td>
<td>ENTRY</td>
</tr>
<tr>
<td>ENTRY</td>
<td>ENTRY</td>
</tr>
Code: Select all
<?php
$conn = mysql_connect("***","***","***");
mysql_select_db("***",$conn);
$sql = "SELECT * FROM categorys";
$result = mysql_query($sql,$conn) or die(mysql_error());
while ($r = mysql_fetch_array($result)) {
$cat_id = $r['id'];
$cat_title = $r['title'];
$cat_description = $r['description'];
$cat_supportsite = $r['supportsite'];
$cat_tutcount = $r['tutcount'];
$cat_latestid = $r['latestid'];
echo "<tr>";
echo "<td><font face=\"arial\" size=\"2\"><a href=\"./cats.php?cid=$cat_id\">$cat_title</a> (<i><b>$cat_tutcount</b> Tutorials</i>)";
if ($cat_supportsite != "") {
echo " [About <a href=\"$cat_supportsite\" target=\"_blank\">$cat_title</a>]";
}
echo "<br>$cat_description</font></td>";
echo "</tr>";
}
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Apr 20, 2005 7:43 pm
Useful Posts thread: Multi-column formatted output
viewtopic.php?t=29816
Todd_Z
Forum Regular
Posts: 708 Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan
Post
by Todd_Z » Wed Apr 20, 2005 11:12 pm
Code: Select all
$x = 1;
while ( $info = mysql_fetch_array($results) ) {
if ( $x%2 == 1 )
echo "<tr>";
echo "<td>".$info["ID"]."</td>";
if ( $x%2 == 1 )
echo "</tr>";
$x = 3 - $x;
}
harrisonad
Forum Contributor
Posts: 288 Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:
Post
by harrisonad » Thu Apr 21, 2005 5:26 am
Code: Select all
$firsttime = true;
while($data = mysql_fetch($result)){
if($firsttime) echo "<TR>";
echo "<TD>$data[0]</TD>";
if(!$firsttime){
echo "</TR>"
$firsttime = true;
}else
$firsttime = false;
}
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Thu Apr 21, 2005 5:57 am
Cheers Guys!