...

View Full Version : Retriving more than one row in php from mysql



codytheking313
09-24-2005, 05:02 AM
I am making a table for the results of my quiz and i need help getting each row in a different table row. heres my code:


while ($rows=mysql_fetch_array($results)) {
echo 'name: '.$Name.'&nbsp;<br>';
echo 'score: '.$Score.'&nbsp;<br>';
echo 'question 1: '.$q1.'&nbsp;<br>';
echo 'question 2: '.$q2.'&nbsp;<br>';
echo 'question 3: '.$q3.'&nbsp;<br>';
echo 'question 4: '.$q4.'&nbsp;<br>';
echo 'question 5: '.$q5.'&nbsp;<br>';
echo 'question 6: '.$q6.'&nbsp;<br><br><br>';


$Name = $rows['name'];
$Score = $rows['score'];
$q1 = $rows['question_1'];
$q2 = $rows['question_2'];
$q3 = $rows['question_3'];
$q4 = $rows['question_4'];
$q5 = $rows['question_5'];
$q6 = $rows['question_6'];

}
?>
</p>
<table align='center' border='1' bordercolor='black'>
<tr>
<td align='center'>Name:</td>
<td align='center'>Score: </td>
<td align='center'>? #1</td>
<td align='center'>? #2</td>
<td align='center'>? #3</td>
<td align='center'>? #4</td>
<td align='center'>? #5</td>
<td align='center'>? #6</td>
</tr>


<tr>
<td align='center'><?php echo $Name; ?>&nbsp;&nbsp;</td>
<td align='center'><?php echo $Score; ?>&nbsp;&nbsp;</td>
<td align='center'><?php echo $q1; ?>&nbsp;&nbsp;</td>
<td align='center'><?php echo $q2; ?>&nbsp;&nbsp;</td>
<td align='center'><?php echo $q3; ?>&nbsp;&nbsp;</td>
<td align='center'><?php echo $q4; ?>&nbsp;&nbsp;</td>
<td align='center'><?php echo $q5; ?>&nbsp;&nbsp;</td>
<td align='center'><?php echo $q6; ?>&nbsp;&nbsp;</td>
</tr>

</body>
</html>

missing-score
09-24-2005, 05:18 AM
Try re-arranging your code a bit...:



<?php ?>
</p>
<table align='center' border='1' bordercolor='black'>
<tr>
<td align='center'>Name:</td>
<td align='center'>Score: </td>
<td align='center'>? #1</td>
<td align='center'>? #2</td>
<td align='center'>? #3</td>
<td align='center'>? #4</td>
<td align='center'>? #5</td>
<td align='center'>? #6</td>
</tr>

<?php
while ($rows=mysql_fetch_array($results)) {

echo "<tr>
<td align='center'>{$rows['name']}&nbsp;&nbsp;</td>
<td align='center'>{$rows['score']}&nbsp;&nbsp;</td>
<td align='center'>{$rows['question_1']}&nbsp;&nbsp;</td>
<td align='center'>{$rows['question_2']}&nbsp;&nbsp;</td>
<td align='center'>{$rows['question_3']}&nbsp;&nbsp;</td>
<td align='center'>{$rows['question_4']}&nbsp;&nbsp;</td>
<td align='center'>{$rows['question_5']}&nbsp;&nbsp;</td>
<td align='center'>{$rows['question_6']}&nbsp;&nbsp;</td>
</tr>";

}
?>
</body>
</html>

codytheking313
09-25-2005, 08:56 PM
Thank you that helped alot and it displayed my data right



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum