Alternate rows in a table...

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
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Alternate rows in a table...

Post 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?
Image Image
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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))&#123;
echo "<td>".$data&#1111;'id']."</td>";
if(!is_odd($data&#1111;'id']))&#123;
echo "</tr><tr>\n";
&#125;
&#125;
echo "</tr></table>";
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post 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)) &#123;
	$id = $row&#1111;'id'];
&#125;
$id = mysql_num_rows($id);
function is_odd($id)&#123; 
$mod = $id % 2; 
if ($mod == 0)&#123; 
return FALSE; 
&#125; else &#123; 
return TRUE; 
&#125; 
&#125; 

$qry = mysql_query("SELECT * FROM nnpicz ORDER BY id DESC LIMIT 0,90"); 
while($data = mysql_fetch_array($qry))&#123; 
echo "<td><a class=g href=$data&#1111;'galurl'] target="_blank" onClick="c($data&#1111;'galurl']);">$data&#1111;'galdesc']</a> - $data&#1111;'numpics'] pics <a class=x href=tell.php?id=$data&#1111;'id']>&#1111;r]</a></td>"; 
if(!is_odd($data&#1111;'id']))&#123; 
echo "</tr><tr>\n"; 
&#125; 
&#125; 
echo "</tr></table>"; 

?>
What am I doing wrong?
Image Image
Post Reply