php paging issues

Discussion in 'PHP' started by r1919, Jul 19, 2008.

  1. #1
    hi,

    i have a problem.

    i have a page with photo albums.
    the page also have an dropdown menu.
    when i chose other album from dropdown the paging didn't work.
    if i hit page3 for example i'm redirected to page 3 but for the fisrt album.
    this is happening for all albums.
    can anyone help me?
    P.s. i'm newbie
    (sorry about my english)
    here's the paging code:

    for($page = 1; $page <= $maxPage; $page++)
    {
    if ($page == $pageNum)
    {
    $nav .= " $page "; // no need to create a link to current page
    }
    else
    {
    $nav .= " <a href=\"$self?meciID=$mecisel&page=$page\">$page</a> ";
    }
    }

    if ($pageNum > 1)
    {
    $page = $pageNum - 1;
    $prev = " <a href=\"$self?meciID=$mecisel&page=$page\">[Prev]</a> ";
    $first = " <a href=\"$self?meciID=$mecisel&page=1\">[First Page]</a> ";
    }
    else
    {
    $prev = '&nbsp;'; // we're on page one, don't print previous link
    $first = '&nbsp;'; // nor the first page link
    }
    if ($pageNum < $maxPage)
    {
    $page = $pageNum + 1;
    $next = " <a href=\"$self?meciID=$mecisel&page=$page\">[Next]</a> ";

    $last = " <a href=\"$self?meciID=$mecisel&page=$maxPage\">[Last Page]</a> ";
    }
    else
    {
    $next = '&nbsp;'; // we're on the last page, don't print next link
    $last = '&nbsp;'; // nor the last page link
    }

    // print the navigation link
    echo $first . $prev . $nav . $next . $last;
    die;

    and this is the select:

    <select class="select" name="mecisel" onChange="submit()">
    <?php foreach($meciuri as $meci):?>
    <option value="<?=$meci['meci_id']?>" <?=(($meci['meci_id'] == $_POST['mecisel']) ? 'selected = "selected"' : '')?>>
    <?=$meci['sport_nume']?> - <?=$meci['sezon_nume']?> - <?=$meci['meci_nume']?>
    </option>
    <?php endforeach;?>
    </select>

    I hope this makes sense
    thank you for your help
     
    r1919, Jul 19, 2008 IP
  2. r1919

    r1919 Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    i guess i need to refresh/redirect the page when i choose option.
    the url is ***.php but i need it tot be ***.php?id=(optionselected)
    how can i do that?
     
    r1919, Jul 19, 2008 IP
  3. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #3
    make a form, method="get", <select name="id">
     
    matthewrobertbell, Jul 19, 2008 IP
  4. r1919

    r1919 Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    i already have a form in header for all pages.
    <form method="POST" enctype="multipart/form-data" action="<?=$_SERVER['PHP_SELF']?>">

    i don't think it's a good idea to change to it get.

    should i create another form only for this select?
     
    r1919, Jul 19, 2008 IP
  5. Cri2T

    Cri2T Peon

    Messages:
    104
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yes, method="get" will send the info to $_GET instead of $_POST. This way your Pagination script can read the value and use it.
     
    Cri2T, Jul 19, 2008 IP
  6. r1919

    r1919 Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    still not working :(((((((
     
    r1919, Jul 20, 2008 IP
  7. Cri2T

    Cri2T Peon

    Messages:
    104
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    What's your SQL look like? Since Pagination uses LIMIT to change the results based on the page.

    (just replace your database name with 'database' and table name with 'table' or something before posting it)
     
    Cri2T, Jul 20, 2008 IP
  8. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #8
    here's some code..

    // ************************
    // Start of Search Engine
    // ************************ ____
    $searchtag = $_GET['keyword']; // User Defined Input \
    $category = $_GET['category']; // Category ----->> Inputs from SearchTab.php
    $options = $_GET['options']; // Options ____/
    $pageLimit = 5; // Pagination Limit of Pages ie. 1-5, 6-10, 11-15

    // ***********************
    // NO NEED TO EDIT BELOW
    // ***********************
    if(!isset($_GET['limitrecords']))
    { $limitrecords = 10; }else{ $limitrecords = $_GET['limitrecords']; }
    $category_name = __selectFetch('job_category','pdi_job_category',"where job_id = '". $category ."'");
    switch($options) {
    case 1: $options = 'all'; $string = "SELECT * FROM pdi_job_posting WHERE (job_title like '%".$searchtag."%' or emp_name like '%".$searchtag."%' or job_type like '%".$searchtag."%' or job_location like '%".$searchtag."%')";break;
    case 2: $options = 'position'; $string = "SELECT * FROM pdi_job_posting WHERE (job_title like '%".$searchtag."%')"; break;
    case 3: $options = 'location'; $string = "SELECT * FROM pdi_job_posting WHERE (job_location like '%".$searchtag."%')"; break;
    case 4: $options = 'company'; $string = "SELECT * FROM pdi_job_posting WHERE (emp_name like '%".$searchtag."%')";break;}
    $searchtag = addslashes($_GET['keyword']);
    if(!isset($_GET['pagenumber']))
    { $pagenumber=0;
    }else{
    $pagenumber = ($_GET['pagenumber'] * $limitrecords)-$limitrecords;
    }
    if($searchtag == "" || strlen($searchtag)<3)
    { echo "<center><br /><br /><br /><br /><br />Please Retype Your Keyword.<br /><br /><br /><br /></center>";
    } else { if($category != 'jcat00001'){ $job_category = " and job_category = '" . $category . "' "; } $query2 = __md($string . $job_category ."and flag = 0 ORDER BY id desc limit ". $pagenumber .",".$limitrecords."")or die(mysql_error());
    $begin = microtime_calc();
    $rowcheck = __md($string . $job_category . "and flag = 0");
    $rows = mysql_num_rows($rowcheck);$i = 0;$x = 0;
    while ($i < 100000)
    {
    $x = $x * $i;
    $i++;
    }
    $end = microtime_calc();
    $run_time = $end-$begin;
    $pagination = paging($rows,$limitrecords);
    $currrecord = $pagenumber+1;
    $maxrecord = ($currrecord+$limitrecords)-1;
    if($maxrecord>$rows){$maxrecord = $rows;}if($rows<1)
    { echo "<br /><br /><br /><br /><br /><center>Sorry, we found no records for your keyword.</center><br /><br /><br /><br />";exit();} else { if(!isset($_GET['pagenumber']))
    {
    if($pageLimit>$pagination)
    {
    $pageLimit=$pagination;
    }
    $paginationPage = '1';
    $minpage = 1;
    $maxpage = $pageLimit;
    }
    else
    {
    if($pageLimit>$pagination)
    {
    $pageLimit=$pagination;
    }
    $paginationPage = $_GET['pagenumber'];
    $pagesx = paging($paginationPage,$pageLimit);
    $minpage = ($pageLimit * $pagesx)-$pageLimit+1;
    $maxpage = ($minpage + $pageLimit) - 1;
    if($maxpage>$pagination)
    {
    $maxpage = $pagination;
    }
    }
    echo "<div style=\"float: left;text-align: left; border: 0px black solid;margin-top: 14px; margin-left: 10px\">Job Search results:
    keyword: <strong>". $searchtag ."</strong><br />
    Options: <strong>". $options ." </strong><br />
    Category: <strong>". $category_name['job_category'] ."</strong><br />
    </div>";
    echo "<div style=\"float: right;text-align: right; border: 0px black solid; width: 450px; margin-right: 5px; height: 39px; margin-top: 10px;\"> ";
    echo "Limit Records : <strong>" . $limitrecords . "</strong>";
    echo " <br />Results: ". $currrecord ." - ". $maxrecord ." of ". $rows . " records ";
    ?>
    <table border="0" cellspacing="0" align="right" style="margin-top: 0px; border: 0px #CCCCCC solid;"><tr><td>Pages : </td>
    <?php
    if($paginationPage>=2)
    {
    $minusPage = $paginationPage -1;
    echo "<td style=\"width: 30px; border: 1px #CCCCCC solid;\"><a href=\"javascript:changePage('". $searchtag ."','". $category ."','". $_GET['options'] ."','1','". $limitrecords ."')\" style=\" color: black;\"><center>Prev</center></a></td>";
    echo "<td style=\"width: 15px; border: 1px #CCCCCC solid;\"><a href=\"javascript:changePage('". $searchtag ."','". $category ."','". $_GET['options'] ."','". $minusPage ."','". $limitrecords ."')\" style=\" color: black;\"><center><</center></a></td>";
    }
    for($i=$minpage;$i<=$maxpage;$i++)
    {
    if($paginationPage==$i)
    {
    echo"<td width=\"17\" style=\" border: 1px #CCCCCC solid; background: #003300; color: #FFFFFF;\"><strong><center>" .$i."</center></strong></td>";
    }else{
    echo"<td width=\"17\" style=\" border: 1px #CCCCCC solid;\"><center>
    <a href=\"javascript:changePage('". $searchtag ."','". $category ."','". $_GET['options'] ."','". $i ."','". $limitrecords ."')\" style=\" color: black;\">" .$i."</a></center></td>";
    }
    }
    if($paginationPage!=$pagination)
    {
    $paginationPage = $paginationPage +1;
    echo"<td style=\"width: 15px; border: 1px #CCCCCC solid;\"><center><a href=\"javascript:changePage('". $searchtag ."','". $category ."','". $_GET['options'] ."','". $paginationPage ."','". $limitrecords ."')\" style=\" color: black;\">></a></center></td>";
    echo"<td style=\"width: 30px; border: 1px #CCCCCC solid;\"><center><a href=\"javascript:changePage('". $searchtag ."','". $category ."','". $_GET['options'] ."','". $pagination ."','". $limitrecords ."')\" style=\" color: black;\">Last</a></center></td>";
    }
    ?>
    </tr>
    </table>
    <?php
    echo "</div>";
    ?>

    <div style="float: left; margin-left: 5px; margin-top: 2px;">
    <table width="705" border="0" cellspacing="0" style="border: 1px #CCCCCC solid;color: #333333; margin-bottom: 5px;">
    <tr height="22">
    <td align="left" style="background: url(user_page/user_cssimages/menubg.png) bottom repeat-x;"><strong>Date</strong></td>
    <td align="left" style="background: url(user_page/user_cssimages/menubg.png) bottom repeat-x;"><strong>Position</strong></td>
    <td align="left" style="background: url(user_page/user_cssimages/menubg.png) bottom repeat-x;"><strong>Company</strong></td>
    <td align="left" style="background: url(user_page/user_cssimages/menubg.png) bottom repeat-x;"><strong>Location</strong></td>
    <td align="left" style="background: url(user_page/user_cssimages/menubg.png) bottom repeat-x;" width="100"><strong>Salary</strong></td>
    </tr>
    <?php
    while($query = mysql_fetch_array($query2))
    {
    $newDate = explode(" ",$query['job_c_date']);
    ?>
    <tr height="25">
    <td align="left" style="border-bottom: 1px #CCCCCC solid;"><?php echo $newDate[0];?></td>
    <td align="left" style="border-bottom: 1px #CCCCCC solid;">&nbsp;<?php echo "<a href=\"javascript:popUp('contents/jobForm.php?account=". base64_encode($query['job_id']) ."')\">" . $query['job_title'];?></a></td>
    <td align="left" style="border-bottom: 1px #CCCCCC solid;">&nbsp;<?php echo $query['emp_name'];?></td>
    <td align="left" style="border-bottom: 1px #CCCCCC solid;">&nbsp;<?php echo $query['job_location'];?></td>
    <td align="left" style="border-bottom: 1px #CCCCCC solid;">&nbsp;<?php echo $query['job_comprange'];?></td>
    </tr>
    <?php
    }
    echo "<tr>
    <td colspan=\"5\" align=\"right\">Found in: <strong>" . round($run_time, 4) . " seconds</strong></td>
    </tr>";
    }
    echo "</table>";

    ?>

    <?php
    $b = 5; // default limit records
    echo "<div style=\"float: right; margin-right: 5px;\">";
    echo "Display Records Limit : <select name=\"recordlimit\" onchange=\"javascript:changePage('". $searchtag ."','". $category ."','". $_GET['options'] ."','1',this.value)\">";
    for($i=0;$i<=9;$i++)
    {
    if($b==$limitrecords)
    {
    echo "<option selected=\"selected\">". $b ."</option>";
    }else{
    echo "<option value=\"".$b."\" >". $b ."</option>";
    }
    $b = $b + 5;
    }
    echo "</select>";
    echo "</div>";
    }
    ?>
    you can pm at my email add, i can give you some tutorials
     
    bartolay13, Jul 20, 2008 IP
  9. Cri2T

    Cri2T Peon

    Messages:
    104
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Um, bart, I don't think he was looking for a search engine; but I can't say anything derogatory to you simply because your signature deserves some kind of award.
     
    Cri2T, Jul 20, 2008 IP
  10. r1919

    r1919 Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    the problem is not from sql because when i chose other album from dorpdown is working, it shows the right photos.
    the url is ../photos.php and when i change the album it remains photos.php.
    thats why every time i'm redirected to first album.
    i need that the url to be something like that photos.php?id=(option selected).

    i hope that you understand what i'm trying to say.
     
    r1919, Jul 20, 2008 IP
  11. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #11
    The dropdown box needs to be within a form with the get method.

    using a get method submits in the form of script.php?key=value
     
    matthewrobertbell, Jul 20, 2008 IP
  12. r1919

    r1919 Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    10x
    it's works now.
    now i have the form <form method="GET" enctype="multipart/form-data" action="<?=$_SERVER['PHP_SELF']?>">

    the page 2,3 are like ...photos.php?sportid=61&page=2 but the first page is
    /photos.php?action=&id=&sportid=87......etc
    there is a way so that the first page look like other ones?

    like i said before i am newbie, sorry for stupid questions.
     
    r1919, Jul 20, 2008 IP
  13. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #13
    you must have "action" and "id" fields in your form, remove them and they wont appear in the url
     
    matthewrobertbell, Jul 20, 2008 IP
  14. r1919

    r1919 Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    i have many field in my form and i con not remove them because i need them.
    all i want is to associate an url for every option from drop down menu.

    <select onChange="submit()">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    </select>

    i want that when i chose option 1 url becomes photo.php?sportid=1,
    when i chose option 2 url becomes photo.php?sportid=2
     
    r1919, Jul 20, 2008 IP