Jump to content


Photo

What's wrong?


  • Please log in to reply
36 replies to this topic

#21 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 September 2006 - 05:39 PM

$SQL = "UPDATE chibifriendspets SET lastDatefed = $fedtime, WHERE ...

Remove the comma after $fedtime
Legend has it that reading the manual never killed anyone.
My site

#22 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 16 September 2006 - 05:45 PM

try this...
<?php

session_start();
$session = session_id();

include ("../htm/siteinfo.htm"); 
include ("dbinfo.php");
include ("config.php");


 $SQL = "SELECT * FROM chibifriendspets WHERE monopetID = '".$_POST['monopetID']."'";

$result = mysql_query($SQL, $connection) or die("Error: ".mysql_error()."");
	$query_data = mysql_fetch_array($result);
	$hunger = $query_data['hunger'];
	$monopetName = $query_data['monopetName'];
	
	 $SQLB = "SELECT * FROM myitemschibi WHERE itemID = '".$_POST['itemID']."'";

$result2 = mysql_query($SQLB,$connection) or die("Error: ".mysql_error()."");
	$query_data = mysql_fetch_array($result2);
	$food = $query_data['food'];
	$itemName = $query_data['itemName'];
	
	$fedtime = strtotime("today");


if ($food == "Food")
	{
		$hunger--;
		mysql_query("DELETE FROM myitemschibi WHERE itemID = '".$_POST['itemID']."'");
		mysql_query("UPDATE chibifriendspets SET lastDatefed = '$fedtime' WHERE petID = '".$_POST['monopetID']."'");
		
		echo "<p>Yopu have used <b>".$itemName."</b> on <b>".$monopetName."</b>!</p>";
	}
	
?>


#23 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 16 September 2006 - 06:22 PM

It works, but it still doesn't decrease the hunger. Do I need to do more to save the decreased hunger in the database?
Schroedinger's Cat walks into a bar.
And doesn't.

#24 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 September 2006 - 06:35 PM

Yes.  In some query, you'll have to UPDATE the value of the hunger field.
Legend has it that reading the manual never killed anyone.
My site

#25 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 16 September 2006 - 06:36 PM

Ok.
Schroedinger's Cat walks into a bar.
And doesn't.

#26 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 16 September 2006 - 06:38 PM

How would i take $fedtime and make it so that if it's more then 1 day away it adds 1 to hunger?
Schroedinger's Cat walks into a bar.
And doesn't.

#27 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 September 2006 - 06:45 PM

Depends on the format of $fedtime in your database.

Basically you need to retrieve $fedtime; determine today's date; if they're significanylt different, incremnent hunger and write to database.

Try and do that yourself. Post back - with code - if your efforts are unsuccessful.
Legend has it that reading the manual never killed anyone.
My site

#28 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 16 September 2006 - 06:52 PM

i'm using

$query = "SELECT * FROM chibifriendspets WHERE monopetID = '$monopetID'";
   	$result = mysql_query($SQL,$connection);
	$query_data = mysql_fetch_array($result);
	$lastDatefed = $query_data['lastDatefed'];

$timespan = strtotime("$today - $lastDatefed");

$hours = strtotime("1 day");

if ($timespan >= $hours);
	{
		$hunger++;
		mysql_query("UPDATE chibifriendspets SET hunger = '$hunger' WHERE monopetID = '".$_POST['monopetID']."'");
	}

But noting happens. The lastDatefed for the pet i'm using to test it is 2006-08-29, which is a lot more then 24 hours from today.
Schroedinger's Cat walks into a bar.
And doesn't.

#29 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 16 September 2006 - 09:20 PM

What am I doing wrong?
Schroedinger's Cat walks into a bar.
And doesn't.

#30 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 September 2006 - 09:33 PM

It always helps debug if you echo out variables from time to time. If you add a line like echo $timespan after you 'calculate' it, you'll see just what the problem is ...

I think what you really want in order to compare with yyyy-mm-dd dates is something like:

if (date("Y-m-d", strtotime("-1 day")) < $lastDatefed) {
    echo "ooooo, I'm hungry"; // or whatever you want to do
}

Legend has it that reading the manual never killed anyone.
My site

#31 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 16 September 2006 - 09:45 PM

Nothing happens, I'm using

<? $query = "SELECT * FROM chibifriendspets WHERE monopetID = '$monopetID'";
   	$result = mysql_query($SQL,$connection);
	$query_data = mysql_fetch_array($result);
	$lastDatefed = $query_data['lastDatefed'];
	$hunger = $query_data['hunger'];

$timespan = strtotime("$today - $lastDatefed");

$hours = strtotime("1 day");

if (date("Y-m-d", strtotime("-1 day")) < $lastDatefed) {
    echo "I'm hungery";
	$hunger++; // or whatever you want to do
	mysql_query("UPDATE chibifriendspets SET hunger = '$hunger' WHERE monopetID = '".$_POST['monopetID']."'");	
} ?>

Schroedinger's Cat walks into a bar.
And doesn't.

#32 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 September 2006 - 10:08 PM

What's wrong? My logic.

if ($datelastfed < date("Y-m-d", strtotime("-1 day"))) {
echo "One hungry hippo";
}

Legend has it that reading the manual never killed anyone.
My site

#33 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 17 September 2006 - 12:55 AM

Now it increases their hunger even if you fed them today. It also doesn't update the time last fed. For that I'm using:

$today = strtotime("today");


if ($food == "Food")

{

$hunger--;	

mysql_query("DELETE FROM myitemschibi WHERE itemID = '".$_POST['itemID']."'");
mysql_query("UPDATE chibifriendspets SET lastDatefed = '$today' WHERE monopetID = '".$_POST['monopetID']."'");

Schroedinger's Cat walks into a bar.
And doesn't.

#34 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 17 September 2006 - 12:57 AM

I'm trying to get it so that you use food on them and it decreases their hunger, but it increases by 1 if you havn't fed tem for 24 hours.
Schroedinger's Cat walks into a bar.
And doesn't.

#35 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 17 September 2006 - 12:58 AM

It also is decreasing for all of the user's pets instead of just the 1 they click on.
Schroedinger's Cat walks into a bar.
And doesn't.

#36 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 17 September 2006 - 02:05 PM

Do you know what's wrong?
Schroedinger's Cat walks into a bar.
And doesn't.

#37 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 17 September 2006 - 02:44 PM

No idea what's wrong as we're not looking at the whole script exactly as you have it in it's "not quite working" state.  Take a careful look at your logic, your database queries, and any conditional structures in your script and that should give you some clues.

Remember that while debugging, it's worthwhile echoing all queries so you can see exactly what the querystrings are (not always what you think they should be), and include error traps on all the mysql_query statements.  How to do both is strewn through this thread as examples.
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users