Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
MySQL Update, Updating all records...
Old 10-11-2010, 11:59 PM MySQL Update, Updating all records...
Novice Talker

Posts: 11
Trades: 0
I am having trouble with the following portion of code:

Code:
if($total<5){
	$gamesToAdd = 5-$total;
	$addGames="SELECT gId FROM games WHERE gInCategory=$category_num AND gDate='0000-00-00 00:00:00' ORDER BY gId DESC LIMIT $gamesToAdd";

	$d = new db(0);
	$d->dir="/home/xiler84z/dbbackup/";
	$newGames=$d->fetch($addGames, "300");

foreach($newGames as $addGame)
	{
		$updateDate="UPDATE games SET gDate=NOW() WHERE gId=$addGame[gId]";
		mysql_query($updateDate);
		sleep(1);
	}
	$stop==FALSE;
}
The reason I am having trouble is because I don't think the MySQL query is paying attention to the "WHERE" part. The reason I think this is that when I run this code every single record that has a "0000-00-00 00:00:00" timestamp is being updated. This should be limited by the first MySQL query I do where I find the relevant "gId"s first.

What am I missing that is making all the records update? How can I only update the records returned by $addGames?

Thanks.
zenthoef is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-12-2010, 12:11 AM Re: MySQL Update, Updating all records...
Ultra Talker

Posts: 366
Name: Steve
Location: Miami, FL, Earth
Trades: 0
Best way to figure out what's going on is:

print($addGames);

...

print($updateDate);

Instead of executing the queries.... then your script will output the SQL being generated, and you can run that in a mysql query panel (e.g. phpMyAdmin) to see what's going on. If you're not seeing the results you expect, play with the query there to get it working how you want.
__________________
- Steve

President,
Please login or register to view this content. Registration is FREE
smoseley is offline
Reply With Quote
View Public Profile Visit smoseley's homepage!
 
Old 10-12-2010, 12:42 AM Re: MySQL Update, Updating all records...
Novice Talker

Posts: 11
Trades: 0
That is a good idea and I tried it.

I got:
Code:
SELECT gId FROM games WHERE gInCategory=1 AND gDate='0000-00-00 00:00:00' ORDER BY gId DESC LIMIT 3
Warning: Invalid argument supplied for foreach() in /home/user/public_html/file.php on line 102
So the $addGames looks correct and it works in myPhpAdmin.

However, it complains that the foreach argument is invalid. I suspect this is because the $addGames query is not being done. When I have that query take place, then nothing works. I think it is stuck in the foreach() and it never times out because I am not executing the $updateDate query.

In other words, I am still stuck and I'm pretty sure its the UPDATE statement in the foreach. Any other suggestions?
zenthoef is offline
Reply With Quote
View Public Profile
 
Old 10-12-2010, 09:12 AM Re: MySQL Update, Updating all records...
Ultra Talker

Posts: 366
Name: Steve
Location: Miami, FL, Earth
Trades: 0
Try this {
PHP Code:
if($total 5) {
     
$gamesToAdd 5-$total;
     
$addGames="SELECT gId FROM games WHERE gInCategory=$category_num AND gDate='0000-00-00 00:00:00' ORDER BY gId DESC LIMIT $gamesToAdd";
     
$d = new db(0);
     
$d->dir="/home/xiler84z/dbbackup/";
     
$newGames=$d->fetch($addGames"300");
     foreach(
$newGames as $addGame) {
         
$updateDate="UPDATE games SET gDate=NOW() WHERE gId=$addGame[gId]";
         print(
$updateDate."<br />");
         
$updateDate="UPDATE games SET gDate=NOW() WHERE gId='".$addGame["gId"]."'";
         print(
$updateDate."<br />");
        
//mysql_query($updateDate);
        //sleep(1);
     
}
     
$stop==FALSE;

I'm guessing the 2nd will be different than the first, and will execute the way you're expecting.
__________________
- Steve

President,
Please login or register to view this content. Registration is FREE

Last edited by smoseley; 10-12-2010 at 09:15 AM..
smoseley is offline
Reply With Quote
View Public Profile Visit smoseley's homepage!
 
Old 10-12-2010, 10:48 PM Re: MySQL Update, Updating all records...
Novice Talker

Posts: 11
Trades: 0
I can't fully test it right at this time, but I think that is what I am looking for! I'm a novice and I always get so confused about how to use all those double and single quotes...

Thanks!
zenthoef is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to MySQL Update, Updating all records...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15036 seconds with 12 queries