|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate 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
|
|||
|
|||
|
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>"); } ?> |
|
#2
|
|||
|
|||
|
RE: Pagination Code Problem
Quote:
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... |
|
#3
|
|||
|
|||
|
RE: Pagination Code Problem
Thanks for the help
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. |
|
#4
|
|||
|
|||
|
RE: Pagination Code Problem
sorry, i can't find the error.
btw, i never said i am "ready"... |
|
#5
|
|||
|
|||
|
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.
|
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Pagination Code Problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|