|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Building A Dynamic MySQL Paging Class With PHP
Hi,
I use PHP 4.2.0. When I test the example of the first exercise : "Building A Dynamic MySQL Paging Class With PHP", (a tutorial in this site by Joe O'Donnell), I have this error message : Warning: REG_EMPTY:?empty (sub)expression in c:\weblocal\demo\class.recnav.php one line 122. The products appear but not the links. Thank's for a possible answer. |
|
#2
|
|||
|
|||
|
Try using this class...
Hi!
I've made a class for using with MySQL and it makes easy paging records. I've attached the files here and in them you have instructions on how to page records and anything else... Any problem... msg...
__________________
Regards, Ramiro Varandas Jr. |
|
#3
|
|||
|
|||
|
Hi Ramiro,
I'm trying to test the db_class.php but something wrong. This is the original example script without db_class.php. Code:
index.php : <html> <head> <title>Document sans-titre</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <frameset cols="150,*" rows="*"> <frame name="menu" src="menu.php"> <frame name="list" src="list.php" noresize> </frameset> <noframes><body bgcolor="#FFFFFF"> </body></noframes> </html> PHP Code:
Code:
phptest.sql :
CREATE DATABASE phptest;
USE phptest;
CREATE TABLE people
(
id mediumint(10) unsigned NOT NULL auto_increment,
firstname varchar(20) NOT NULL,
list varchar(50) NOT NULL,
PRIMARY KEY (id)
);
INSERT INTO people VALUES('1','James','Lastname of James');
INSERT INTO people VALUES('2','James','Age of James');
INSERT INTO people VALUES('3','James','Email of James');
INSERT INTO people VALUES('4','James','Address of James');
INSERT INTO people VALUES('5','James','ZIP code of James');
INSERT INTO people VALUES('6','James','City of James');
INSERT INTO people VALUES('7','James','Education of James');
INSERT INTO people VALUES('8','James','Profession of James');
INSERT INTO people VALUES('9','James','Sport of James');
INSERT INTO people VALUES('10','James','Music of James');
INSERT INTO people VALUES('11','James','Movie of James');
INSERT INTO people VALUES('12','James','Miscellaneous of James');
INSERT INTO people VALUES('13','Lucia','Lastname of Lucia');
INSERT INTO people VALUES('14','Lucia','Age of Lucia');
INSERT INTO people VALUES('15','Lucia','Email of Lucia');
INSERT INTO people VALUES('16','Lucia','Address of Lucia');
INSERT INTO people VALUES('17','Lucia','ZIP code of Lucia');
INSERT INTO people VALUES('18','Lucia','City of Lucia');
INSERT INTO people VALUES('19','Lucia','Education of Lucia');
INSERT INTO people VALUES('20','Lucia','Profession of Lucia');
INSERT INTO people VALUES('21','Lucia','Sport of Lucia');
INSERT INTO people VALUES('22','Lucia','Music of Lucia');
INSERT INTO people VALUES('23','Lucia','Movie of Lucia');
INSERT INTO people VALUES('24','Lucia','Miscellaneous of Lucia');
For example, having 4 records per page in the second frame (list.php), can you adapte it and send me your modification ? Thanks to try. Regards Henry Markovski |
|
#4
|
|||
|
|||
|
Adapted
Try this...
<?php include("db.Class.php"); if(!$pg) { $pg = 1; } $db = new db("localhost","root","","phptest"); $db->sql = "SELECT DISTINCT firstname, list FROM people WHERE firstname = '$firstname'"; $db->query($db->sql); $db->perPage(4); $db->totalPages(); $nav = $db->printPages($pg,"myPagingHTML.php",100,2,1,""); $rs = $db->query($db->pageNo($db->sql,$pg)); $db->close(); if($rs) { print $nav; print "<table border=0 width='0%' cellpadding=4 cellspacing=1 bgcolor='#CCCCCC'>"; for($i = 0; $i < sizeof($rs); $i++) { if($i % 2 == 0) { $bgrow = "#FFFFFF"; } else { $bgrow = "#F0F0F0"; } print "<tr bgcolor='$bgrow'><td>" . $rs[$i]['firstname'] . "</td><td>" . $rs[$i]['list'] . "</td></tr>"; } print "</table>"; print $nav; } else { print "No results..."; } ?> Last edited by ramz : January 30th, 2003 at 10:16 AM. |
|
#5
|
|||
|
|||
|
Hi Ramiro,
I tested the example that you posted, but I have this error message : Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in c:\weblocal\phptest\db.Class.php one line 336. When I click in the links of the first frame (menu.php), I' ve got the result in the second frame (list.php), But when I click in the links to have 4 records page per page in list.php, the results disappear. Thanks to try. Regards Henry Markovski |
|
#6
|
|||
|
|||
|
Try now
It was missing a . (dot) to concatenate in the log2file function.
Try it now... |
|
#7
|
|||
|
|||
|
Hi Ramiro,
I tested the files that you posted me but there is something wrong. I have a total of 24 records but when I click to next I have No result. I addead a search engine and I have the same problem. Thanks to try. Regards Henry Markovski |
|
#8
|
|||
|
|||
|
Hi Ramiro,
It's OK. It works perfect online. Can you add to your script a function to make link for each page, like that : [First] [Previous] 1 - 2 - 3 [Next] [Last] Page 1 of 3 Total of records: 12 If you add it, send me the result. Thanks to do it. Regards Henry Markovski |
|
#9
|
|||
|
|||
|
Hi Henry!
Sorry for not answer before... busy =) So it worked!! It's good to know that. About linking to each page, I'm still thinking about a way to do that. If I get it, I'll send you the new file. |
|
#10
|
|||
|
|||
|
Hi Henry!
You've request the link to page numbers, and here it is! I've change the file: myPagingFile.php - I've included a new line (the last one). And it was necessary to add an extra parameter to the $db->printPages() function. It's the 3rd parameter. There you can pass the name of a CSS class of a link, so that you can customize the appearance of the link. Any problem, message here. |
|
#11
|
|||
|
|||
|
Hi Ramiro,
I am trying to adapt dbclass to this script but something wrong. Thanks to adapt as possibe. Regards Henry Markovski |
|
#12
|
|||
|
|||
|
Hi Henry!
Look, I've made some modifications in your code, but I don't know exactly what you're trying to do. Perhaps you could give me more information about this... and I do think that you're using form field names very strange, but... it's ok. Test this and see if it works, else, send another message. <?php $db = new db("localhost","root","","phptest"); $db->sql = "SELECT DISTINCT * FROM products WHERE GroupA='$GroupA' AND GroupB='$GroupB' ORDER BY GroupB" $db->query($db->sql); $db->perPage(10); $db->totalPages(); $nav = $db->printPages($pg,"myPagingHTML.php"); $result = $db->query($db->sql); if($result) { print $nav . "<br>"; print "<table align='center' cellspacing='0'>"; print "<form name='groupform'>"; for($i = 0; $i < sizeof($result); $i++) { print "<tr>"; for($k = 0; $k < 5; $k++) { if($result[$i]['Image']) { $img = "<img src='" . $result[$i][Image] . "' border='0'>"; } else { $img = "<img src='../img/empty_photo/nophoto.gif' border='0'>"; } print "<td><a href='product_info.php?No_article=" . $result[$i]['No_article'] . "' target='mainFrame'>$img</a>"; print "<br><a class='fontTNR12ptItalicU' href='product_info.php?No_article=" . $result[$i]['No_article'] . "' target='mainFrame'>Réf.: " . $result[$i]['No_article'] . " - " . $result[$i]['Price'] . "</a></font><br>"; if($result[$i]['Size1']) { print "<input type=hidden name='" . $sid . $result[$i]['No_article'] . "size' size='20' value='.'>"; print "<font>Quantity :</font>"; print "<select name='quantity'>"; print "<option value='0'>0</option>"; print "<option value='1' selected>1</option>"; print "<option value='2'>2</option>"; print "<option value='3'>3</option>"; print "</select>"; print " <input type='button' name='" . $sid . $result[$i]['No_article'] . "add' value='Add' onclick=\"top.menuFrame.addGroup('" . $result[$i]['GroupA'] . "','" . $result[$i]['No_article'] . "',document.groupform." . $sid . $result[$i]['No_article'] . "size.value,'" . $result[$i][Price] . "',document.groupform." . $sid . $result[$i]['No_article'] . "quantity.options[document.groupform." . $sid . $result[$i]['No_article'] . "quantity.selectedIndex].value);\"></td>"; } else { print "<select name='" . $sid . $result[$i]['No_article'] . "size'>"; print "<option value='" . $result[$i]['Size1'] . "'>" . $result[$i]['Size1'] . "</option>"; print "<option value='" . $result[$i]['Size2'] . "'>" . $result[$i]['Size2'] . "</option>"; print "<option value='" . $result[$i]['Size3'] . "'>" . $result[$i]['Size3'] . "</option>"; print "</select>"; print "<font>Size Quantity :</font>"; print "<select name='" . $sid . $result[$i]['No_article'] . "quantity'>"; print "<option value='0'>0</option>"; print "<option value='1' selected>1</option>"; print "<option value='2'>2</option>"; print "</select>"; print "<br><input type='button' name='" . $sid . $result[$i]['No_article'] . "add' value='Add' onclick=\"top.menuFrame.addGroup('" . $result[$i]['GroupA'] . "','" . $result[$i]['No_article'] . "',document.groupform." . $sid . $result[$i]['No_article'] . "size.options[document.groupform." . $sid . $result[$i]['No_article'] . "size.selectedIndex].text,'" . $result[$i]['Price'] . "',document.groupform." . $sid . $result[$i]['No_article'] . "quantity.options[document.groupform." . $sid . $result[$i]['No_article'] . "quantity.selectedIndex].value);\"></td>"; } print "</td>"; $i++; } print "</tr>"; } print "</form>"; print "</table>"; print "<br>" . $nav; } else { print "No results..."; } ?> |
|
#13
|
|||
|
|||
|
When I'm trying the class in "Building A Dynamic MySQL Paging Class With PHP",
(the tutorial in this site by Joe O'Donnell), I'm getting a strange error. I've changed the "\" issue mentioned in this discussion and getting the search to show the expected reult. But when I click on the "nex" link or any ow the numbers linking to pages found, I get this link: http://127.0.0.1/Test_PHP/?page=2 instead of http://127.0.0.1/Test_PHP/paging_test.php??page=2 ('PHP_SELF' returning no value???) Any ideas what's wrong? <- YES!(PHP Version 4.1.2 - Mac OS X 10.2.4) |
|
#14
|
|||
|
|||
|
Hi!
Look, I already have developed a MySQL class that can page easily in both GET and POST method and keep the all the variables used in the process. If you're interested, send another message and I'll post it to you. |
|
#15
|
|||
|
|||
|
Quote:
That would be great! mail me at micke_fors "at" mac.com ! Thanks! ![]() By the way - I've solved my little problem. I had a "include" instead of "require"... (at least I think that was th eproblem) /M |