/    Sign up×
Community /Pin to ProfileBookmark

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.

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 24.2011 — Assuming for this example the primary key field is "id", something like:
[code=php]
echo "<td><input type='radio' name='id' value='" . $row['id'] . "' /></td>";
[/code]


PS: If you use this forum's [noparse][code=php]...[/code][/noparse] bbcode tags around your code snippets, they'll be much easier to read. ?
×

Success!

Help @Galway spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...