trouble passing variable to SQL
Posted: Wed Aug 03, 2005 10:06 pm
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
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.
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
Code: Select all
$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}");
$num=mysql_numrows($result);
if ($num == "FALSE"){
$Unit = 'No History';
return $Unit;
}
else{
$i=0;
while ($i < $num){
echo $i;
echo nl2br("\n");
$DayTotal = mysql_result($result,$i,"Daily");
$Daily = $Daily + $DayTotal;
$i++;
$Today = OneDay($Unit);
$Unit = $Daily + $Today;
return $Unit;
}
}
}
$Lab = Hist('515',$date);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.