Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP and MySQL problem

Status
Not open for further replies.

webmastadj84

IS-IT--Management
Aug 23, 2006
86
US
Ok, here is the problem. This code works. The only part that is not working correctly is the bottom 5 lines. The loop works but it does not insert the information into the table and I get no error messages. Here is the full code; remember, everything works but the last 5 lines.

===============================================
$sqlGetNumbers = "SELECT * FROM `lotterynumbers`";
$conn = mysql_connect("localhost","**********","***********");
$result = mysql_query($sqlGetNumbers, $conn);
$LoopCount = 1;

while ($LoopCount < 54 ) {
$NumberTally[$LoopCount] = 0;
$LoopCount = $LoopCount + 1;
}

while ($newArray = mysql_fetch_array($result)) {
$date = $newArray['date'];
$n1 = $newArray['n1'];
$n2 = $newArray['n2'];
$n3 = $newArray['n3'];
$n4 = $newArray['n4'];
$n5 = $newArray['n5'];
$n6 = $newArray['n6'];


$NumberTally[$n1] = $NumberTally[$n1] + 1;
$NumberTally[$n2] = $NumberTally[$n2] + 1;
$NumberTally[$n3] = $NumberTally[$n3] + 1;
$NumberTally[$n4] = $NumberTally[$n4] + 1;
$NumberTally[$n5] = $NumberTally[$n5] + 1;
$NumberTally[$n6] = $NumberTally[$n6] + 1;
}

$LoopCount = 1;

while ($LoopCount < 54) {
$sqlUpdate = "INSERT INTO `lottostats` (`Number`,`Count`,Precent`,`Updated`) VALUES ('$LoopCount','$NumberTally[$LoopCount]','0.00','0')";
mysql_query($sqlUpdate, $conn);
echo "<tr><td>$LoopCount</td><td>$NumberTally[$LoopCount]</td></tr>";
$LoopCount = $LoopCount + 1;
}
===============================================
 
Try changing to

Code:
while ($LoopCount < 54) {
  $numTally = $NumberTally[$LoopCount];  // <<<<<<<<
  $sqlUpdate = "INSERT INTO `lottostats` (`Number`,`Count`,Precent`,`Updated`) VALUES ('$LoopCount','$numTally','0.00','0')";  // <<<<<<<<
  mysql_query($sqlUpdate, $conn);
  echo "<tr><td>$LoopCount</td><td>$NumberTally[$LoopCount]</td></tr>";
  $LoopCount = $LoopCount + 1;
}

Hope this works!


Jose
 
Actually,

I think this should get the job done
Code:
while ($LoopCount < 54) {
  $numTally = $NumberTally[$LoopCount];  // <<<<<<<<
  $sqlUpdate = "
  INSERT INTO `lottostats` (`Number`,`Count`,Precent`,`Updated`) VALUES ('" . $LoopCount . "','" . $numTally . "','0.00','0')";  // <<<<<<<<
  mysql_query($sqlUpdate, $conn);
  echo "<tr><td>$LoopCount</td><td>$NumberTally[$LoopCount]</td></tr>";
  $LoopCount++;
}

Regards,

Jose
 
One useful thing I do is to code my queries this way.

Code:
$result = MYSQL_QUERY($sql);
if ($result == 1):
  echo "Success!";
else:
  echo "Failure!";
  echo $sql;
endif;

This helps a lot to debug things and actually tells you if it was successful or not.

Nick

Creator of - Movie Reviews, Movie Lists, and much more!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top