Hello all,
I am an extreme novice at MySQL and PHP. I mention this because, I have searched through the archives here at php builder, and have happened across this same problem a few times. The answers, however, are sort of over my head. I'm praying that someone is nice enough to humor me, and answer the same old question again, but maybe in relation to the way I have it coded already. I'm not good enough at this yet to take a generic solution and customize it for myself, unfortunately.
The problem I'm trying to solve is to loop through a simple query, and output two SQL row returns for every 1 HTML table row. Meaning simply, I need the output from the query statement to have 2 sets of data returned (in 2 HTML table cells) per every 1 HTML table row.
The way I have it coded now returns one SQL row per one HTML row, making a one column table. All I want to be able to do is turn it into a two column table.
My code is set up as follows :
$sql = "SELECT * FROM this_table WHERE condition";
$result = mysql_query($sql);
$num=mysql_numrows($result);
if (!$result) {
echo("<P>Error performing query: " .
mysql_error() . "</P>"); exit();
}
if ($num==0) {
echo "<font size=\"+1\">This is currently being compiled, and will be posted shortly!</font><br><br><a href=\"index.php\">Go Back</a>";
}
else {
echo("<table border=\"1\" cellspacing=\"0\" cellpadding=\"3\">");
$i=0;
while ($i < $num) {
$image_id=mysql_result($result,$i,"image_id");
$image_name=mysql_result($result,$i,"image_name");
$image_bio=mysql_result($result,$i,"image_bio");
$rest = substr("$image_id", 0, 4);
echo("<tr><td><img src=\"./images/composites/$rest/$image_id.jpg\"></td><td><a href=\"bio_page.php?$image_bio\">$image_name</a></td></tr>");
++$i;
}
echo("</table>");
}
mysql_close();
That's pretty much it. Any help at all would be appreciated. I hate to have someone else do my work for me, but I'm such a newbie at this stuff, that I'm having trouble working through the basics. If you do answer, please act like you're talking to someone who barely knows the language, that way I won't have to sound like an idiot and reply with a "huh?"
Thanks in advance!!
B.