Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers 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 October 29th, 2003, 05:32 AM
tpiele tpiele is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 3 tpiele User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to tpiele
Pagination Code Problem

Ok, I am so frustrated! I have been working on an sql based shopping cart for a few days and the only problem I am having is getting pagination to work. I have found some code snippets on the web and gone over them line by line trying to figure this out with no luck. The problem seems to be this: The pagination needs to occur on a page called browse.php. There are like 60 products in one catagory and I'd like to display 12 per page. Sounds simple but here is where it gets messy. I am not starting that page with a fresh query that pulls all of the products from the db and displays them, I think I might be able to get that to work maybe. My issue is I am passing a variable on from the previous page called $dept which is a department key. This site sells clothes so you may click on a baby clothes link and go to browse.php?baby_clothes. How do I get baby_clothes into the pagination code below? I have a query up top that pulls sku, price and thumb from the db but when I run this code....the limit works, i do only get 4 per page, but it is the same item 4 times! Click here to see example of page:

http://www.morphosnaturals.com/catalog.php

Click on a link to see it mess up!

Any help getting this to work would be much appreciated. My code is below:

<?php

if (!$PHPSESSID) {
header("Location: main.php");
exit;
}
session_start();

$connection = mysql_connect("127.0.0.1", "login", "passturd")
or die ("Couldn't connect to server.");

$db = mysql_select_db("dbname", $connection)
or die ("Couldn't select database.");

if ($dept) {
$sql = "select sku, price, thumb from products
where dept='$dept' and stock > 0 order by sku";
}

$sql_result = mysql_query($sql,$connection)
or die ("Couldn't get list!");
?>

<?php
include("toolbar.html");
?>

<?php

if (!$PHPSESSID) {
header("Location: main.php");
exit;
}
session_start();

$connection = mysql_connect("127.0.0.1", "login", "passturd")
or die ("Couldn't connect to server.");

$db = mysql_select_db("dbname", $connection)
or die ("Couldn't select database.");

if ($dept) {
$sql = "select sku, price, thumb from products
where dept='$dept' and stock > 0 order by sku";
}

$sql_result = mysql_query($sql,$connection)
or die ("Couldn't get list!");
?>

<?php
include("toolbar.html");
?>

<?php
$limit = 4;
$query_count = "SELECT count(*) FROM products";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);

if(empty($page)){
$page = 1;

while ($row = mysql_fetch_array($sql_result)) {
$sku = $row["sku"];
$price = sprintf("%0.2f",$row["price"]);
$thumb = $row["thumb"];

$limitvalue = $page * $limit - ($limit);
$query = "SELECT * FROM products LIMIT $limitvalue, $limit";
$result = mysql_query($query) or die("Error: " . mysql_error());

if(mysql_num_rows($result) == 0){
echo("Nothing to Display!");
}

$bgcolor = "#E0E0E0"; // light gray

echo("<table>");
}

while($row = mysql_fetch_array($result)){
if ($bgcolor == "#E0E0E0"){
$bgcolor = "#FFFFFF";
}else{
$bgcolor = "#E0E0E0";
}

echo("<tr bgcolor=".$bgcolor."><td>");
echo "<a href="flypage.php?sku=$sku"><img src="$thumb"></a>";
echo("</td><td>");
echo "$price";
echo("</td></tr>");
}

echo("</table>");

}

?>

Reply With Quote
  #2  
Old October 29th, 2003, 07:48 PM
zombie zombie is offline
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: serbia
Posts: 1,876 zombie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: Pagination Code Problem

Quote:
Ok, I am so frustrated! I have been working on an sql based shopping cart for a few days and the only problem I am having is getting pagination to work.


no offence, but if you can't get a simple thing like pagination to work, maybe you are not ready for a shopping chart application?


just my 2 euro-cents...

Reply With Quote
  #3  
Old October 29th, 2003, 10:26 PM
tpiele tpiele is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 3 tpiele User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to tpiele
RE: Pagination Code Problem

Thanks for the help My shopping cart works fine... and I can get simple pagination to work just fine. I am just having trouble integrating the variable I passed from the prevoius query.

If your so "ready" zombie, why don't you act productively and point out my error(s)? I am not a newbie, I have a degree in CS BUT I have only 6 months experience with PHP. I used to write C so the syntax is familiar but of course never did C with mySQL.

Reply With Quote
  #4  
Old October 30th, 2003, 05:19 AM
zombie zombie is offline
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: serbia
Posts: 1,876 zombie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: Pagination Code Problem

sorry, i can't find the error.


btw, i never said i am "ready"...

Reply With Quote
  #5  
Old October 30th, 2003, 06:47 AM
tpiele tpiele is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 3 tpiele User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to tpiele
RE: Pagination Code Problem

That's ok, I fixed it through pure ingenuity and a $9.00 book. My new query was cancelling out the data I needed from an old query, so I renamed one, works now. Thanks anyways.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Pagination Code Problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway