Page 1 of 1
Alternate rows in a table...
Posted: Mon Jul 22, 2002 1:11 am
by phice
I didn't know if I should post this in this forum, or the database forum. :/
Lets say theres a table, with multiple additions in it... like 1,2,3,4,5,6,7... and so on.
Now, I've got an HTML Table that has 2 sides, 1 on the left, 1 on the right. I want 1 on the left, 2 on the right, 3 on the left, 4 on the right, and so on
Anyone have any ideas on how I would accomplish this?
Posted: Mon Jul 22, 2002 2:21 am
by hob_goblin
ok, lets say the number is in the "id" field, alright.
and lets say its in the table "foo", and that you're already connected
Code: Select all
function is_odd($num){
$mod = $num % 2;
if($mod == 0){
return FALSE;
} else {
return TRUE;
}
}
/* connection goes here */
$qry = mysql_query("SELECT * FROM foo");
echo "<table><tr>";
while($data = mysql_fetch_assoc($qry)){
echo "<td>".$dataї'id']."</td>";
if(!is_odd($dataї'id'])){
echo "</tr><tr>\n";
}
}
echo "</tr></table>";
Posted: Tue Jul 23, 2002 2:42 am
by phice
The error I get:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/nncommunity/www/nnpicz/autosubmit.php on line 80
My code:
Code: Select all
<?
echo "<table align=center width=100% cellpadding=4 cellspacing=0 border=0 bordercolor=#000000><tr>";
$connection = @mysql_connect("localhost", "------", "-----") or die("Couldn't connect.");
$db = mysql_select_db("nnpicz", $connection) or die("Couldn't select database.");
$sql2 = "SELECT * FROM nnpicz ORDER BY id DESC";
$result2 = mysql_query($sql2,$connection) or die("Couldn't execute query.");
while ($row2 = mysql_fetch_array($result2)) {
$id = $rowї'id'];
}
$id = mysql_num_rows($id);
function is_odd($id){
$mod = $id % 2;
if ($mod == 0){
return FALSE;
} else {
return TRUE;
}
}
$qry = mysql_query("SELECT * FROM nnpicz ORDER BY id DESC LIMIT 0,90");
while($data = mysql_fetch_array($qry)){
echo "<td><a class=g href=$dataї'galurl'] target="_blank" onClick="c($dataї'galurl']);">$dataї'galdesc']</a> - $dataї'numpics'] pics <a class=x href=tell.php?id=$dataї'id']>їr]</a></td>";
if(!is_odd($dataї'id'])){
echo "</tr><tr>\n";
}
}
echo "</tr></table>";
?>
What am I doing wrong?