Forum Moderators: coopster

Message Too Old, No Replies

Loop

         

FayeN

9:07 pm on Nov 10, 2003 (gmt 0)

10+ Year Member



The code below is what I am working with. My radio buttons are generated by mysql I need to make a loop so that I can assign a name to each of the radio buttons. I am assigning a name so that I can assign it to a variable and then use session register to call the variable on another page.

Any help with the loop would be great.


<?
session_start();

if ($_SESSION[valid]!= "yes") {
header("Location: [127.0.0.1...]
exit;
}

$db_name = "voter_ballotDB";

$table_name = "candidate";

$connection = @mysql_connect("localhost", "bobby", "bhappy")
or die(mysql_error());

$db = @mysql_select_db($db_name, $connection) or
die(mysql_error());

$sql = "SELECT cand_id, cand_fname, cand_lname, cand_office, cand_major
FROM $table_name WHERE cand_office = 'President' ORDER BY cand_lname";

$result = @mysql_query($sql, $connection) or die(mysql_error());

while ($row = mysql_fetch_array($result)) {

$cand_id = $row['cand_id'];
$cand_fname = $row['cand_fname'];
$cand_lname = $row['cand_lname'];
$cand_office = $row['cand_office'];
$cand_major = $row['cand_major'];

$menu_block .= "

<input type=\"radio\" name=\"cb1\">$cand_lname, $cand_fname<br>";

}

$button_block .="
<FORM METHOD=POST ACTION=\"vicepresident.php\">
<input type=\"Submit\" value=\"Vote\">
<input type=\"Submit\" value=\"Skip\">

<P><INPUT TYPE=\"submit\" NAME=\"Continue\" VALUE=\"Continue\"></P>
</form>";

?>

<HTML>
<HEAD>
<TITLE>Voting System</TITLE>
</HEAD>
<BODY>
<P><h1><strong>Please Vote For President</strong></h1></P>
<P><stong>Choose From The Following:</strong></P>
<hr>
<? echo "$menu_block";?>
<hr>
<? echo "$button_block";?>
</BODY>
</HTML>

jatar_k

5:50 pm on Nov 11, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Is it the $menu_block that you need to loop?

are these the values that you need to build into the radio buttons?

$cand_id = $row['cand_id'];
$cand_fname = $row['cand_fname'];
$cand_lname = $row['cand_lname'];
$cand_office = $row['cand_office'];
$cand_major = $row['cand_major'];

I don't really understand what you need to do. Maybe if you could show us where and what you need to loop through or a static example that you want to change to a loop it would better demonstrate your problem.

lorax

6:22 pm on Nov 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I think you got it right jatar_k. I think FayeN wants to loop over

<input type=\"radio\" name=\"cb1\">$cand_lname, $cand_fname<br>";

and replace $cand_lname, $cand_fname with the contents of the table.

jatar_k

7:17 pm on Nov 11, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



well, it's already inside a while loop. Is it misbehaving?

What is it not doing right then?