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
https://forums.phpfreaks.com/topic/201068-add-1-to-all-rows/
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
https://forums.phpfreaks.com/topic/201068-add-1-to-all-rows/#findComment-1054945
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.