Page splitter

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
puREp3s+
Forum Newbie
Posts: 7
Joined: Tue Dec 17, 2002 1:53 am
Location: Scotland

Page splitter

Post by puREp3s+ »

Hi,

I am currently setting up my web page so that I can display all the records from a table on my page.

Can anyone point me in the right direction for such a function?

Thanks
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post by Johnm »

Here is an example:

Code: Select all

<?php
    $sql="select * from menu_info 
          where ".$cat." > 0 
              and ".$cat." <= ".$user_info[$user_cat]." 
              and loc_code like '%".trim($session_info['loc_code'])."%'
              order by web_desc";

$qry=ifx_query($sql,$dbid);

for($row=ifx_fetch_row($qry,"NEXT"))
{
    echo "<tr valign="top">\n";
        echo "<td width="33%" align="center">\n";
        echo $row['name'];
        echo "</td>\n";
    echo "</tr>\n";
}

?>
You will need to modify it for your purposes and database (this is written for Informix)but the general idea is there.

John M
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

You probably need to change quite a lot, I presume that you are using MySQL. Note - If you have a lot of data in the table I wouldn't put them all to one table, as it can take a lot of time to load in Internet Explorer.
But anway:-

Code: Select all

<?php
mysql_connect("host","usr","pwd");
mysql_select_db("db");

$sql = "SELECT * FROM [i]yourtable[/i]";
$result = mysql_query($sql);

echo "<table>\n";

$row = mysql_fetch_array($result);
$num = count($row);

for($i = 0; $i < $num; $i++) {
  echo 
"<tr>
    <td>".$row[$i]['[i]column1 name[/i]']."</td>
    <td>".$row[$i]['[i]column2 name[/i]']."</td>
    <td>".$row[$i]['[i]column3 name[/i]']."</td>
  </tr>\n";
}

echo "<table>
?>
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post by Johnm »

Takuma,
First of all, the type of db was not defined.
I presume that you are using MySQL
What you did was make an assumption which is a bad thing to do when dealing with computers. You either know or you don't.

Second of all, the request was:
Can anyone point me in the right direction for such a function?
and that was what was done. puREp3s+ did not ask for someone to write it for him.


John M
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

What you did was make an assumption which is a bad thing to do when dealing with computers. You either know or you don't.
If you have a problem with something, you will assume that something is wrong and try to guess it...
puREp3s+ did not ask for someone to write it for him.
yes you are write but you did not only mention the functions, you showed him code -> writing for him. :wink:
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post by Johnm »

That explains a lot.


John M
puREp3s+
Forum Newbie
Posts: 7
Joined: Tue Dec 17, 2002 1:53 am
Location: Scotland

Post by puREp3s+ »

Thanks for that.

From what I can see, that will show a limited amount of rows, but what if i have 90 records and i need to show 30 per page, how do I add in the buttons that will show the correct rows.

Sorry about this.

There are a few developers in the office that are always shouting about ASP and I want to learn PHP
User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Post by Kriek »

I concur with John. You guys crack me up.
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

try searching the forum

Post by AVATAr »

viewtopic.php?t=4963&highlight=next+previous

try searching the forum for "previous" and "next"
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post by oldtimer »

If you are not able to find your answers by searching send me a message or email. This type of function is pretty easy(or is now to me). You can use it for many many things. Not just page one page two etc.

Jerry
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

You could use "LIMIT" in the SQL query like this:-

Code: Select all

SELECT * FROM &#1111;i]yourtable&#1111;/i] LIMIT 30 OFFSET $offset
And pass the $offset by GET to page to page. Something like this:-

Code: Select all

<?php
$offset = $_GET['offset'];
$sql = "SELECT * FROM [i]yourtable[/i] LIMIT 30 OFFSET $offset";
?>
Post Reply