|
Posted by scott Johnson on 10/22/05 00:20
Ok now its starting to make sense.
Any time you start to compare a string to an interger, it trys to
convert the string looking at it one character at a time. strings
without intergers will convert to 0 (zero).
If it encounters a string with INF in it, it will treat it as a
'infinity' type. (not an expert on that).
It seems like you are taking a string and testing it for either an
interger or a string. But be testing it against an interger, "if
($search_value != 0)", will automatically treat the string as an
interger, and then if it sees 'inf' in it, will try to force the case on it.
What I have done in the past to check for interger is use:
if(is_int($search_value)){
Do your number search
}else{
Do your string search
}
I hope this makes sense.
Maybe Malcolm can elborate some more.
Good luck
starbuck wrote:
> <pre>
>
> below is the code that i'm using:
> i added the echo's above the mysql query
> just to see what is actually being assigned to the $where_condition.
> it seems that when $search_value is given the 'info' string, the
> $where_condition never gets set at all
> even though the else statement should set it.
> If the users enters a number, the query tries to match that number by
> looking for it in the school_number
> column. If a user types some text, it tries to match it up in the name
> and aka fields.
>
>
> $search_value = $_POST["textfield"];
>
> if (!$search_value) {
> echo("<p>You must type something in the search box to get results: "
> . mysql_error() . "</p>");
> exit();
> }
>
> if ($search_value != 0) {
> if ($search_value / $search_value == 1) {
> $where_condition = "schools.school_number = '$search_value'";
> }
> }
> else {
> $where_condition = "schools.name like '$search_value%' OR
> schools.aka like '$search_value%' OR schools.name like
> '%$search_value%' OR schools.aka like '%$search_value%'";
> }
>
> echo $search_value;
> echo "<br>SELECT *, ceiling(read_scores/20) as read_stars,
> ceiling(math_scores/20) as math_stars FROM schools WHERE " .
> $where_condition . " ORDER BY borough ASC";
>
> $result = db_query("SELECT *, ceiling(read_scores/20) as read_stars,
> ceiling(math_scores/20) as math_stars FROM schools WHERE " .
> $where_condition . " ORDER BY borough ASC", $link);
> if (!$result) {
> echo("<p>Error performing query: " . mysql_error() . "</p>");
> exit();
> }
> </pre>
>
--
Scott Johnson
http://www.seaforthsailingclub.com
Navigation:
[Reply to this message]
|