SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist jazztie's Avatar
    Join Date
    Mar 2001
    Location
    the Netherlands
    Posts
    519
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Limit array-print to a number of lines

    I'm currently working on an online administrative system. One of the function I'm trying to develop is an e-mail wizard.

    I use a mySql-statement to get all the email-addresses of customers, print them with a checkbox in front of them (to select the customers that you want to send the email to. Compairable with hotmail)...

    But when the list of customers becomes larger, the print statement will screw up my graphic design. So, I want to limit the list to (say) 15 records at a time.

    So, the first problem is:
    How do limit the list to 15 records? And how do I move between the records 1/15 - 16/30 - 31/45 et cetera?

    Because I want to store the records that are checked (see above), here comes the second problem:
    How do I store all the records that have been checked when navigating between several screens?

    Please advise!

    Jazz

  2. #2
    code addict Abstraction's Avatar
    Join Date
    Apr 2001
    Location
    Des Moines, IA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can grab the first 15 rows by doing something like this:

    SELECT TOP 15 email FROM tblUser

    To have x pages with n numbers of items on each page, I don't know of a clean way to do this with MySQL, so I'll keep my mouth shut. =)

    To store the checked items between pages you can use a temporary table, cookie or a session variable.

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Jazz-
    at phpbuilder.com they have a code snippet about the prev. & next buttons (here) , but have you thought of using a multiple select list box?? that way they can just select as many e-mails as they want, without have to change pages

    hope this helps!
    signature

  4. #4
    SitePoint Evangelist jazztie's Avatar
    Join Date
    Mar 2001
    Location
    the Netherlands
    Posts
    519
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the code, but frankly: I don't understand how you use this to print sets of information.

    PHP Code:
    $Select"SELECT count(*) 
            FROM relatie RE LEFT JOIN relatienaw RN ON (RN.rid=RE.rid)
                    LEFT JOIN netwerk NW ON (NW.nid=RE.nid)
            WHERE RE.sid='1' 
            
    $SortBy"

    $MaxRow=4
    if (!isset(
    $CR)) 
     { 
                
    $result mysql_query($Select) or die ( "Datenbankfehler1! versuchen Sie es erneut"); 
                
    $row=mysql_fetch_row($result); 
                
    $CR=$row[0]; 
                
    $RL=0;
                if (
    mysql_num_rows($result) > 0) {
            while (
    $rows    mysql_fetch_array($result)){
                
    extract($rows);
        
                print     
    "
                    <tr bgcolor='#FBFBFB'>
                      <td valign='top' nowrap> 
    $achternaam $voornaam </td>
                      <td valign='top' nowrap><b><a href='javascript:detailLid(
    $rid);'> $bedrijfsnaam</a></b></td>
                      <td valign='top' nowrap> 
    $p_plaats </td>
                      <td valign='top' nowrap> 0
    $telzaak </td>
                      <td valign='top' nowrap> 
    $n_naam </td></tr>
                
                    "
    ;
            }
            }             
     } 

    $AnzahlSeiten=intval($CR/$MaxRow); 
    if (
    $AnzahlSeiten < ($CR/$MaxRow)) 
     { 
                
    $AnzahlSeiten++; 
     } 


     
    $text"<BR>Seite : "
    // check for Prevbutton 
    if   ($RL 0
     { 
                
    $y=$RL-$MaxRow
                
    $Button.=  "<a href=\"leden.php?CR=$CR&RL=$y\">-</a> "
     } 


    for (
    $i 1$i <= $AnzahlSeiten$i++) 
      {   
    $y=($i*$MaxRow)-$MaxRow
         if (
    $y==$RL){$Button.= "<B>";} 

         
    $Button.= "[<a href=\"leden.php?CR=$CR&RL=$y\">$i</a>] "
          if (
    $y==$RL){$Button.=  "</B>";} 
      } 

      
    // check for Nextbutton 
    if   ($RL < ($CR-$MaxRow)) { 
    $y=$RL+$MaxRow
    $Button.= "<a href=\"leden.php?CR=$CR&RL=$y\">+</a> "

    print 
    $text;    
    print 
    $Button
    How do you print the first set of 4 items,
    and clicking on the next-button the second set of 4 items,
    and so forth

    The only thing this code does is print the next button and number of pages (depending on the number of records).

    So, how do you get the records that are in the second set of items?

  5. #5
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, in your situation, take the idea of a previous post, and use a multi selection SELECT form field.

    Like so:

    PHP Code:
    <select name="email[]" multiple size="10">
    <?
    $sql 
    "SELECT name,id FROM $table";
    $result mysql_query($sql);
    while(
    $row mysql_fetch_array($result)){
        
    extract($row);
        echo(
    "<option value=\"$id\">$name</option>");
    }
    ?>
    </select>
    Than deal with the email[] as an array...
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services


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
  •