Jump to content

[SOLVED] need some help...


Patrick3002

Recommended Posts

Heres my code:

 


<?php

include_once("config.php");

	$sql="SELECT `title`, `op1`, `op2`, `op3`, `op4`, `op5`, `op6`, `op7`, `op8`, `op9`, `op10` FROM `vote` WHERE `poll_id` = '69'";
	$result=mysql_query($sql);
	$num_rows=mysql_num_rows($result);

	echo "<table width=\"335\" height=\"342\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\">
  <tr>
    <td height=\"42\" colspan=\"2\" align=\"center\" valign=\"middle\"><table width=\"95%\" height=\"80%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
      <tr>
        <td align=\"left\" valign=\"middle\" bgcolor=\"#00CCFF\"><?php echo $title; ?></td>
      </tr>
    </table></td>
  </tr>";

	$i=0;
	$x=0;
	while ($i < $num_rows) {

			$title=mysql_result($result,$i,"title");
    			$op=mysql_result($result,$i,"op1");
    			$op=mysql_result($result,$i,"op2");
    			$op=mysql_result($result,$i,"op3");
    			$op=mysql_result($result,$i,"op4");
    			$op=mysql_result($result,$i,"op5");
    			$op=mysql_result($result,$i,"op6");
    			$op=mysql_result($result,$i,"op7");
    			$op=mysql_result($result,$i,"op8");
    			$op=mysql_result($result,$i,"op9");
    			$op=mysql_result($result,$i,"op10");
    			$brdr_clr=mysql_result($result,$i,"brdr_clr");


			echo "<tr>
    					<td>$op</td>
    					<td width=\"73\" align=\"center\" valign=\"middle\"><input name=\"$op\" type=\"radio\" value=\"radiobutton\"></td>
  					  </tr>";


	$i++;
	$x++;
	}

	echo "</table>";

?>

 

Now, its only echoing the last $op var, which would be = to whatever op10 = in the db, i want it to echo w/e op1-op10 is from the db, so i guess i'd need it to automatically increase, but im not sure how i'd go about doing that.

 

I want to echo this for each op1-op10, so it would echo that table and the first table, $op would = op1, the second table, $op2 would = op2 and so on...

echo "<tr>
    					<td>$op</td>
    					<td width=\"73\" align=\"center\" valign=\"middle\"><input name=\"$op\" type=\"radio\" value=\"radiobutton\"></td>
  					  </tr>";

 

 

 

Any help is appreciated! :D

Link to comment
Share on other sites

you have to loop through $op not just echo it...

 

so

 

<?php 

while ($op = mysql_fetch_array($result))
{
echo "<tr>
    		<td>
                      $op['op1'];
                </td>
    		<td width=\"73\" align=\"center\" valign=\"middle\">
                       <input name=\"$op\" type=\"radio\" value=\"radiobutton\">
                </td>
  	</tr>";
echo "<tr>
    		<td>
                      $op['op2'];
                </td>
    		<td width=\"73\" align=\"center\" valign=\"middle\">
                       <input name=\"$op\" type=\"radio\" value=\"radiobutton\">
                </td>
  	</tr>";

//and so on

}

Link to comment
Share on other sites

For starters, don't bump your thread every 45 mins or so, have some patience and if need be reword your question a little clearer.

 

Secondly... the problem you describe is only one issue here. The code you provided really ought not to be working as you expect. Your opening <?php tages within an already existing php echo'd string.

 

Thirdly, this piece....

 

$op=mysql_result($result,$i,"op1");
$op=mysql_result($result,$i,"op2");
$op=mysql_result($result,$i,"op3");
$op=mysql_result($result,$i,"op4");
$op=mysql_result($result,$i,"op5");
$op=mysql_result($result,$i,"op6");
$op=mysql_result($result,$i,"op7");
$op=mysql_result($result,$i,"op8");
$op=mysql_result($result,$i,"op9");
$op=mysql_result($result,$i,"op10");

 

Your assinging different results over the same variable... what do you expect the resultant $op to be?

 

You might try.....

 

<?php

 while ($i < $num_rows) {		
   for ($cnt = 1; $<=10; $i++) {
     $op = mysql_result($result,$i,${'op'.$cnt});
     echo "<tr><td>$op</td><td width=\"73\" align=\"center\" valign=\"middle\"><input name=\"$op\" type=\"radio\" value=\"radiobutton\"></td></tr>";
     $cnt++;
   }
   $i++;
   $x++;

 }

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.