IF stament virker ikke
Hej alle sammen.. nogen der kan fortælle mig hvad der er galt med mit IF statement i dette stykke kode?<?php
//** Get the data from last page.
$produkt = $_GET['produkt'];
$antal = $_GET['antal'];
$enhed = $_GET['enhed'];
$dato = date('dmY');
$ddato = "d" . $dato;
$forhandler = $_GET['forhandler'];
//** Connect to the database
mysql_connect("212.97.132.75", "tirdyr_admin", "silverchair") or die(mysql_error());
mysql_select_db("tirdyr_db") or die(mysql_error());
//** Create the table for the day (if i some day find a way to check if it allrdy exists ill add that
$query = 'CREATE TABLE '. $ddato .'( '.
'nummer INT NOT NULL AUTO_INCREMENT, '.
'vare VARCHAR(30) NOT NULL, '.
'enhed VARCHAR(10) NOT NULL, '.
'forhandler VARCHAR(30) NOT NULL, '.
'antal INT NOT NULL, '.
'PRIMARY KEY(nummer))';
$result=mysql_query($query);
//** select all data in "orginal" so it can be inserted to "$ddato"
$query = "SELECT * FROM $ddato";
$result = mysql_query($query);
$num = mysql_numrows($result);
//** only do the following if the table is empthy.
if ($num = 0) { //** <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< This IF statement
$query = "SELECT * FROM orginal";
$result = mysql_query($query);
$num = mysql_numrows($result);
$i=0;
//** Insert all data from "orginal" except all "antal" is zero.
while ($i < $num) {
$produkt0=mysql_result($result,$i,"vare");
$antal0=0;
$enhed0=mysql_result($result,$i,"enhed");
$forhandler0=mysql_result($result,$i,"forhandler");
$query = "INSERT INTO $ddato (vare, antal, enhed, forhandler) VALUES ('$produkt0', '$antal0', '$enhed0', '$forhandler0')";
mysql_query($query);
$i++;
}
}
//** Insert the data into the table
$query = "UPDATE $ddato SET vare='$produkt', antal='$antal', enhed='$enhed', forhandler='$forhandler'";
mysql_query($query);
//** Print what is added right now.
echo "Du har lige tilføjet " . $antal . " " . $enhed . " " . $produkt . " fra " . $forhandler . ".<br /><hr><br />";
//** Find the cols with "Frugtlageret"
$query = "SELECT * FROM $ddato WHERE forhandler='Frugtlageret' ORDER BY vare";
$result = mysql_query($query);
//** Find the number of results
$num = mysql_numrows($result);
$i=0;
//** Make a table from the former query, use a WHILE loop this is for frugtlageret
echo "<table><tr><td><b>Frugtlageret</b></td></tr>";
while ($i < $num) {
$produkt=mysql_result($result,$i,"vare");
$antal=mysql_result($result,$i,"antal");
$enhed=mysql_result($result,$i,"enhed");
$forhandler=mysql_result($result,$i,"forhandler");
echo "<tr><td>" . $antal . " " . $enhed . " " . $produkt . "</td></tr>";
$i++;
}
echo "</table><br /><hr><br />";
//** Lets do this again for the "KKEngros"
$query = "SELECT * FROM $ddato WHERE forhandler='KKEngros' ORDER BY vare";
$result = mysql_query($query);
$num = mysql_numrows($result);
$i=0;
echo "<table><tr><td><b>KK Engros</b></td></tr>";
while ($i < $num) {
$produkt=mysql_result($result,$i,"vare");
$antal=mysql_result($result,$i,"antal");
$enhed=mysql_result($result,$i,"enhed");
$forhandler=mysql_result($result,$i,"forhandler");
echo "<tr><td>" . $antal . " " . $enhed . " " . $produkt . "</td></tr>";
$i++;
}
//** And again for "Netto"
echo "</table><br /><hr><br />";
$query = "SELECT * FROM $ddato WHERE forhandler='Netto' ORDER BY vare";
$result = mysql_query($query);
$num = mysql_numrows($result);
$i=0;
echo "<table><tr><td><b>Netto</b></td></tr>";
while ($i < $num) {
$produkt=mysql_result($result,$i,"vare");
$antal=mysql_result($result,$i,"antal");
$enhed=mysql_result($result,$i,"enhed");
$forhandler=mysql_result($result,$i,"forhandler");
echo "<tr><td>" . $antal . " " . $enhed . " " . $produkt . "</td></tr>";
$i++;
}
echo "</table><br /><hr><br />";
//** And a again for "Bager"
$query = "SELECT * FROM $ddato WHERE forhandler='Bager' ORDER BY vare";
$result = mysql_query($query);
$num = mysql_numrows($result);
$i=0;
echo "<table><tr><td><b>Bager</b></td></tr>";
while ($i < $num) {
$produkt=mysql_result($result,$i,"vare");
$antal=mysql_result($result,$i,"antal");
$enhed=mysql_result($result,$i,"enhed");
$forhandler=mysql_result($result,$i,"forhandler");
echo "<tr><td>" . $antal . " " . $enhed . " " . $produkt . "</td></tr>";
$i++;
}
echo "</table><br /><hr><br />";
//** And again for "Fisk"
$query = "SELECT * FROM $ddato WHERE forhandler='Fisk' ORDER BY vare";
$result = mysql_query($query);
$num = mysql_numrows($result);
$i=0;
echo "<table><tr><td><b>Fisk</b></td></tr>";
while ($i < $num) {
$produkt=mysql_result($result,$i,"vare");
$antal=mysql_result($result,$i,"antal");
$enhed=mysql_result($result,$i,"enhed");
$forhandler=mysql_result($result,$i,"forhandler");
echo "<tr><td>" . $antal . " " . $enhed . " " . $produkt . "</td></tr>";
$i++;
}
echo "</table><br /><hr><br />";
mysql_close();
?>