Getting too many results from a query!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wm

    Getting too many results from a query!

    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.p hp page:

    if ($searchname !== "") {
    $query="SELECT artistID,firstn ame,lastname,em ail,city,state, country
    from artists WHERE lastname='$sear chname'";
    $result=mysql_q uery($query) or die(mysql_error ("Could not execute
    query."));
    while($row = mysql_fetch_arr ay($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."<B R>"
    .$alt_city.", ".$alt_stat e." ".$alt_country. "<BR>
    <A HREF=delete.php ?aritstID=".$al t_artistID.">DE LETE THIS
    LISTING?</A><BR></CENTER>";
    }
    }

    The second section is identical except for:
    if ($searchemail !== "") {
    $query="SELECT artistID,firstn ame,lastname,em ail,city,state, country
    from artists WHERE email='$searche mail'";
    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




  • Jamie Davison

    #2
    Re: Getting too many results from a query!


    "Wm" <LAshooter@hotm ail.com> wrote in message
    news:lvz%a.2447 007$ZC.352429@n ews.easynews.co m...[color=blue]
    > This is very peculiar -- for some reason, I'm getting 6-8 results from[/color]
    each[color=blue]
    > of these queries, although only one listing matches. I have a pair of[/color]
    forms[color=blue]
    > on one page:
    >
    > <FORM>
    > Search for lastname: ____________ [Submit]
    > </FORM>
    > <FORM>
    > Search for email: _______________ _ [Submit]
    > </FORM>
    >
    > This goes to a searchresults.p hp page:
    >
    > if ($searchname !== "") {
    > $query="SELECT artistID,firstn ame,lastname,em ail,city,state, country
    > from artists WHERE lastname='$sear chname'";
    > $result=mysql_q uery($query) or die(mysql_error ("Could not execute
    > query."));
    > while($row = mysql_fetch_arr ay($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."<B R>"
    > .$alt_city.", ".$alt_stat e." ".$alt_country. "<BR>
    > <A HREF=delete.php ?aritstID=".$al t_artistID.">DE LETE THIS
    > LISTING?</A><BR></CENTER>";
    > }
    > }
    >
    > The second section is identical except for:
    > if ($searchemail !== "") {
    > $query="SELECT[/color]
    artistID,firstn ame,lastname,em ail,city,state, country[color=blue]
    > from artists WHERE email='$searche mail'";
    > etc...
    > }
    >
    > I don't understand why I would get 6-8 records when you can look at them[/color]
    and[color=blue]
    > see that all but one clearly do not match...???
    >
    > Wm
    >
    >
    >
    >[/color]


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

    e.g.:

    $query="SELECT artistID,firstn ame,lastname,em ail,city,state, country from
    artists WHERE email LIKE '$searchemail'" ;

    Additionally, you can use wildcard matches:

    $query="SELECT artistID,firstn ame,lastname,em ail,city,state, country from
    artists WHERE email LIKE %'$searchemail' %";

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

    -JD



    Comment

    • Andy Hassall

      #3
      Re: Getting too many results from a query!

      On Sat, 16 Aug 2003 23:54:57 GMT, "Wm" <LAshooter@hotm ail.com> wrote:
      [color=blue]
      >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.p hp page:
      >
      > if ($searchname !== "") {
      > $query="SELECT artistID,firstn ame,lastname,em ail,city,state, country
      >from artists WHERE lastname='$sear chname'";
      > $result=mysql_q uery($query) or die(mysql_error ("Could not execute
      >query."));[/color]
      [snip][color=blue]
      > }
      >
      >The second section is identical except for:
      > if ($searchemail !== "") {
      > $query="SELECT artistID,firstn ame,lastname,em ail,city,state, country
      >from artists WHERE email='$searche mail'";
      > 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...???[/color]

      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 (andy@andyh.co. uk) icq(5747695) (http://www.andyh.co.uk)
      Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)

      Comment

      Working...