PDA

View Full Version : PHP and Table Rows help



Moh
20-08-2008, 12:00 PM
Well I'm currently displaying images in rows, this all works, but im having trouble with one thing.
Each row has a check box, and I want the current selected (in the database) to be checked. But, it is checking each one, even though I only want it to check the one in the database.
Heres my code.

<?php
$sql = mysql_query("SELECT * FROM `images` WHERE `dj` = '$username'");
$sql2 = mysql_query("SELECT `picture` FROM `users` WHERE `username` = '$username'");
$rows2 = mysql_fetch_array($sql2);
echo("<table>");
while($rows = mysql_fetch_array($sql))
{
if(!$o) print ("<tr>");
$o++;
if($rows["url"] == $rows2["picture"]) {
$sel = "checked";
}
print ("<td style=\"border:1px solid black;text-align:center;width:150px;\"><img src=\"djpics/$rows[url]\"><br>
<input type=\"radio\" value=\"$rows[url]\" name=\"profimg\" $sel><br>
<a href=\"?view=delprofileimg&imgid=$rows[id]\">Delete</a>
</td>");
if($o!=3) continue;
print ("</tr>");
unset($o);
}
echo ("</tr></table>");
?>

Moved by Invent (Forum Moderator) from Designing & Development: Please post in the correct forum next time, thanks :).

Delatory
20-08-2008, 12:11 PM
<?php
$sql = mysql_query("SELECT * FROM `images` WHERE `dj` = '$username'");
$sql2 = mysql_query("SELECT `picture` FROM `users` WHERE `username` = '$username'");
$rows2 = mysql_fetch_array($sql2);
echo("<table>");
while($rows = mysql_fetch_array($sql))
{
if(!$o) print ("<tr>");
$o++;
if($rows["url"] == $rows2["picture"]) {
$sel = "checked";
}
print ("<td style=\"border:1px solid black;text-align:center;width:150px;\"><img src=\"djpics/$rows[url]\"><br>
<input type=\"radio\" value=\"$rows[url]\" name=\"profimg\" $sel><br>
<a href=\"?view=delprofileimg&imgid=$rows[id]\">Delete</a>
</td>");
unset($sel);
if($o!=3) continue;
print ("</tr>");
unset($o);
}
echo ("</tr></table>");
?>


I'm guessing that will work. I added in unset($sel);

Moh
20-08-2008, 01:38 PM
<?php
$sql = mysql_query("SELECT * FROM `images` WHERE `dj` = '$username'");
$sql2 = mysql_query("SELECT `picture` FROM `users` WHERE `username` = '$username'");
$rows2 = mysql_fetch_array($sql2);
echo("<table>");
while($rows = mysql_fetch_array($sql))
{
if(!$o) print ("<tr>");
$o++;
if($rows["url"] == $rows2["picture"]) {
$sel = "checked";
}
print ("<td style=\"border:1px solid black;text-align:center;width:150px;\"><img src=\"djpics/$rows[url]\"><br>
<input type=\"radio\" value=\"$rows[url]\" name=\"profimg\" $sel><br>
<a href=\"?view=delprofileimg&imgid=$rows[id]\">Delete</a>
</td>");
unset($sel);
if($o!=3) continue;
print ("</tr>");
unset($o);
}
echo ("</tr></table>");
?>
I'm guessing that will work. I added in unset($sel);
Ah, thank you :)
Im new to this type of php :P

Want to hide these adverts? Register an account for free!