I need to run multiple UPDATES in php on an SQL table - so I tried using:
$query="select Name, Age, Master.studentID from Ages, Master where Ages.studentID=Master.studentID";
$result = mysql_query($query) or die('Error123');
while ($line = @mysql_fetch_array($result))
{
$ID=$line['studentID'];
$Name=$line['Name'];
$Age=$line['Age'];
$Age=$Age+1;
$newquery="UPDATE Ages SET Age=$Age where studentID=$ID";
$result = mysql_query($newquery) or die("Error-LastU-".mysql_error());
echo "<p>Completed $Name</p>";
}
echo "<p>Totally Done!</p>";
I get back
Completed John
Totally Done!
However, if I remove the $result lines, such as
$query="select Name, Age, Master.studentID from Ages, Master where Ages.studentID=Master.studentID";
$result = mysql_query($query) or die('Error123');
while ($line = @mysql_fetch_array($result))
{
$ID=$line['studentID'];
$Name=$line['Name'];
$Age=$line['Age'];
$Age=$Age+1;
$newquery="UPDATE Ages SET Age=$Age where studentID=$ID";
echo "<p>Completed $Name</p>";
}
echo "<p>Totally Done!</p>";
I get back
Completed John
Completed Mike
Completed Bill
Completed Sally
Completed Tom
Completed Todd
Completed Jonny
Totally Done!
if I run it in PHPMyAdmin - I see there are 7 items in the Master table.
why is this just doing one of the queries and ending?
$query="select Name, Age, Master.studentID from Ages, Master where Ages.studentID=Master.studentID";
$result = mysql_query($query) or die('Error123');
while ($line = @mysql_fetch_array($result))
{
$ID=$line['studentID'];
$Name=$line['Name'];
$Age=$line['Age'];
$Age=$Age+1;
$newquery="UPDATE Ages SET Age=$Age where studentID=$ID";
$result = mysql_query($newquery) or die("Error-LastU-".mysql_error());
echo "<p>Completed $Name</p>";
}
echo "<p>Totally Done!</p>";
I get back
Completed John
Totally Done!
However, if I remove the $result lines, such as
$query="select Name, Age, Master.studentID from Ages, Master where Ages.studentID=Master.studentID";
$result = mysql_query($query) or die('Error123');
while ($line = @mysql_fetch_array($result))
{
$ID=$line['studentID'];
$Name=$line['Name'];
$Age=$line['Age'];
$Age=$Age+1;
$newquery="UPDATE Ages SET Age=$Age where studentID=$ID";
echo "<p>Completed $Name</p>";
}
echo "<p>Totally Done!</p>";
I get back
Completed John
Completed Mike
Completed Bill
Completed Sally
Completed Tom
Completed Todd
Completed Jonny
Totally Done!
if I run it in PHPMyAdmin - I see there are 7 items in the Master table.
why is this just doing one of the queries and ending?