radio_active Posted December 1, 2008 Posted December 1, 2008 Hey there Im working on a script right now and to make it more effecient im going to need to use a " For() loop with a counter" Can someone supply just the base code of a for loop with a counter that i can work off =) Thanks Quote
Vortex Posted December 1, 2008 Posted December 1, 2008 Re: Need base code to work off. for ($i = 0; $i < 5; $i++) { echo $i . " "; } Outputs 0 1 2 3 4 See: control-structures.for Quote
Haunted Dawg Posted December 1, 2008 Posted December 1, 2008 Re: Need base code to work off. //Your starting number & Ending number $start_point = 0; $end_pont = 5; for($i = $start_point; $i < $end_point; $i++) //What we do here is the following: // $i = $start_point == your starting number // $i = $end_point == your ending number // $i++ == counts to that number to stop //Start the loop { //echo out your restult echo $i.' '; //close the loop } Hope thats a good description to help you. Quote
radio_active Posted December 1, 2008 Author Posted December 1, 2008 Re: Need base code to work off. Yeah thanks alot. Basically i have a query selecting 3 ids from a table in the DB. Now i need to select those 3 IDs and send 3 different numbers to that users account. So i figured if i used a for() loop with a counter that would be the best way to do it? Quote
Haunted Dawg Posted December 2, 2008 Posted December 2, 2008 Re: Need base code to work off. I think a while function would be best. //Your ids bellow $array = array(1,2,3); //Fetch rows $row = mysql_query("SELECT userid FROM users WHERE userid=1 AND userid=2 AND userid=3"); //Count / leave $i = -1; //fetch $row values while($soc = mysql_fetch_assoc($row)) //open loop { //random number $rand = rand(1,10); //count up $i++ //Event user with random number event_add($soc[$array[$i]],"Random Number: ".$rand."."); //if $i = 3 exit script and cloose loop if($i == 2) { exit; } //End loop } That should help i hope. :lol: Quote
radio_active Posted December 2, 2008 Author Posted December 2, 2008 Re: Need base code to work off. Hmmmm, i dont think that will do it. Im selecting three IDs from a table that i have. A userid is in each ID (Not selecting from the users table) Then once they are selected im sending three differents precentages of money out of a total lot. The reason i need the loop is obviously for looping the Event ad and the update money etc and i thought the counter for the different percentages being sent which is why i came to the conclusion of a for() loops witha counter, lol... Ill contact you on msn. Quote
Haunted Dawg Posted December 2, 2008 Posted December 2, 2008 Re: Need base code to work off. A while function can do that for you. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.