mercredi 5 août 2015

How to select a data from a table using the where and like statement and echo it


I am having a issue on how to select a data from a database table using the were and like statement.

$hy=mysql_query("select (Total) AS firstterm FROM studentmark, subject where studentmark.student_id='$name' AND studentmark.YEAR='$ya' AND subject.code=studentmark.code AND studentmark.TERM='$term' LIKE 'F%'"); $hm=mysql_num_rows($hy); $fetch=mysql_fetch_array($hy);

echo $fetch['firstterm'];

the issue is that the LIKE 'F%' (FIRST) in the term which has 89 as Total was not selected in the table but the LIKE 'S%' (SECOND) in the term which has 73 was selected. is there anything i am missing?

the table below TERM | CODE |student_id|contAss20Asg|ClassWk10 |Test2nd10|YEAR |EXAM| TOTAL FIRST | AGR | John | 18 |5 | 7 |2011 | 59 | 89 SECOND |AGR2 |John | 13 |6 | 4 |2011 | 40 | 73 THIRD |AGR3 |John | 18 |6 | 8 |2011 | 34 | 64 FIRST |BIO |John | 12 |3 | 3 |2011 | 55 | 73 SECOND |BIO2 |John | 14 |8 | 7 |2011 | 56 | 85 THIRD |BIO3 |John | 12 |8 | 8 |2011 | 42 | 70

My code is stated below

<?php echo '</td><td>'?>
  <?php 
    if ($fetch['Total']==NULL){
echo 'missed';
}else 
    $hy=mysql_query("select  (Total) AS secondterm FROM studentmark, subject where studentmark.student_id='$name' AND studentmark.YEAR='$ya' AND subject.code=studentmark.code    AND studentmark.TERM='$term' LIKE 'S%'");
$hm=mysql_num_rows($hy);
$fetch=mysql_fetch_array($hy);
echo $fetch['secondterm'];
?>
<?php echo '</td><td>'?>
  <?php 
    if ($fetch['Total']==NULL){

}else 
    $hy=mysql_query("select  (Total) AS firstterm FROM studentmark, subject where studentmark.student_id='$name' AND studentmark.YEAR='$ya' AND subject.code=studentmark.code    AND studentmark.TERM='$term' LIKE 'F%'");
$hm=mysql_num_rows($hx);

$hm=mysql_num_rows($hy);
$row=mysql_fetch_array($hy);
echo $row['secondterm'];


?>

<?php echo '</td><td>'?>
  <?php 
    if ($fetch['Total']==NULL){
//echo 'missed';
}else 
    $hy=mysql_query("select  (Total) AS thirdterm FROM studentmark, subject where studentmark.student_id='$name' AND studentmark.YEAR='$ya' AND subject.code=studentmark.code    AND studentmark.TERM='$term'");
$hm=mysql_num_rows($hy);

$hm=mysql_num_rows($hy);
$fetch=mysql_fetch_array($hy);
$row=mysql_fetch_array($hy);

echo $fetch['firstterm']+ $row['secondterm'] + $fetch['thirdterm'];

?>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire