Solved

Echo radio button

Posted on 2006-06-24
3
513 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
windows 10 bash shell 4 37
Time difference 10 35
Editing login page in zencart. 2 15
showing numeric numbers 2 11
Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

747 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

16 Experts available now in Live!

Get 1:1 Help Now