Solved

Echo radio button

Posted on 2006-06-24
3
515 Views
Last Modified: 2010-05-18
HI all THis is my cod eits all working but im not sure how to implament alternative coloums


this line will echo out a coloum with the radio button and a name from the db
<th width="200" align="left" valign="top" scope="col"><input name="radio<?=$count?>" type="radio" value="radiobutton" /><?=$name?></th>

but if on the next line as you would expect if i make it identical to this one it will echo the results out twice

i wish to have two coloums and echo out the results in order for example

left coloum then right coloum
and so on untill the db is empty

mysql_connect ($dbhost, $dbuser, $dbpass) or die (mysql_error () );
mysql_select_db ($dbname) or die (mysql_error () );
$sql="SELECT * FROM users ";
$query=mysql_query ($sql) or die (mysql_error ());

$count=mysql_num_rows ($query);

while ($row=mysql_fetch_array ($query) or die (mysql_error ()))
{
$name=$row['real_name'];
?>
<table width="400" border="0" cellspacing="2" cellpadding="2">
<tr>
<th width="200" align="left" valign="top" scope="col"><input name="radio<?=$count?>" type="radio" value="radiobutton" /><?=$name?></th>
<th width="200" align="left" valign="top" scope="col">&nbsp;</th>
</tr>
</table>
<? }?>

Hope this makes sense All help appriciated
0
Comment
Question by:avo42
  • 2
3 Comments
 
LVL 37

Accepted Solution

by:
Harisha M G earned 500 total points
ID: 16976906
Hi, you need to have the <table> tag OUTSIDE the loop...

Try this:

<?
    mysql_connect ($dbhost, $dbuser, $dbpass) or die (mysql_error () );
    mysql_select_db ($dbname) or die (mysql_error () );
    $sql="SELECT * FROM users ";
    $query=mysql_query ($sql) or die (mysql_error ());

    $count=mysql_num_rows ($query);

    if($count > 0)
    {
        $i = 0;
?>
        <table width="400" border="0" cellspacing="2" cellpadding="2">
<?
        while ($row=mysql_fetch_array($query) or die (mysql_error ()))
        {
            $name=$row['real_name'];
            if(($i++)%2 == 0)
            {
?>
            <tr>
<?
            }
?>
                <th width="200" align="left" valign="top" scope="col">
                    <input name="radio<?=$count?>" type="radio" value="radiobutton" /> <?=$name?>
                </th>
<?
            if(($i)%2 == 0)
            {
?>
            </tr>
<?
            }
        }
?>
        </table>
<?
    }
?>



---
Harish
0
 
LVL 10

Expert Comment

by:Khanh Doan
ID: 16977028
<?=$name?>
Change to
<?php echo $name;?>
Bonmat86.
0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 16978195
Bonmat86, they are both the same
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now