Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 3

Mysql Insert query inserts correctly but select query results are wrong

Thanks in advance, I'm having problems with avoiding mysql insert query in php while loop as i find it the simples way and am getting wrong mysql SELECT values.
2 Replies
Copilot Lvl 2
Message 2 of 3

Re: Mysql Insert query inserts correctly but select query results are wrong

/* this is my code*/
$ssss = "SELECT stnum,averages,class FROM positionn where class = '{$class}' ORDER BY conditions DESC, averages DESC, english DESC, mathematics DESC, science DESC";
$phel = mysql_query($ssss,$link);
$h = 0;
mysql_data_seek($phel,0);
While($rowzi = mysql_fetch_array($phel))
{
$h++;
$stn = $rowzi['stnum'];
$p = "INSERT INTO pn(rank,stnumb) VALUES('{$h}','{$stn}') ON DUPLICATE KEY UPDATE rank = '{$h}'";
$successfu = mysql_query($p,$link);
}
$final = "SELECT stnumb, rank FROM pn where stnumb = '{$stid}'";
$finish = mysql_query($final,$link);
mysql_data_seek($finish,0);
$r = mysql_fetch_array($finish);
$rank = $r['rank'];
$stud = $r['stnumb'];


$sehlopha = array($class);
$letsatsi = array(date('F Y'));
$bana = array('Number in class: '.$numb);
$position = array('Position: '.$rank);
Commander Lvl 2
Message 3 of 3

Re: Mysql Insert query inserts correctly but select query results are wrong

For us to be able to effectively help you, you need to provide two more pieces of information:

1. What are you trying to accomplish? It looks to me like you want to show the rank of a student based on their student id. What determines the rank? The best "averages" value?

2. In what way are the "select query results are wrong"?

 

Please follow-up to let us know how you made out. For good karma, mark a reply as the answer if it helped!