SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Sep 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Search returns no results

    Hi.

    I have an issue with a search in my php script.

    When I want to do a search against a specific country then I get results for that country.
    However if I do a search for All. I get no results found? If I then just do a search for the word destination I find everything?
    I want to be able to get the same results if I search for All as I would if I searched for the word destination?
    I also need to still keep the same functions that work already so if I search for a specific country I get the right results.
    I hope that makes some sense..
    I have attached the code below that I think is causing the problem.

    Thanks for any help

    <option value="">Destination</option>

    <option value="all">All</option>

    <?php do { ?>

    <option value="<?php echo $row_destinations['Country']?>" <?php if (!(strcmp($row_destinations['Country'], $cntfilter))) {echo "SELECTED";} ?>><?php echo $row_destinations['Country']?></option>

    <?php } while ($row_destinations = mysql_fetch_assoc($destinations)); $rows = mysql_num_rows($destinations); if($rows > 0) { mysql_data_seek($destinations, 0); $row_destinations = mysql_fetch_assoc($destinations); }?>

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    I think we would need to see how you are building your SQL statement which contains the country code.

  3. #3
    SitePoint Member
    Join Date
    Sep 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is this what you need?

    mysql_select_db($database_);

    $query_destinations = "SELECT DISTINCT `Country` FROM location2 WHERE `Country`<>'Belize' ORDER BY Country ASC";

    $destinations = mysql_query($query_destinations, $dtw) or die(mysql_error());

    $row_destinations = mysql_fetch_assoc($destinations);

    $totalRows_destinations = mysql_num_rows($destinations)

    Thanks

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2011
    Location
    Novi Sad
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try using a while loop, instead of do...while - your code runs one time before the mysql_fetch_assoc() is actually called to get a row from results.
    Hope this helps!

  5. #5
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,810
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by popartns View Post
    Try using a while loop, instead of do...while - your code runs one time before the mysql_fetch_assoc() is actually called to get a row from results.
    Hope this helps!
    That unfortunately is bad advice. Since he is calling mysql_fetch_assoc() prior to the loop, he needs to use a do-while instead of a while loop, otherwise, his results will never show the very first row (as shown when combining the OP's first and second posts on this thread).
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  6. #6
    SitePoint Enthusiast
    Join Date
    Jul 2011
    Location
    Novi Sad
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    That unfortunately is bad advice. Since he is calling mysql_fetch_assoc() prior to the loop, he needs to use a do-while instead of a while loop, otherwise, his results will never show the very first row (as shown when combining the OP's first and second posts on this thread).
    Oh, if you combine 2 posts, then yes, first result will never be shown. I was actually having only first post in mind.

  7. #7
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    When I want to do a search against a specific country then I get results for that country.
    However if I do a search for All. I get no results found?
    So in that case ('All') what does your SQL statement end up as?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •