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.

/* 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;
While($rowzi = mysql_fetch_array($phel))
$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);
$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);

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”?