Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Echo radio button

Posted on 2006-06-24
3
Medium Priority
?
521 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 37

Accepted Solution

by:
Harisha M G earned 2000 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses four methods for overlaying images in a container on a web page
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.

715 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