tobimichigan Posted April 14, 2010 Share Posted April 14, 2010 Hi fellowcode comrades, Please I am stuck with this array...output, everything works but on the output it only displays the "A" Grade. But I want to display other grades as well..but its not <?php $grade=array("A","B","C","D","E","F"); $adno=$_GET['adno']; $select=mysql_query("select * from acadinfo where adno='$adno'"); $num=mysql_num_rows($select); $a=1; if(!@select) { die('<p>Error Retrieving<br/>'. 'Error: ' .mysql_error() . '</p>');} while ($datalist=mysql_fetch_array($select)){ $adno=htmlspecialchars($datalist["adno"]); $math=htmlspecialchars($datalist["math"]); $eng=htmlspecialchars($datalist["eng"]); $physics=htmlspecialchars($datalist["physics"]); $chem=htmlspecialchars($datalist["chem"]); $biology=htmlspecialchars($datalist["biology"]); $economics=htmlspecialchars($datalist["economics"]); $yoruba=htmlspecialchars($datalist["yoruba"]); echo ("<table width='548' border='1'>"); echo("<tr> <th width='26' scope='col'>ADMISSION NO.</th> <th width='26' scope='col'>MATHEMATICS</th> <th width='26' scope='col'>ENGLISH</th> <th width='26' scope='col'>PHYSICS</th> <th width='26' scope='col'>CHEMISTRY</th> <th width='365' scope='col'>BIOLOGY</th> <th width='365' scope='col'>ECONOMICS</th> <th width='365' scope='col'>YORUBA</th> </tr>"); echo("<tr> <th scope='row'>$adno</th>"); if ($datalist >=80) { echo("<td>$grade[0]</td>");} elseif ($datalist >=70) { echo("<td>$grade[1]</td>");} elseif ($datalist >=60) { echo("<td>$grade[2]</td>");} elseif ($datalist >=50) { echo("<td>$grade[3]</td>");} elseif ($datalist >=40) { echo("<td>$grade[4]</td>");} elseif ($datalist <=39) { echo("<td>$grade[5]</td>");} echo("</tr>"); echo("</table>"); $a++; } ?> Please can sm1 tell me what I'm doing wrong here? Link to comment https://forums.phpfreaks.com/topic/198575-array-issue/ Share on other sites More sharing options...
Ken2k7 Posted April 14, 2010 Share Posted April 14, 2010 if(!@select) { ^ see anything wrong with that? I don't suppose select is a constant. Where is your loop that displays the other grades? Link to comment https://forums.phpfreaks.com/topic/198575-array-issue/#findComment-1042055 Share on other sites More sharing options...
tobimichigan Posted April 15, 2010 Author Share Posted April 15, 2010 Wait men, r u saying that I have to repeat: <?php echo ("<table width='548' border='1'>"); echo("<tr> <th width='26' scope='col'>ADMISSION NO.</th> <th width='26' scope='col'>MATHEMATICS</th> <th width='26' scope='col'>ENGLISH</th> <th width='26' scope='col'>PHYSICS</th> <th width='26' scope='col'>CHEMISTRY</th> <th width='365' scope='col'>BIOLOGY</th> <th width='365' scope='col'>ECONOMICS</th> <th width='365' scope='col'>YORUBA</th> </tr>"); echo("<tr> <th scope='row'>$adno</th>"); if ($datalist >=80) { echo("<td>$grade[0]</td>");} elseif ($datalist >=70) { echo("<td>$grade[1]</td>");} elseif ($datalist >=60) { echo("<td>$grade[2]</td>");} elseif ($datalist >=50) { echo("<td>$grade[3]</td>");} elseif ($datalist >=40) { echo("<td>$grade[4]</td>");} elseif ($datalist <=39) { echo("<td>$grade[5]</td>");} echo("</tr>"); echo("</table>"); $a++; } ?> All these codes to display the other grades on the other table? Link to comment https://forums.phpfreaks.com/topic/198575-array-issue/#findComment-1042059 Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 No, of course not. Use a loop, which is what I said before. Link to comment https://forums.phpfreaks.com/topic/198575-array-issue/#findComment-1042068 Share on other sites More sharing options...
tobimichigan Posted April 15, 2010 Author Share Posted April 15, 2010 Please can u kindly show me how 2 do this with these codes? Link to comment https://forums.phpfreaks.com/topic/198575-array-issue/#findComment-1042069 Share on other sites More sharing options...
tobimichigan Posted April 15, 2010 Author Share Posted April 15, 2010 Please can some1 tell me how to loop through these values.. and the out put comes appropriately?? Link to comment https://forums.phpfreaks.com/topic/198575-array-issue/#findComment-1042422 Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 Look up the loops. You can use any of the 3 loops: 1. foreach loop - foreach 2. while loop - while 3. for loop - for I've linked to documentations for them. There should be examples there too. Link to comment https://forums.phpfreaks.com/topic/198575-array-issue/#findComment-1042429 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.