Submit Your Article Forum Rules

Results 1 to 5 of 5

Thread: msql loop..

  1. #1
    Senior Member ristenk1's Avatar
    Join Date
    Apr 2009
    Posts
    122

    msql loop..

    Hi, I want to create a loop that reads out each of my page's menu_name from the database and on the same line that it reads it out, put a radio button to change the visibility. So far It looks like my radio buttons are on a different line and are all connected (instead of being checked "no" for all of them it is only check no on the last one of the entire sequence...

    PHP Code:
        //K's function:        function get_all_pages() {        global $connection;        $query = "SELECT *                 FROM pages ";        $query .= "WHERE visible = 1 ";        $query .= "ORDER BY position ASC";        $page_set = mysql_query($query, $connection);        confirm_query($page_set);        return $page_set;    }        //K's function:function list_all_pages(){$output = "<ul>";$page_set = get_all_pages();while ($page = mysql_fetch_array($page_set)) {$output .= "<li><a href=\"add_feature.php?page=" . urlencode($page["id"]) . "\">{$page["menu_name"]}</a></li>";$output .= "&nbsp;&nbsp;<input type=\"radio\" name=\"visible\" value=\"0\" checked=\"checked\" /> No <input type=\"radio\" name=\"visible\" value=\"1\" /> Yes";    }$output .= "</ul>";return $output;} 






    pic1.jpg

  2. #2
    Senior Member ristenk1's Avatar
    Join Date
    Apr 2009
    Posts
    122
    Posting code again as the previous is hard to read:

    //K's function:
    function get_all_pages() {
    global $connection;
    $query = "SELECT *
    FROM pages ";
    $query .= "WHERE visible = 1 ";
    $query .= "ORDER BY position ASC";
    $page_set = mysql_query($query, $connection);
    confirm_query($page_set);
    return $page_set;
    }

    //K's function:
    function list_all_pages(){
    $output = "<ul>";
    $page_set = get_all_pages();
    while ($page = mysql_fetch_array($page_set)) {
    $output .= "<li><a href=\"add_feature.php?page=" . urlencode($page["id"]) . "\">{$page["menu_name"]}</a></li>";
    $output .= "&nbsp;&nbsp;<input type=\"radio\" name=\"visible\" value=\"0\" checked=\"checked\" /> No <input type=\"radio\" name=\"visible\" value=\"1\" /> Yes";
    }
    $output .= "</ul>";
    return $output;
    }

    Picture can be clicked on to enlarge and see what I am talking about

  3. #3
    Senior Member ristenk1's Avatar
    Join Date
    Apr 2009
    Posts
    122
    ok, I think the answer is that my radio buttons had the same "name" attribute.. giving that a shot

  4. #4
    WebProWorld MVP DaveSawers's Avatar
    Join Date
    Dec 2006
    Location
    Lunenburg, Nova Scotia, Canada
    Posts
    760
    Yes, changing the names should fix it.

    Why not use a check box for this function though?
    Dynamic Software Development
    www.activeminds.ca

  5. #5
    Junior Member
    Join Date
    Aug 2012
    Posts
    3
    Yes, the problem is the radio names. You could add a unique ID number onto the end of the names which is also stored in the database so that the names are unique.

Posting Permissions

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