Jump to content

[SOLVED] subtracting CURDATE... anyhelp?


phpstuck

Recommended Posts

OK I get the following error when running this on my server.... any ideas?

 

"Title: 650 New!!

Warning: mysql_fetch_array(): 4 is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\jhc\csidisplay.php on line 6"

 

It returns the tag number and the phrase New!! but develops this error, any help is greatly appreciated!

 

<?
include "db.php";

$sql_date = mysql_query("SELECT tag, ro, veh, cust, phone, warr, appt, wait, tech, type, notes, dateadded , ( TO_DAYS(CURDATE()) - TO_DAYS(dateadded) ) as date_diff FROM repairs") or die (mysql_error());

    while(list($tag, $ro, $veh, $cust, $phone, $warr, $appt, $wait, $tech, $type, $notes, $dateadded, $date_diff)=mysql_fetch_array($sql_date)){

        if($date_diff > 14){

        $new = "y";

        }

    echo "Title: $tag";

    if($new == "y"){

        echo " <font color='red'>New!!</font>";

    }

    mysql_free_result($sql_date);

    unset($new);

  }



?>

Link to comment
Share on other sites

Oh well I will just make it invisible for now using the trusty ole'

 

<?
include "db.php";
error_reporting(~E_ALL);

$sql_date = mysql_query....

 

But I still sure would like to know what is causing the warning to pop up there... If anyone knows I am watching for the answer so that I can learn from my mistake.

Link to comment
Share on other sites

Always dump the variables... you'll learn to troubleshoot your own scripts quickly.

 

Run this script and post the results:

 

<?
include "db.php";

$sql_date = mysql_query("SELECT tag, ro, veh, cust, phone, warr, appt, wait, tech, type, notes, dateadded , ( TO_DAYS(CURDATE()) - TO_DAYS(dateadded) ) as date_diff FROM repairs") or die (mysql_error());

$row = mysql_fetch_array($sql_date);

echo"$sql_date<br /><pre>";
print_r($row);
die("</pre>");

   while(list($tag, $ro, $veh, $cust, $phone, $warr, $appt, $wait, $tech, $type, $notes, $dateadded, $date_diff)=mysql_fetch_array($sql_date)){

       if($date_diff > 14){

       $new = "y";

       }

   echo "Title: $tag";

   if($new == "y"){

       echo " <font color='red'>New!!</font>";

   }

   mysql_free_result($sql_date);

   unset($new);

 }



?>

 

PhREEEk

Link to comment
Share on other sites

mysql_free_result($sql_date);<--- that i guess is the prob you free the result inside the loop so when the loop run for the second time no more resource data to be used

 

Nice catch.. yes, proper code formatting would have made that so much more apparent.

Also, to the OP, you don't need to free the result set unless you really need to, which is rather rare.

So, 2 solutions:

 

<?php
include "db.php";

$sql_date = mysql_query("SELECT tag, ro, veh, cust, phone, warr, appt, wait, tech, type, notes, dateadded , ( TO_DAYS(CURDATE()) - TO_DAYS(dateadded) ) as date_diff FROM repairs") or die (mysql_error());

while(list($tag, $ro, $veh, $cust, $phone, $warr, $appt, $wait, $tech, $type, $notes, $dateadded, $date_diff)=mysql_fetch_array($sql_date)) {
    if($date_diff > 14) {
        $new = "y";
    }
    echo "Title: $tag";
    if($new == "y") {
        echo " <font color='red'>New!!</font>";
    }
    unset($new);
}
mysql_free_result($sql_date);

?>

 

Or just

 

<?php
include "db.php";

$sql_date = mysql_query("SELECT tag, ro, veh, cust, phone, warr, appt, wait, tech, type, notes, dateadded , ( TO_DAYS(CURDATE()) - TO_DAYS(dateadded) ) as date_diff FROM repairs") or die (mysql_error());

while(list($tag, $ro, $veh, $cust, $phone, $warr, $appt, $wait, $tech, $type, $notes, $dateadded, $date_diff)=mysql_fetch_array($sql_date)) {
    if($date_diff > 14) {
        $new = "y";
    }
    echo "Title: $tag";
    if($new == "y") {
        echo " <font color='red'>New!!</font>";
    }
    unset($new);
}

?>

 

PhREEEk

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.