Question : Why does a simple arithmetic execution return wrong number?

Gurus! What is wrong here? Is it a simple typo or more serious. Hope you understand what I mean by looking at the example here:
<?php
$SQL17 = " SELECT MAX(upptagnings_turnummer) as max_upptagnings_turnummer FROM medlem WHERE upptagningsdatum = '$upptagningsdatumet_varv1' AND upptagningsupplagsplats = '$varv_3_namn' ";  
if (!$ret17) { echo("Nr 2 (här): " .mysql_error()); }
else {
      while ($row = mysql_fetch_array($ret17)) {
        $max_upptagnings_turnummer  = $row["max_upptagnings_turnummer"]; // (Returns 1.)}}
$SQL18 = " SELECT MAX(upptagnings_turnummer_bat_2) as max_upptagnings_turnummer_bat_2 FROM medlem WHERE upptagningsdatum = '$upptagningsdatumet_varv1]' AND upptagningsupplagsplats = '$varv_3_namn' ";
$ret18 = mysql_query($SQL18);
if (!$ret18) { echo("Nr 4: " .mysql_error()); }
else {
      while ($row = mysql_fetch_array($ret18)) {
        $max_upptagnings_turnummer_bat_2  = $row["max_upptagnings_turnummer_bat_2"];  // (Returns 2.)
}}

//------------------------------
if($max_upptagnings_turnummer >= $max_upptagnings_turnummer_bat_2)  {  $nytt_turnummer = $max_upptagnings_turnummer + 1;  }
if($max_upptagnings_turnummer < $max_upptagnings_turnummer_bat_2)   {  $nytt_turnummer = $max_upptagnings_turnummer_bat_2 + 1;  }  // (Returns 2. Had expected 3.)
?>

Answer : Why does a simple arithmetic execution return wrong number?

You're not executing your SQL strings for starters.

Once you've set your query string, you need to run it using mysql_query, and assign the results to $ret17 and $ret18


1:
2:
3:
4:
5:
$SQL17 = " SELECT MAX(upptagnings_turnummer) as max_upptagnings_turnummer FROM medlem WHERE upptagningsdatum = '$upptagningsdatumet_varv1' AND upptagningsupplagsplats = '$varv_3_namn' ";  

$ret17 = mysql_query($SQL17);

if (!$ret17) { echo("Nr 2 (här): " .mysql_error()); }
Random Solutions  
 
programming4us programming4us