Re: About PHP & Oracle

From: Date: Fri, 31 Aug 2001 03:45:27 +0000
Subject: Re: About PHP & Oracle
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-65403@lists.php.net to get a copy of this message
> Dear all, > Now i have an Oracle database. I have created a table contains 43 rows for example. I use PHP to contact with my oracle. I want to write a script access my Oracle for display data into table. Each time display 9 rows. So I dont't know how to program such as "Page 1 2 3 4 Next".Can anybody show me the way?And addition, when i use SQL command as "select * from table_name where id>'$id' ", it didn't display at all. > Thanks you in advance. > BaDu Below is some snippets of code from a project I just did where I did the same thing. You will have to do some editing for this but I hope it gives you the general idea. First of all, this was for MySQL but assuming that a LIMIT statement in Oracle works the same as in MySQL, you should be ok. Second of all, in some versions of MySQL numbering of table records for an offset on LIMIT starts at 0, newer versions at 1. I'm using the older version as you can see but you will want to check your Oracle documentation for future information. <?php $perpage=10; //you'll want to change the above to 9 since that is how many items per page you want to show. $q = "SELECT COUNT(*) AS NumImage FROM Photo_Image WHERE Cat_ID = '$id' GROUP BY Cat_ID"; $db->query($q); $db->next_record(); $numrows = $db->f("NumImage"); if (empty($offset)) { $offset=0; //Again, offset may be 1 or it may be 0.. check docs. } $q = "SELECT Photo_Image.*, Photo_Cat.Name FROM Photo_Image, Photo_Cat WHERE Photo_Image.Cat_ID = '$id' AND Photo_Cat.Cat_ID = '$id' ORDER BY SortOrder LIMIT $offset, $perpage"; $db->query($q); // print stuff here $pages = ceil($numrows/$perpage); if ($offset - $perpage >= 0) { ?> <a href="<? echo $PHP_SELF; ?>?func=ph&id=<? echo $id; ?>&offset=<? echo $offset - $perpage; ?>">[Prev]&nbsp;</a><? } if ($pages > 1) { for ($x = 0; $x < $pages; $x++) { ?> <a href="<? echo $PHP_SELF; ?>?func=ph&id=<? echo $id; ?>&offset=<? echo $x * $perpage; ?>"><? echo $x+1; ?></a>&nbsp;<? } } if (($offset + $perpage) < $numrows) { ?> <a href="<? echo $PHP_SELF; ?>?func=ph&id=<? echo $id; ?>&offset=<? echo $offset + $perpage; ?>">[Next]&nbsp;</a><? } Hope this helps. Joel

« previous php.general (#65403) next »