|
Posted by J.O. Aho on 09/03/07 14:05
Captain Paralytic wrote:
> On 3 Sep, 13:10, "Matthew White" <mgw...@msn.com> wrote:
>>>> I have started using the new mysql_* extensions. Here is the code I am
>>>> trying to run:
>>>> $temp2 = "SELECT * FROM assignments2 WHERE daydue < '247' &&
>>>> progress !=
>>>> '100'";
>>>> $temp2 = mysqli_query($mysqli,$temp2) or
>>>> die(mysqli_error($mysqli));
>>>> $temp2 = mysqli_fetch_array($temp2) or
>>>> die(mysqli_error($mysqli));
Matthew, don't reuse variables in that manner, suddenly the variable with the
query is the variable containing the resource. You make your own code a lot
harder to follow, specially when you haven't looked on it for a while, you
will never know what the $temp2 will be when you jump down to line 100 and
have to fix some error you got.
$mysqli = new mysqli('server','login','pass','database');
$temp2 = "SELECT * FROM assignments2 WHERE daydue < 247 && progress <> 100";
$res=$mysqli->query($temp2);
if($mysqli->error) {
echo $mysqli->error;
flush();
ob_flush();
exit;
}
flush();
ob_flush();
$row=$res->fetch_array();
flush();
ob_flush();
>>>> This query doesn't work (though it throws no errors). Only when I change
>>>> the "<" to "<=" does the script work. Why doesn't the less than operator
>>>> work?
>>> "This query doesn't work",
>>> Very helpful this, very discriptive!
>>> What precisely doesn't work about it? Do you just get no data output?
>>> If so, please post some of the output from when it does "work".
>> When it fails, it just returns a blank page, disregarding all other code
>> below it. If it completes, it will display the names and dates of all
>> assignments that are overdue.- Hide quoted text -
>>
>> - Show quoted text -
>
> It can't return a blank page. It is a query. It returns a data
> resourse.
His script dies somewhere on the page before it's finished, so there is no
flushing of the output buffer, which makes the page to appear as an empty page.
The solution is to use flush()/ob_flush() after each thing done on the page,
this will then show the last thing that happens before the error, which will
make things a lot easier to fix, when you know where in the code you will be next.
Had this problem myself a couple of days ago, had gladly turned off the
buffering in php.ini, if it hadn't been that some of the older php scripts
will stop working as someone hasn't been smart enough when designing it and
had headers sent after outputs.
--
//Aho
Navigation:
[Reply to this message]
|