www.webdeveloper.com
Results 1 to 2 of 2

Thread: echoing radio buttons

  1. #1
    Join Date
    Feb 2011
    Location
    Waterloo, Ontario, Canada
    Posts
    80

    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:

    <?php
    $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'>
    <tr>
    <th></th>
    <th>Artist</th>
    <th>Song</th>
    <th>Album</th>
    <th>Genre</th>
    <th>Length</th>

    </tr>";

    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>";

    mssql_close($dbhandle);
    ?>


    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
    Location
    Ankh-Morpork
    Posts
    19,604
    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.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

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



Recent Articles