SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 31 of 31
  1. #26
    SitePoint Zealot
    Join Date
    Oct 2010
    Posts
    167
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Absolutely right CT, there is a database entry for every "version" of the name so "Chris" for instance would have an entry for Male and an entry for Female. When people are searching, they choose the gender they are searching for "Male" or "Female" so it will only bring up the one relative to the gender they are looking for.

    CT, I'll try out your suggestions today and come back to you on this thread to let you know how they worked

    Thanks again to all of you for your help on this

  2. #27
    SitePoint Zealot
    Join Date
    Oct 2010
    Posts
    167
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Again,

    Sorry for bringing this threat back to life after so long - Other work got in the way so I'm just getting back to this now.

    All previous suggestions have worked a dream and my script is now running almost perfect... I just need some help with some minor modifications to the results display.

    Currently, it displays in a long list. I want to split this list and paginate it.

    I only want to display 50 results per page, further split down into 5 columns (so that's 10 results per column).

    I've no idea how to paginate and columnize SQL search results so I'm hoping someone can help me out...

    Here is the part of the script that handles the results display:


    Code PHP:
    <?php 
     
    if (count($results) > 0) {
     
       echo "You searched for: <span id=\"terms\">{$searchTerms} ({$searchgenderTerm})</span> - Here are your results:<br /><br />";
     
       foreach ( $results as $value ) {
          echo '<a href="babynames-details.php?search=' . $value . '&amp;searchgender=' . $searchgenderTerm . '">' . $value . '</a><br />';
       }
     
     
    }
     
    ?>

    So I want it to display the results like so:

    Name 1 Name 11 Name 21 Name 31 Name 41
    Name 2 Name 12 Name 22 Name 32 Name 42
    Name 3 Name 13 Name 23 Name 33 Name 43
    Name 4 Name 14 Name 24 Name 34 Name 44
    Name 5 Name 15 Name 25 Name 35 Name 45
    Name 6 Name 16 Name 26 Name 36 Name 46
    Name 7 Name 17 Name 27 Name 37 Name 47
    Name 8 Name 18 Name 28 Name 38 Name 48
    Name 9 Name 19 Name 29 Name 39 Name 49
    Name 10 Name 20 Name 30 Name 40 Name 50

    <<Previous Page >> Next Page

    I hope that makes sense...

  3. #28
    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)
    Use Mysql's LIMIT clause, as seen in plenty of examples php pagination to get bunches of 50 results.

    As for how to display them, every 10 results end a <td> and start another <td>.
    PHP Code:
    $start_table 'start table <table><tr></td>' PHP_EOL;
    $end_table '</tr></table>' PHP_EOL;
    $tbody "";
    $cnt 0;
    foreach(
    $results as $value) {
     
    $cnt++;
     
    $tbody .= $value;
     if( ( 
    $cnt 10) ==$tbody .= '</td><td>' PHP_EOL;

    }

    echo 
    $start_table$tbody$end_table
    You gotta do some work to chop off the last </td> from tbody with [fphp]rtrim[fphp] but you should get the gist.

  4. #29
    SitePoint Zealot
    Join Date
    Oct 2010
    Posts
    167
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Cups,

    Sorry but you've lost me lol.

    Where do I put my "echo" in that? And I don't understand what you mean about the last </td> - I don't know what [fphp]rtrim[fphp] means?

    Any chance you could elaborate a little for me? I don't know where to put my script specific info into your code?

  5. #30
    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)
    Where I wrote $value, you enter your entire string:
    PHP Code:
    $tbody '<a href="babynames-details.php?search=' 
    $value '&amp;searchgender=' $searchgenderTerm '">' $value '</a><br />'
    (put as 2 lines to make it readable on this posting)

    If you dont like the build up method I used, then just echo the variables straight onto the page instead:
    PHP Code:
    echo 'START TABLE <table><tr><td>START TD' PHP_EOL;

    $cnt 0;
    foreach(
    $results as $value) {
     
    $cnt++;
     echo 
    '<a href="babynames-details.php?search=' 
             
    $value '&amp;searchgender=' $searchgenderTerm '">' 
             
    $value '</a><br />' PHP_EOL;

      if( ( 
    $cnt 10) ==) {
          echo 
    '</td><td> START TD' PHP_EOL;
       }
    }

    echo 
    '</tr></table> END TABLE' PHP_EOL
    ** there was an error in my first code where the opening <td> was written </td>
    The link to the manual was malformed, should be rtrim

  6. #31
    SitePoint Zealot
    Join Date
    Oct 2010
    Posts
    167
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh I see - Thank you Cups, I really appreciate your help.

    I will have a play around with this tonight/tomorrow and see how I go but I'm sure this will be exactly what I need I'll let you know how I get on.


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
  •