Solved

Echo radio button

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

635 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