Results 1 to 3 of 3
  1. #1
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default PHP and Table Rows help

    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 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 .
    Last edited by Invent; 24-08-2008 at 01:25 AM.

  2. #2
    Join Date
    Jul 2008
    Location
    Leeds, UK
    Posts
    47
    Tokens
    0

    Default

    PHP 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>"
    );
        unset(
    $sel);
        if(
    $o!=3) continue;
        print (
    "</tr>");
        unset(
    $o);

    echo (
    "</tr></table>");
    ?>
    I'm guessing that will work. I added in unset($sel);

  3. #3
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default

    Quote Originally Posted by Delatory View Post
    PHP 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>"
    );
        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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •