Results 1 to 2 of 2

Thread: echoing radio buttons

  1. #1
    Join Date
    Feb 2011
    Waterloo, Ontario, Canada

    echoing radio buttons

    This is my first post on this site. I've spent the past 2 months learning from scratch how to make my own website but I've finally run into a problem where I'm a little oblivious.

    What I'm trying to do is select a table from my database and echo it into an html table. In this case, the table is a list of songs and their artists. So each row will be another song and artist. But in every new row I want to put in a radio button so the user gets to choose which song they would like.

    Code is:

    $myServer = "myserver";
    $myUser = "myusername";
    $myPass = "mypassword";
    $myDB = "mydatabase";

    //connection to the database
    $dbhandle = mssql_connect($myServer, $myUser, $myPass)
    or die("Couldn't connect to SQL Server on $myServer");

    //select a database to work with
    $selected = mssql_select_db($myDB, $dbhandle)
    or die("Couldn't open database $myDB");

    //declare the SQL statement that will query the database
    $query = "SELECT * ";
    $query .= "FROM tblPlaylist ";

    //execute the SQL query and return records
    $result = mssql_query($query);

    echo "<table border='1'>


    while($row = mssql_fetch_array($result))
    echo "<tr>";
    echo "<td>" . ********** . "</td>";
    echo "<td>" . $row['Artist'] . "</td>";
    echo "<td>" . $row['Song'] . "</td>";
    echo "<td>" . $row['Album'] . "</td>";
    echo "<td>" . $row['Genre'] . "</td>";
    echo "<td>" . $row['Length'] . "</td>";
    echo "</tr>";
    echo "</table>";


    Where you see ********** is where I want to put a radio button for each row but I just don't know how. Thanks for your help.

  2. #2
    Join Date
    Aug 2004
    Assuming for this example the primary key field is "id", something like:
    PHP Code:
    echo "<td><input type='radio' name='id' value='" $row['id'] . "' /></td>"
    PS: If you use this forum's [php]...[/php] bbcode tags around your code snippets, they'll be much easier to read.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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