By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,050 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

Getting too many results from a query!

P: n/a
Wm
This is very peculiar -- for some reason, I'm getting 6-8 results from each
of these queries, although only one listing matches. I have a pair of forms
on one page:

<FORM>
Search for lastname: ____________ [Submit]
</FORM>
<FORM>
Search for email: ________________ [Submit]
</FORM>

This goes to a searchresults.php page:

if ($searchname !== "") {
$query="SELECT artistID,firstname,lastname,email,city,state,count ry
from artists WHERE lastname='$searchname'";
$result=mysql_query($query) or die(mysql_error("Could not execute
query."));
while($row = mysql_fetch_array($result)) {
$alt_artistID = $row['artistID'];
$alt_firstname = $row['firstname'];
$alt_lastname= $row['lastname'];
$alt_email = $row['email'];
$alt_city = $row['city'];
$alt_state = $row['state'];
$alt_country = $row['country'];
echo "<CENTER><HR>".$alt_artistID."<BR>"
.$alt_firstname." ".$alt_lastname."</A><BR>"
.$alt_email."<BR>"
.$alt_city.", ".$alt_state." ".$alt_country."<BR>
<A HREF=delete.php?aritstID=".$alt_artistID.">DELETE THIS
LISTING?</A><BR></CENTER>";
}
}

The second section is identical except for:
if ($searchemail !== "") {
$query="SELECT artistID,firstname,lastname,email,city,state,count ry
from artists WHERE email='$searchemail'";
etc...
}

I don't understand why I would get 6-8 records when you can look at them and
see that all but one clearly do not match...???

Wm


Jul 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Wm" <LA*******@hotmail.com> wrote in message
news:lv*********************@news.easynews.com...
This is very peculiar -- for some reason, I'm getting 6-8 results from each of these queries, although only one listing matches. I have a pair of forms on one page:

<FORM>
Search for lastname: ____________ [Submit]
</FORM>
<FORM>
Search for email: ________________ [Submit]
</FORM>

This goes to a searchresults.php page:

if ($searchname !== "") {
$query="SELECT artistID,firstname,lastname,email,city,state,count ry
from artists WHERE lastname='$searchname'";
$result=mysql_query($query) or die(mysql_error("Could not execute
query."));
while($row = mysql_fetch_array($result)) {
$alt_artistID = $row['artistID'];
$alt_firstname = $row['firstname'];
$alt_lastname= $row['lastname'];
$alt_email = $row['email'];
$alt_city = $row['city'];
$alt_state = $row['state'];
$alt_country = $row['country'];
echo "<CENTER><HR>".$alt_artistID."<BR>"
.$alt_firstname." ".$alt_lastname."</A><BR>"
.$alt_email."<BR>"
.$alt_city.", ".$alt_state." ".$alt_country."<BR>
<A HREF=delete.php?aritstID=".$alt_artistID.">DELETE THIS
LISTING?</A><BR></CENTER>";
}
}

The second section is identical except for:
if ($searchemail !== "") {
$query="SELECT artistID,firstname,lastname,email,city,state,count ry from artists WHERE email='$searchemail'";
etc...
}

I don't understand why I would get 6-8 records when you can look at them and see that all but one clearly do not match...???

Wm

Try using a "LIKE" with a wildcard instead of "=" to return string matches:

e.g.:

$query="SELECT artistID,firstname,lastname,email,city,state,count ry from
artists WHERE email LIKE '$searchemail'";

Additionally, you can use wildcard matches:

$query="SELECT artistID,firstname,lastname,email,city,state,count ry from
artists WHERE email LIKE %'$searchemail'%";

The % symbol will return any string which matches the email embedded within
the table record.

-JD

Jul 16 '05 #2

P: n/a
On Sat, 16 Aug 2003 23:54:57 GMT, "Wm" <LA*******@hotmail.com> wrote:
This is very peculiar -- for some reason, I'm getting 6-8 results from each
of these queries, although only one listing matches. I have a pair of forms
on one page:

<FORM>
Search for lastname: ____________ [Submit]
</FORM>
<FORM>
Search for email: ________________ [Submit]
</FORM>

This goes to a searchresults.php page:

if ($searchname !== "") {
$query="SELECT artistID,firstname,lastname,email,city,state,count ry
from artists WHERE lastname='$searchname'";
$result=mysql_query($query) or die(mysql_error("Could not execute
query.")); [snip] }

The second section is identical except for:
if ($searchemail !== "") {
$query="SELECT artistID,firstname,lastname,email,city,state,count ry
from artists WHERE email='$searchemail'";
etc...
}

I don't understand why I would get 6-8 records when you can look at them and
see that all but one clearly do not match...???


Can you post a sample of the data that demonstrates this? The SQL queries (as
they're being executed, i.e. with the values filled in, not just a variable)?
Show the query returning unexpected rows from a mysql command prompt?

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.