i got to this version:
Code:
<?
$result = mysql_query("SELECT customers_id
, customers_name
, customers_email_address
, billing_state
, customers_telephone
, COUNT(orders_id) AS number_of_orders
FROM orders
WHERE date_purchased >= '2008-12-01'
AND date_purchased < '2008-12-25'
GROUP BY customers_id,
customers_name,
customers_email_address,
billing_state,
customers_telephone
HAVING number_of_orders >= 5
ORDER
BY RAND() LIMIT 1
");
while($row = mysql_fetch_array($result)); {
$query = mysql_query("SELECT * FROM tombola");
$queryrows = mysql_num_rows($query);
while($row2 = mysql_fetch_array($query)); {
if ($queryrows > 0) {
echo "Castigatorul tombolei de craciun a fost deja desemnat!<br>";
//$past = mysql_query("SELECT * from tombola");
// while ($row2 = mysql_fetch_array($past)) {
echo "Castigatorul este ".$row2["customers_name"]."(".$row2["customers_email_address"].")<br><br>Telefon: ".$row2["customers_telephone"]."<br>Oras: ".$row2["billing_state"]." <br><br>".$row2["customers_name"]." a comandat ".$row2["number_of_orders"]." coduri!";
//}
}else {
$result2 = mysql_query("SELECT customers_id
, customers_name
, customers_email_address
, billing_state
, customers_telephone
, COUNT(orders_id) AS number_of_orders
FROM orders
WHERE date_purchased >= '2008-12-01'
AND date_purchased < '2008-12-25'
GROUP BY customers_id,
customers_name,
customers_email_address,
billing_state,
customers_telephone
HAVING number_of_orders >= 5
ORDER
BY RAND() LIMIT 1
");
while($row5 = mysql_fetch_array($result2)); {
mysql_query("INSERT into tombola values('".$row5['customers_name']."','".$row5['customers_email_address']."','".$row5['billing_state']."','".$row5['customers_telephone']."','".$row5['number_of_orders']." ')");
$now = mysql_query("SELECT * from tombola");
while ($row3 = mysql_fetch_array($now)) {
echo "Castigatorul este ".$row3["customers_name"]."(".$row3["customers_email_address"].")<br><br>Telefon: ".$row3["customers_telephone"]."<br>Oras: ".$row3["billing_state"]." <br><br>".$row3["customers_name"]." a comandat ".$row3["number_of_orders"]." coduri!";
}}
}
}}
?>
the if works ok... but when my table is zero i get an empty INSERT on all fields...
any idea where is the mistake?
Bookmarks