473,394 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

while,foreach and select

Hi there ive trying to make a game based on php and currently ive some
problems with this part of the script, i've tryed to fix it alone with out
success...
This is the script

<?php
include("db.php");
include("debug.php");
set_time_limit(0);
dbConnect("sessions");
$sqlUID = "SELECT UserID FROM Star_USER";
$UsersID = mysql_query($sqlUID) or die("Query failed");

while ($UserID = mysql_fetch_array($UsersID,MYSQL_ASSOC)) {
foreach ($UserID as $UID){
$sqlSz = "SELECT Size FROM Star_USER WHERE UserID = '$UID'";
$UserSize = mysql_query($sqlSz);
$OldUS = mysql_fetch_array($UserSize);
$AKA=$OldUS[0]
$UpdateSTR = mysql_query("UPDATE Star_USER SET NW='$AKA' WHERE
UserID='$UID'");
}
}
?>

What i wanted is that each time i run the script it will update the NW field
in the database based on the size of the player and this for each one of
them.
It all works if i take the select statment from inside the foreach, but i
need him there soo i can have the size of the player.
Anyone sees a problem with the script or do i need to find another away to
do it?
Thx

Marco
Jul 17 '05 #1
4 4541
Marco wrote:

<?php
include("db.php");
include("debug.php");
set_time_limit(0);
dbConnect("sessions");
$sqlUID = "SELECT UserID FROM Star_USER";
$UsersID = mysql_query($sqlUID) or die("Query failed");

while ($UserID = mysql_fetch_array($UsersID,MYSQL_ASSOC)) {
foreach ($UserID as $UID){
$sqlSz = "SELECT Size FROM Star_USER WHERE UserID = '$UID'";
$UserSize = mysql_query($sqlSz);
$OldUS = mysql_fetch_array($UserSize);
$AKA=$OldUS[0]
$UpdateSTR = mysql_query("UPDATE Star_USER SET NW='$AKA' WHERE
UserID='$UID'");
}
}
?>

What i wanted is that each time i run the script it will update the NW field
in the database based on the size of the player and this for each one of
them.
It all works if i take the select statment from inside the foreach, but i
need him there soo i can have the size of the player.
Anyone sees a problem with the script or do i need to find another away to
do it?


I am not sure of the point of your script. The following should set the field
NW to the value of field Size in each record (I think -- I didn't get much sleep
last night -- be careful).

<?php
include("db.php");
include("debug.php");
set_time_limit(0);
dbConnect("sessions");
$sqlUID = "UPDATE Star_USER SET NW = Size";
$UsersID = mysql_query($sqlUID) or die("Query failed");
echo ("<br><br>".mysql_affected_rows()." rows affected.<br><br>");
?>

If you need the size of the player for other uses, you can consolidate your
select statements, instead of using two. This reduces load on the server.

<?php
include("db.php");
include("debug.php");
set_time_limit(0);
dbConnect("sessions");
$sqlUID = "SELECT UserID, Size FROM Star_USER";
$UsersID = mysql_query($sqlUID) or die("Query failed");

while ($UserID = mysql_fetch_array($UsersID)) {
//Your game code that uses the player's size goes here
$UpdateSTR = mysql_query("UPDATE Star_USER SET NW='".$UserID['Size']."'
WHERE UserID='".$UserID['UserID']."'");
}

Regards,
Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com

I have a spam filter. Please include "PHP" in the
subject line to ensure I'll get your message.
Jul 17 '05 #2
On 2004-01-13, Marco <> wrote:
Hi there ive trying to make a game based on php and currently ive some
problems with this part of the script, i've tryed to fix it alone with out
success...
This is the script

<?php
include("db.php");
include("debug.php");
set_time_limit(0);
dbConnect("sessions");
$sqlUID = "SELECT UserID FROM Star_USER";
$UsersID = mysql_query($sqlUID) or die("Query failed");

while ($UserID = mysql_fetch_array($UsersID,MYSQL_ASSOC)) {
foreach ($UserID as $UID){
$sqlSz = "SELECT Size FROM Star_USER WHERE UserID = '$UID'";
$UserSize = mysql_query($sqlSz);
$OldUS = mysql_fetch_array($UserSize);
$AKA=$OldUS[0]
$UpdateSTR = mysql_query("UPDATE Star_USER SET NW='$AKA' WHERE
UserID='$UID'");
}
}
?>

What i wanted is that each time i run the script it will update the NW field
in the database based on the size of the player and this for each one of
them.
It all works if i take the select statment from inside the foreach, but i
need him there soo i can have the size of the player.
Anyone sees a problem with the script or do i need to find another away to
do it?


You already got a got hint on affected_rows etc, but have you ever
thought about what happens when this script is called by 2 users, on
more or less the same time? i'm affraid it might ruin your database.
have a look at lock and unlock or transactions in your mysql manual ;)

--
http://home.mysth.be/~timvw
Jul 17 '05 #3

"Shawn Wilson" <sh***@glassgiant.com> wrote in message
news:40***************@glassgiant.com...
I am not sure of the point of your script. The following should set the field NW to the value of field Size in each record (I think -- I didn't get much sleep last night -- be careful).

<?php
include("db.php");
include("debug.php");
set_time_limit(0);
dbConnect("sessions");
$sqlUID = "UPDATE Star_USER SET NW = Size";
$UsersID = mysql_query($sqlUID) or die("Query failed");
echo ("<br><br>".mysql_affected_rows()." rows affected.<br><br>");
?>

If you need the size of the player for other uses, you can consolidate your select statements, instead of using two. This reduces load on the server.

<?php
include("db.php");
include("debug.php");
set_time_limit(0);
dbConnect("sessions");
$sqlUID = "SELECT UserID, Size FROM Star_USER";
$UsersID = mysql_query($sqlUID) or die("Query failed");

while ($UserID = mysql_fetch_array($UsersID)) {
//Your game code that uses the player's size goes here
$UpdateSTR = mysql_query("UPDATE Star_USER SET NW='".$UserID['Size']."'
WHERE UserID='".$UserID['UserID']."'");
}

Regards,
Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com

I have a spam filter. Please include "PHP" in the
subject line to ensure I'll get your message.


Indeed your second script is more what im looking for, ill work out the
other issues.

Thx

Marco
Jul 17 '05 #4

"Tim Van Wassenhove" <eu**@pi.be> wrote in message
news:bu************@ID-188825.news.uni-berlin.de...
On 2004-01-13, Marco <> wrote:
Hi there ive trying to make a game based on php and currently ive some
problems with this part of the script, i've tryed to fix it alone with out success...
This is the script

<?php
include("db.php");
include("debug.php");
set_time_limit(0);
dbConnect("sessions");
$sqlUID = "SELECT UserID FROM Star_USER";
$UsersID = mysql_query($sqlUID) or die("Query failed");

while ($UserID = mysql_fetch_array($UsersID,MYSQL_ASSOC)) {
foreach ($UserID as $UID){
$sqlSz = "SELECT Size FROM Star_USER WHERE UserID = '$UID'";
$UserSize = mysql_query($sqlSz);
$OldUS = mysql_fetch_array($UserSize);
$AKA=$OldUS[0]
$UpdateSTR = mysql_query("UPDATE Star_USER SET NW='$AKA' WHERE
UserID='$UID'");
}
}
?>

What i wanted is that each time i run the script it will update the NW field in the database based on the size of the player and this for each one of
them.
It all works if i take the select statment from inside the foreach, but i need him there soo i can have the size of the player.
Anyone sees a problem with the script or do i need to find another away to do it?


You already got a got hint on affected_rows etc, but have you ever
thought about what happens when this script is called by 2 users, on
more or less the same time? i'm affraid it might ruin your database.
have a look at lock and unlock or transactions in your mysql manual ;)

--
http://home.mysth.be/~timvw


Indeed I didn't think about it, this script will only run hourly but Im not
sure what happens if 2 people run it at the same time, probably it wont do
anything good to the DB. Thx for the advice, Im new to PHP (like to all
languages) and I basically learn it step by step when I face a problem.
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Marco | last post by:
Hi there ;) Im building a MySQL table for a menssaging system, its a table that has 3 fields de UserID, MTime and Mess. My problem is that i cant find a way that using only a mysql query i get...
2
by: Marco | last post by:
We can read this comment at php.net >jon >05-Nov-2003 10:06 >According to my tests, the "do...while" control structure actually seems to be ~40% faster than the "for" control structure. At...
5
by: Gustavo Randich | last post by:
Hello, I'm writing an automatic SQL parser and translator from Informix to DB2. Now I'm faced with one of the most difficult things to translate, the "foreach execute procedure" functionality...
8
by: Nancy | last post by:
Greetings: First, I apologize if my posting format is improper. The code below does what I intended it to do, but presently only displays 1 table entry. I've grown it to this point, but really...
4
by: Ja NE | last post by:
(as first, I have to apologize for my clumsy English...) here is my situation: // I'm stupid... sort of. ;) I would like to see how many pictures have "lost" their albums - I have table...
4
by: Gary | last post by:
Hi, I get this error " " when my web page run, what does it mean? Hope someone can help!!! Gary
7
by: david | last post by:
I need 5 queries from the database, which I display in a php foreach loop the following way. $query1 = $DB->query("SELECT ... DESC LIMIT 20"); $query2 = $DB->query("SELECT ... DESC LIMIT 20");...
2
by: recordlovelife | last post by:
So I am trying to display a title, date, and content of a wordpress blog. Word press provides nice drop in functions to get the job done with simple names like "the_title", and the "the_content" But...
5
by: dhanashivam | last post by:
hi all i am doing a web site with single sign on technique. I am getting the error "COMException (0x80072020): An operations error occurred" while executing the statement foreach (SearchResult...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.