Page splitter
Moderator: General Moderators
Page splitter
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
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
- Johnm
- Forum Contributor
- Posts: 344
- Joined: Mon May 13, 2002 12:05 pm
- Location: Michigan, USA
- Contact:
Here is an example:
You will need to modify it for your purposes and database (this is written for Informix)but the general idea is there.
John M
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";
}
?>John M
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:-
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>
?>- Johnm
- Forum Contributor
- Posts: 344
- Joined: Mon May 13, 2002 12:05 pm
- Location: Michigan, USA
- Contact:
Takuma,
First of all, the type of db was not defined.
Second of all, the request was:
John M
First of all, the type of db was not defined.
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.I presume that you are using MySQL
Second of all, the request was:
and that was what was done. puREp3s+ did not ask for someone to write it for him.Can anyone point me in the right direction for such a function?
John M
If you have a problem with something, you will assume that something is wrong and try to guess it...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.
yes you are write but you did not only mention the functions, you showed him code -> writing for him.puREp3s+ did not ask for someone to write it for him.
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
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
You could use "LIMIT" in the SQL query like this:-
And pass the $offset by GET to page to page. Something like this:-
Code: Select all
SELECT * FROM їi]yourtableї/i] LIMIT 30 OFFSET $offsetCode: Select all
<?php
$offset = $_GET['offset'];
$sql = "SELECT * FROM [i]yourtable[/i] LIMIT 30 OFFSET $offset";
?>