Re: [PHP-DB] php4 to php5

2008-04-03 Thread Greg Bowser
Sounds like you're talking about the register_globals functionality. It's a
php.ini setting that will cause $_POST['foo'] or $_GET['foo'] to be copied
to the global variable $foo. This is somewhat of a security risk, thus
disabled by default.

There's another superglobal array that you might find useful: $_REQUEST.
$_REQUEST consists of variables from $_GET,$_POST,$_COOKIE (in that order, I
believe).

http://us3.php.net/manual/en/reserved.variables.php

http://us3.php.net/manual/en/ini.core.php#ini.register-globals

--GREG

(note:I also posted this to the php-general list as it isn't a db-related
topic.)


[PHP-DB] Dynamic Navigation with Limit

2008-04-03 Thread Nasreen Laghari
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).\lt;lt;Previous 
Entries/a nbsp; ;
 }
else if ($screen  $pages)
 {
$screen = $screen+1;
  print a href=\view.php?screen=.($screen).\Next Entriesgt;gt;/a 
nbsp; ;
 }

?


  

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

Re: [PHP-DB] Dynamic Navigation with Limit

2008-04-03 Thread Jon L.
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 [EMAIL PROTECTED]
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