Page 1 of 1
Page splitter
Posted: Tue Dec 17, 2002 10:12 am
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
Posted: Tue Dec 17, 2002 10:33 am
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
Posted: Tue Dec 17, 2002 10:44 am
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>
?>
Posted: Tue Dec 17, 2002 10:52 am
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
Posted: Tue Dec 17, 2002 10:59 am
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.

Posted: Tue Dec 17, 2002 11:02 am
by Johnm
That explains a lot.
John M
Posted: Tue Dec 17, 2002 12:38 pm
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
Posted: Tue Dec 17, 2002 6:39 pm
by Kriek
I concur with John. You guys crack me up.
try searching the forum
Posted: Tue Dec 17, 2002 9:05 pm
by AVATAr
viewtopic.php?t=4963&highlight=next+previous
try searching the forum for "previous" and "next"
Posted: Tue Dec 17, 2002 9:45 pm
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
Posted: Wed Dec 18, 2002 4:28 am
by Takuma
You could use "LIMIT" in the SQL query like this:-
Code: Select all
SELECT * FROM їi]yourtableї/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";
?>