MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old January 29th, 2003, 12:01 PM
hmarkovski hmarkovski is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 6 hmarkovski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 20 sec
Reputation Power: 0
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.
Attached Files
File Type: txt class.recnav.php.txt (4.8 KB, 528 views)

Reply With Quote
  #2  
Old January 29th, 2003, 03:15 PM
ramz ramz is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Juiz de Fora - MG- Brazil
Posts: 93 ramz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via ICQ to ramz Send a message via MSN to ramz
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...
Attached Files
File Type: zip db_class.zip (3.3 KB, 868 views)
__________________
Regards,
Ramiro Varandas Jr.

Reply With Quote
  #3  
Old January 30th, 2003, 09:04 AM
hmarkovski hmarkovski is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 6 hmarkovski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 20 sec
Reputation Power: 0
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:
 menu.php :

<?
php
mysql_connect
("localhost","root","");

mysql_select_db("phptest");

$result mysql_query("SELECT DISTINCT firstname FROM people ORDER BY firstname");

echo 
"<br><br><br><br>";

while(
$row mysql_fetch_array($result))
  {
  echo 
"<a href=\"list.php?firstname=$row[firstname]\" target=\"list\">$row[firstname]</a><br>";
  }
?>

list.php :

<?php
mysql_connect
("localhost","root","");

mysql_select_db("phptest");

$result mysql_query("SELECT DISTINCT firstname,list FROM people WHERE firstname = '$firstname'");

echo 
"<br><br><br><br>";

while(
$row mysql_fetch_array($result))
  {
  echo 
"<center>$row[list]</center>";
  }
?> 


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

Reply With Quote
  #4  
Old January 30th, 2003, 10:08 AM
ramz ramz is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Juiz de Fora - MG- Brazil
Posts: 93 ramz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via ICQ to ramz Send a message via MSN to ramz
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.

Reply With Quote
  #5  
Old January 31st, 2003, 06:56 AM
hmarkovski hmarkovski is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 6 hmarkovski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 20 sec
Reputation Power: 0
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
Attached Files
File Type: zip phptest.zip (4.1 KB, 385 views)

Reply With Quote
  #6  
Old January 31st, 2003, 06:09 PM
ramz ramz is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Juiz de Fora - MG- Brazil
Posts: 93 ramz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via ICQ to ramz Send a message via MSN to ramz
Try now

It was missing a . (dot) to concatenate in the log2file function.
Try it now...
Attached Files
File Type: zip phptest.zip (4.1 KB, 46223 views)

Reply With Quote
  #7  
Old February 3rd, 2003, 02:46 PM
hmarkovski hmarkovski is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 6 hmarkovski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 20 sec
Reputation Power: 0
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
Attached Files
File Type: zip phptest.zip (5.3 KB, 416 views)

Reply With Quote
  #8  
Old February 4th, 2003, 12:53 PM
hmarkovski hmarkovski is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 6 hmarkovski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 20 sec
Reputation Power: 0
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

Reply With Quote
  #9  
Old February 4th, 2003, 02:24 PM
ramz ramz is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Juiz de Fora - MG- Brazil
Posts: 93 ramz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via ICQ to ramz Send a message via MSN to ramz
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.

Reply With Quote
  #10  
Old February 4th, 2003, 04:59 PM
ramz ramz is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Juiz de Fora - MG- Brazil
Posts: 93 ramz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via ICQ to ramz Send a message via MSN to ramz
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.
Attached Files
File Type: zip phptest.zip (6.5 KB, 46401 views)

Reply With Quote
  #11  
Old February 10th, 2003, 06:41 AM
hmarkovski hmarkovski is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 6 hmarkovski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 20 sec
Reputation Power: 0
Hi Ramiro,


I am trying to adapt dbclass to this script but something wrong.

Thanks to adapt as possibe.


Regards
Henry Markovski
Attached Files
File Type: txt phptest.txt (2.8 KB, 366 views)

Reply With Quote
  #12  
Old February 10th, 2003, 07:45 AM
ramz ramz is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Juiz de Fora - MG- Brazil
Posts: 93 ramz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via ICQ to ramz Send a message via MSN to ramz
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 "&nbsp;<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&nbsp;&nbsp;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...";
}
?>

Reply With Quote
  #13  
Old March 10th, 2003, 04:06 AM
spacemanspiff spacemanspiff is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 2 spacemanspiff User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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)

Reply With Quote
  #14  
Old March 10th, 2003, 08:56 AM
ramz ramz is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Juiz de Fora - MG- Brazil
Posts: 93 ramz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via ICQ to ramz Send a message via MSN to ramz
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.

Reply With Quote
  #15  
Old March 10th, 2003, 12:16 PM
spacemanspiff spacemanspiff is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 2 spacemanspiff User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by ramz
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.


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