Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2005

    trouble passing variable to SQL

    Hey there,
    i have a tricky one here
    i am having trouble passing a variable to be either a field name or a value.

    when i run this
    $Day = $_GET["Day"];
    $Month = $_GET["Month"];
    $date = "2005-".$Month."-";
    $date .= $Day;
    function Hist($Unit, $date){    
         $result = mysql_query("SELECT Daily FROM RainGaugeHistory WHERE Sensor_ID = {$Unit} AND `Date`> {$date}");
          if ($num == "FALSE"){
             $Unit = 'No History';
             return $Unit;            
             while &#40;$i < $num&#41;&#123;
                echo $i;
                echo nl2br&#40;"\n"&#41;;            
                $DayTotal = mysql_result&#40;$result,$i,"Daily"&#41;;
                $Daily = $Daily + $DayTotal;
                $Today = OneDay&#40;$Unit&#41;;
                $Unit = $Daily + $Today;
                return $Unit;
    $Lab = Hist&#40;'515',$date&#41;;
    i am trying to add up the daily totals from a daily updated history file
    trouble is, when i run it, it selects every record for the unit except for only those after the $date.
    i have tried changing the field type from date to VARCHAR(10) but that wasn't it helping either. maybe (probably) there is a much better way to do this, i am really open for any suggestion that may prevent more hair loss.

  2. #2
    Erm, there is a better way to do it. I worked out that storing it as a 10 digit integer (if time of day doesn't matter).

    Then you can use the date() function and time() functions.

    take a look at this code (and what it does) It should help you out.

    $time = time&#40;&#41;; 
    echo $time; 
    echo "
    echo date&#40;'jS F Y H&#58;i&#58;s', $time&#41;;  
    echo "
    echo strtotime&#40;"27 July 2005"&#41;, "\n"; 
    echo "
    echo strtotime&#40;date&#40;'j F Y', mktime&#40;0, 0, 0, 12, 25, 1984&#41;&#41;&#41;;
    "I am not an alcoholic, alcoholics go to meetings"
    Registered Linux user = #372327

  3. #3
    Just Joined!
    Join Date
    Aug 2005
    thanks, i finally got it working in testing but i didnt have to keep the date as a VARCHAR
    thats really cooll
    thanks for the clip


  4. $spacer_open
  5. #4
    It'd be more sensible to let MySQL SUM the field, surely?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts