Error with < in SQL

Error with < in SQL

am 02.09.2007 22:42:24 von Matt White

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));

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?

Re: Error with < in SQL

am 02.09.2007 23:37:09 von zeldorblat

On Sep 2, 4:42 pm, "Matthew White" 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));
>
> 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?

What datatype is daydue? Why are you enclosing numbers (247 and 100)
in quotes?

Re: Error with < in SQL

am 03.09.2007 01:05:28 von Matt White

"ZeldorBlat" wrote in message
news:1188769029.148282.69930@w3g2000hsg.googlegroups.com...
> On Sep 2, 4:42 pm, "Matthew White" 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));
>>
>> 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?
>
> What datatype is daydue? Why are you enclosing numbers (247 and 100)
> in quotes?
>

"daydue" is an integer. The numbers are in quotes because that's how I
usually enclose data values in SQL queries, be they numbers or otherwise.

Matt

Re: Error with < in SQL

am 03.09.2007 11:02:51 von Captain Paralytic

On 2 Sep, 21:42, "Matthew White" 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));
>
> 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".

Re: Error with < in SQL

am 03.09.2007 14:10:54 von Matt White

"Captain Paralytic" wrote in message
news:1188810171.687472.262900@g4g2000hsf.googlegroups.com...
> On 2 Sep, 21:42, "Matthew White" 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));
>>
>> 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.

Re: Error with < in SQL

am 03.09.2007 14:35:51 von Captain Paralytic

On 3 Sep, 13:10, "Matthew White" wrote:
> "Captain Paralytic" wrote in message
>
> news:1188810171.687472.262900@g4g2000hsf.googlegroups.com...
>
>
>
>
>
> > On 2 Sep, 21:42, "Matthew White" 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));
>
> >> 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.

Now I asked you to "please post some of the output from when it does
"work"."

Instead you told me about the data that the program displays on a web
page (I assume).

Now can you please post some of the output FROM THE QUERY!

Re: Error with < in SQL

am 03.09.2007 15:47:35 von Matt White

"Captain Paralytic" wrote in message
news:1188822951.234785.7490@19g2000hsx.googlegroups.com...
> On 3 Sep, 13:10, "Matthew White" wrote:
>> "Captain Paralytic" wrote in message
>>
>> news:1188810171.687472.262900@g4g2000hsf.googlegroups.com...
>>
>>
>>
>>
>>
>> > On 2 Sep, 21:42, "Matthew White" 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));
>>
>> >> 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.
>
> Now I asked you to "please post some of the output from when it does
> "work"."
>
> Instead you told me about the data that the program displays on a web
> page (I assume).
>
> Now can you please post some of the output FROM THE QUERY!

The query returns a mysqli_result object, then stalls on the
mysqli_fetch_array. This results in a blank page. If I removed the <, the
query returns the same object, and returns an array after
mysqli_fetch_array. That's the only ouput.

Re: Error with < in SQL

am 03.09.2007 16:05:32 von Shion

Captain Paralytic wrote:
> On 3 Sep, 13:10, "Matthew White" 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

Re: Error with < in SQL

am 03.09.2007 16:09:42 von Shion

Matthew White wrote:
> "Captain Paralytic" wrote in message

>> Now can you please post some of the output FROM THE QUERY!
>
> The query returns a mysqli_result object, then stalls on the
> mysqli_fetch_array. This results in a blank page. If I removed the <,
> the query returns the same object, and returns an array after
> mysqli_fetch_array. That's the only ouput.

I think Paul will be happy if you would tell what happens if you run that
query directly on the mysql server (use the terminal frontend mysql and cut
and paste the query).


--

//Aho

Re: Error with < in SQL

am 04.09.2007 19:51:21 von unknown

Post removed (X-No-Archive: yes)

Re: Error with < in SQL

am 06.09.2007 01:27:31 von Matt White

"J.O. Aho" wrote in message
news:5k2it6F1rnmsU3@mid.individual.net...
> Matthew White wrote:
>> "Captain Paralytic" wrote in message
>
>>> Now can you please post some of the output FROM THE QUERY!
>>
>> The query returns a mysqli_result object, then stalls on the
>> mysqli_fetch_array. This results in a blank page. If I removed the <,
>> the query returns the same object, and returns an array after
>> mysqli_fetch_array. That's the only ouput.
>
> I think Paul will be happy if you would tell what happens if you run that
> query directly on the mysql server (use the terminal frontend mysql and
> cut
> and paste the query).
>
>
> --
>
> //Aho

PHPMyAdmin returns:

Showing rows 0 - 0 (1 total, Query took 0.0163 sec)

and one row that fits the description. It seems to be a problem exclusively
with mysqli_fetch_array.

Re: Error with < in SQL

am 06.09.2007 01:27:31 von Matt White

"Tom" wrote in message news:fbk5up02196@drn.newsguy.com...
> On Mon, 03 Sep 2007 16:09:42 +0200, J.O. Aho wrote...
>>
>>Matthew White wrote:
>>> "Captain Paralytic" wrote in message
>>
>>>> Now can you please post some of the output FROM THE QUERY!
>>>
>>> The query returns a mysqli_result object, then stalls on the
>>> mysqli_fetch_array. This results in a blank page. If I removed the <,
>>> the query returns the same object, and returns an array after
>>> mysqli_fetch_array. That's the only ouput.
>>
>>I think Paul will be happy if you would tell what happens if you run that
>>query directly on the mysql server (use the terminal frontend mysql and
>>cut
>>and paste the query).
>>
>>
>
>
> Sometimes that's the more direct and easier way for checking your MySQL
> syntax.
> : )
>
> Tom
> --
> Newsguy.com
> Basic Accounts $5.95 / month or $39.95 / 12 months
> http://newsguy.com/overview.htm
>

PHPMyAdmin returns the row when I use this query. It must be a problem with
mysqli_fetch_array.

Re: Error with < in SQL

am 06.09.2007 10:42:36 von Captain Paralytic

On 6 Sep, 00:27, "Matthew White" wrote:
> "J.O. Aho" wrote in message
>
> news:5k2it6F1rnmsU3@mid.individual.net...
>
>
>
>
>
> > Matthew White wrote:
> >> "Captain Paralytic" wrote in message
>
> >>> Now can you please post some of the output FROM THE QUERY!
>
> >> The query returns a mysqli_result object, then stalls on the
> >> mysqli_fetch_array. This results in a blank page. If I removed the <,
> >> the query returns the same object, and returns an array after
> >> mysqli_fetch_array. That's the only ouput.
>
> > I think Paul will be happy if you would tell what happens if you run that
> > query directly on the mysql server (use the terminal frontend mysql and
> > cut
> > and paste the query).
>
> > --
>
> > //Aho
>
> PHPMyAdmin returns:
>
> Showing rows 0 - 0 (1 total, Query took 0.0163 sec)
>
> and one row that fits the description. It seems to be a problem exclusively
> with mysqli_fetch_array.- Hide quoted text -
>
> - Show quoted text -

But by the time you get to use mysqli_fetch_array, the query is
finished with, so how can the < in the query be making the difference?