MySQL Forums
Forum List  »  General

Greater than or Equal to - produces invalid result
Posted by: Simon Lewis
Date: December 06, 2019 05:18AM

Hi there.
I am writing a query that builds dynamically based on what is submitted.

It's a treat, but there is one issue on one field.

SELECT * FROM users WHERE usertype = 'influencer' AND youtube >='100'

This query should find NO results. No one in the DB has even got 99 in that 'youtube' field. And yet this produces one result.

For the rest of the query, if they enter 6000 for Instagram, that produces nothing, but if they enter 5000 or 5001 it does, as the Instagram field for that uses is on 5000.

The field type is the same, and the same length.

This is the query:

$params = array();
$sqlStart = "SELECT * FROM users WHERE usertype = 'influencer'";
$sqlEnd = " ";
$sqlFilters = "";
if(isset($filtertown)) { $sqlFilters .= " AND town =:town"; $params["town"] = $filtertown; }
if(isset($filterinstagram) && !empty($filterinstagram)) { $sqlFilters .= " AND instagram >=:instagram"; $params["instagram"] = $filterinstagram; }
if(isset($filtertwitter) && !empty($filtertwitter)) { $sqlFilters .= " AND twitter >=:twitter"; $params["twitter"] = $filtertwitter; }
if(isset($filterfacebook) && !empty($filterfacebook)) { $sqlFilters .= " AND facebook >=:facebook"; $params["facebook"] = $filterfacebook; }
if(isset($filterpinterest) && !empty($filterpinterest)) { $sqlFilters .= " AND pinterest >=:pinterest"; $params["pinterest"] = $filterpinterest; }
if(isset($filteryoutube) && !empty($filteryoutube)) { $sqlFilters .= " AND youtube >=:youtube"; $params["youtube"] = $filteryoutube; }

$sql = $sqlStart.$sqlFilters.$sqlEnd;
$result = $pdo->prepare($sql); $result->execute($params);
$num_users = $result->rowCount();
echo "<div class='box-container'>Admin - query build:<br/>$sql</div>";

As I say, it works on all fields except 'youtube'.

This is the form field, and I know it is posting the right figure:
echo "<input class='smallinput' type='text' name='filteryoutube' ";
if (isset($filteryoutube)) { echo "value='$filteryoutube'";}
echo ">";

Options: ReplyQuote

Written By
Greater than or Equal to - produces invalid result
December 06, 2019 05:18AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.