Jump to content

add +1 to all rows?


ferrin

Recommended Posts

this is probably really basic, but how do i go about adding '1' to each item in a row?

 

for example, i have a cron set to run a page every hour, and every hour it updates a number under the column 'time' for each column with breeding = 'yes'.

 

then after the number reaches 20, breeding is reset to = 'no'.

 

this is my code (what i figured out so far), but it's not doing anything.

 

 

don't kill me, i'm still a newb.  :wtf:

 

 

<?php

if ($number < 20)
{
$con = mysql_connect ("gamepets.db.6086537.hostedresource.com","gamepets","----") or die(mysql_error());
mysql_select_db("gamepets")or die("cannot select DB");
//
// ------------ GET NUMBER FROM DATABASE  --------

$sql=("SELECT time FROM test WHERE breeding = 'yes'");


$number=mysql_query($sql);

$number++;

// ------------- ADD +1 ($add) to time ----------------

// Connect to server and select database.
$con = mysql_connect ("gamepets.db.6086537.hostedresource.com","gamepets","----") or die(mysql_error());
mysql_select_db("gamepets")or die("cannot select DB");


$number = mysql_query("UPDATE test SET time='$number' WHERE breeding='yes'") 
or die(mysql_error()); 
}
else 
{
$con = mysql_connect ("gamepets.db.6086537.hostedresource.com","gamepets","----") or die(mysql_error());
mysql_select_db("gamepets")or die("cannot select DB");


$number = mysql_query("UPDATE test SET breeding='no' WHERE time='100'") 
or die(mysql_error()); 
}

?>

Link to comment
Share on other sites

Your code is seriously flawed. Firstly, you have an if statement that checks to see if a non-existent variable ($number) is less than 20. $number does not exist yet. Even when it does exist, no where in your code is it ever set to a number.

Link to comment
Share on other sites

Like thorpe said your code is seriously flawed:

 

if ($number < 20)

 

This is what -sort of- happens when it executes

 

1. $number?

2. $number = null

3. $number = (int) null

4. $number = 0

5. $number < 20

6. true

 

$number=mysql_query($sql);
$number++;

 

1. $number = Resource #[iD]

2. $number++

3. $number = 0

 

$number = mysql_query("UPDATE test SET time='$number' WHERE breeding='yes'") 

 

$number = Resource #[iD]

 

1) As you can see $number never goes higher then 0 2) If you are hoping $number will keep increasing with every request, you are dead wrong.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.