$html = ' some html here <br>';
function sql($mysqli,$html){
$stmt = $mysqli->prepare("SELECT * FROM `jobs` WHERE `out` is null");
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($job_id,$vin,$yr,$mk,$mdl,$color,$miles_in,$miles_out,$quoted,$price,$phone,$customer,$bal,$tax,$msg,$in,$out);
$stmt = $mysqli->prepare("SELECT * FROM jobs a WHERE a.in between ? and ?");
$stmt->bind_param('ss', $startday, $endday);
$startday = '2013-01-01';
$endday = '2013-12-31';
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($job_id,$vin,$yr,$mk,$mdl,$color,$miles_in,$miles_out,$quoted,$price,$phone,$customer,$bal,$tax,$msg,$in,$out);
while($stmt->fetch()){
Below is the same line with two different approaches: the commented part works but I cannot get the function to add the same values to the html string and then return it to the script when done with the php code.
$html.= $vin.' - '.$count.' <br> '; // echo $vin.' - '.$count.' <br> ';
$count++;
}
return $html;
}
sql($mysqli,$html);
echo $html;
My output from this is 'some html here' this is because that is how the string was defined. I'm hoping to get this function to add values pulled from the mysql query and then add them to a string that I can print out at the end of all the php. the output of the function if we use echo instead of $html concatenation is
12345 - <br>
123 - 1 <br>
1236485 - 2 <br>
any ideas?
That's because $html
is passed by value and its new value is returned from the function itself.
Echoing out the result of sql()
itself will produce the right value.
echo sql($mysqli,$html);
Alternatively, you could reassign the new value to $html
first:
$html = sql($mysqli, $html);
echo $html;
Pass it by reference:
function sql($mysqli,&$html){
Try using echo sql($mysqli, $html);
Perhaps your issue is that your $startday is after your $endday. The order matters with 'between'. Also, you probably want to include the time part as well in your start and end days, otherwise if your start and end day are the same date, you won't get the results for that day. Like this: WHERE a.in BETWEEN '2013-04-01 00:00:00' AND '2013-04-01 23:59:59'