Re: Dynamic Navigation with Limit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



1)
Something that stands out is one of your links:

  if ($screen > 0)
  {
    print <a href=\"view.php?$screen=".( $screen+1)."\"><<Previous
Entries</a>   ";
  }

The '$' in '?$screen' is probably not helping, as that'll probably translate
to '?0=1' (or similar).

And, don't you want that to be ($screen - 1)??

2)
Depending on what version of PHP you're running.
You're assuming that $screen will equal $_GET['screen'].
Which, since 4.2.0 and with default settings, is a bad assumption.

  if ($screen != $_GET['screen']) $screen = $_GET['screen']; // or just use
the assignment.

There's a register_globals setting you can change (default is false):
  http://php.net/ini.core#ini.register-globals
But, changing it to true also has security implications:
  http://php.net/security.globals

Then again, you're also referencing a lot of variables that aren't defined
in your example.
So, it's hard to know what you may be doing that you just didn't post.

3)
You're basing $pages on the ceil([number of rows] / [rows per page]).
Problem with this, the LIMIT won't allow [number of rows] to ever be greater
than [rows per page].
So, $pages will never be anything besides 0 or 1.

You may want to try running a 2nd, similar query, without the LIMIT, using
COUNT(*).
(just in case: http://dev.mysql.com/doc/refman/5.0/en/counting-rows.html)

4)
You have an extra '}' after the while scope that doesn't line up with
anything.
Since you stated the page loads, I'm assuming that's just because it's a
snippet.


- Jon L.

On Thu, Apr 3, 2008 at 6:57 PM, Nasreen Laghari <nasreen_laghari@xxxxxxxxx>
wrote:

> Hi,
>
> I'm trying to put limit of data fetch as well as dynamic navigation. Below
> is the try which I did but something is going wrong as $screen value is not
> increasing so when I click on NEXt button it refreshes the same page and
> Previous button does even show.
>
> Could you kindly have look on the coding and help me where i'm mistaking.
>
> Regards
>
> Nasreen
>
>
> <?php
> $rows_per_page = 10;
> $i=0;
> if (!isset($screen))
>  $screen=0;
> $start = $screen * $rows_per_page;
> $sql = "SELECT * FROM gig g, venue v WHERE g.gigName LIKE
> '%".$gig_name."%' OR g.gig_date LIKE '%".$sdate."%' OR g.genre LIKE
> '%".$genre."%' OR g.ticket_price LIKE '%".$ticket_price1."%' OR
> g.ticket_price LIKE '%".$ticket_price2."%' OR v.venueName LIKE
> '%".$vname."%' OR v.vCity LIKE '%".$city."%' order by gig_Date LIMIT
> $start,$rows_per_page";
> $result = mysql_query($sql) or die("Query error: ". mysql_error());
> $num_rows = mysql_num_rows($result) ;
> $pages = ceil($num_rows / $rows_per_page);
> $j=0;
> while ($row = mysql_fetch_array($result))
> {
>  global $limit;
>  $j = $j+1;
>      $gigid = $row['gigid'];
>   $gigname = $row['gigName'];
>   $sdate = $row['gig_fdate'];
>   $fdate =$row['gig_tdate'];
>   $genre = $row['genre'];
>   $ticket_price = $row['ticket_price'];
>   $gigdetail= $gigid;
>    echo("<br> $gigid <a href='detail.php?gigDetail=$gigid'>
>  $gigname</a>");
> }
>
> }
>
> if ($screen > 0)
>  {
>   print <a href=\"view.php?$screen=".( $screen+1)."\"><<Previous
> Entries</a>   ";
>  }
> else if ($screen < $pages)
>  {
>    $screen = $screen+1;
>  print "<a href=\"view.php?screen=".($screen)."\">Next Entries>></a>   ";
>  }
>
> ?>
>
>
>
>  ____________________________________________________________________________________
> You rock. That's why Blockbuster's offering you one month of Blockbuster
> Total Access, No Cost.
> http://tc.deals.yahoo.com/tc/blockbuster/text5.com
>

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux