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
Old 11-05-2004, 05:31 AM Loop
Manson's Avatar
Super Talker

Posts: 106
Location: South Wales, UK
Trades: 0
Hi all,

I am trying to write a script that will update numerous entries of the same field. In this case the credits of peoples accounts. The thing is i'm not entirely sure if this would work, i've tested it and it came up blank so I must have done something wrong.

Here's the code:

PHP Code:
<?php

include 'db.php';

$id 1;

while(
$id 201){

$get mysql_query("SELECT * FROM members WHERE id='$id'");
$credit mysql_fetch_array($get['credits']);
$credits $credit 100;

$sql mysql_query("UPDATE members SET credits='$credits' WHERE id='$id'") or die (mysql_error());

$id $id 1;
}

if(!
$sql){
echo 
'Error';
}else{
echo 
'Complete';
include 
'test.html';
}
?>
Thanks,

Manson
__________________
Admin of
Please login or register to view this content. Registration is FREE
Manson is offline
Reply With Quote
View Public Profile Visit Manson's homepage!
 
 
Register now for full access!
Old 11-05-2004, 08:52 AM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
Declare $sql outside of the while loop. It is a matter of scope in that you declare $sql nowhere until inside the while loop -- therefore, as far as PHP is concerned, that is the only place it exists. The way it is written now, your check if(!$sql) pass because $sql at that point is null. Also, even if you had declared $sql above the while loop, when you check it in the end, it will contain only the value of the very last loop iteration.

I am not sure why you are getting a blank screen, but you may want to start with a smaller set of data to update (perhaps all the id's under 5) and put some debug regarding the value of each $sql.
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 11-05-2004, 02:07 PM
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Instead of $id = $id + 1; Would it be better to use $i++ ??

Im not sure the correct syntaxes for it though


Lothop
__________________
Websites Created;
warscope.com
ratepayers.org.nz
lothop is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Loop
 

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.28683 seconds with 12 queries