Solved

Echo radio button

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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

728 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