vForums Support :: Programming & Coding :: Programming Discussion :: Pagination Help :-/ - View Topic
 |  |
| dog199200 Guest | Pagination Help :-/ (3rd Feb 10 at 11:52am UTC) | | OK i have been working on a store system for a site of mine for a few days now and I have been working out one problems after the next and luckily I have only a few bugs left to work out and everything will work perfectly fine. One of the remaining problems is the pagination system I have setup. It works great for the most part, but when i try to call info from my database it prints it out into a single row and I honestly have no idea at all how do break it down into 3 columns of items with 3 items per column, like so:
<------> 1 | 2 | 3 4 | 5 | 6 7 | 8 | 9 <------>
instead its printing out like:
<----------------------------> 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 <---------------------------->
And in printing like that, it hides most of the content cause it doesn't fit within the boundaries of my site. So can someone please help me out? Here is the code I am currently use, or at least the part of it that has any relevance to the request.
 Code: - <?php
- include(CART_DIR."SimpleImage.php");
- $image = new SimpleImage();
- include(CART_DIR."ps_pagination.php");
-
- echo "<table border=\"0\" cellpadding=\"20\" cellspacing=\"0\" align=center width='100%'><tr>";
-
- $sql = 'SELECT * FROM products';
- $pager = new PS_Pagination($db, $sql, 3, 5);
-
- $rs = $pager->paginate();
-
- while($row = mysql_fetch_assoc($rs)) {
- $image->load(CART_DIR."gallery/$row[image].jpg");
- $image->resize(100,100);
- $image->save(CART_DIR."gallery/$row[image]2.jpg");
-
- list($width, $height, $type, $attr) = getimagesize(CART_DIR."gallery/$row[image].jpg");
-
- if(preg_match("/group(4)([^\d]|$)/", $user_info['group'])) {
- $cost = $row[cost] - ($row[cost] * 0.10);
- } else {
- $cost = $row[cost];
- }
-
- echo "<td>
- <img src=\"".CART_DIR."gallery/$row[image]2.jpg\" border=0>
- <br />Name: $row[title]
- <br />Type: $row[product_type]
- <br />Cost: <b> $cost C</b>
- <br /><a href=\"http://www.divineshadowsonline.com/store/includes/desc.php\" target=\"_blank\" onClick=\"window.open(this.href, this.target, 'width=300px,height=100px'); return false;\">View Description</a><br /><br />
-
- <form method=post action=\"index.php\" name=\"frm_add_to_cart\">
- <input type=hidden name=\"product_id\" value=\"$row[id]\">
- <input type=hidden name=\"session_id\" value=\"$_SERVER[REMOTE_ADDR]\">
- <input type=hidden name=\"title\" value=\"$row[title]\">
- <input type=hidden name=\"cost\" value=\"$cost\">
- <input type=hidden name=\"product_type\" value=\"$row[product_type]\">";
-
- if($logged_in) {
- echo "<input type=submit value=\"Add to cart\" name=\"add_to_cart\" class=\"atc\"></form>";
- }
- echo "</td>";
- }
-
- echo "</tr></table>";
- echo "<center>" . $pager->renderFullNav() . "</center>";
- ?>
Any help at all would be greatly appreciated, even if its giving me the general idea on how to do it.
Here is my latest attempt, I think its at least a lot closer then I was before:
 Code: - <?php
- require("../includes/Database.class.php");
- $db = new Database($DBhost, $DBuser, $DBpass, $DBname, $DBpre);
- $db->connect();
-
- $inventory = "SELECT product_id, session_id, title, cost FROM stock WHERE session_id LIKE '". $db->escape($_SERVER[REMOTE_ADDR]) ."%' ORDER BY product_id DESC";
- $inventorycount = $db->query($inventory);
- $num_rows = mysql_num_rows($inventorycount);
-
- if($_POST[add_to_cart]) {
- $data['product_id'] = $_POST[product_id];
- $data['session_id'] = $_POST[session_id];
- $data['title'] = $_POST[title];
- $data['cost'] = $_POST[cost];
- $data['product_type'] = $_POST[product_type];
- $db->query_insert("stock", $data);
- header( 'refresh: 0' );
- }
-
- $total = 0;
- $sql0 = "SELECT id, product_id, session_id, title, cost, product_type FROM stock WHERE session_id LIKE '". $db->escape($_SERVER[REMOTE_ADDR]) ."%' ORDER BY product_id DESC";
- $countRows0 = $db->query($sql0);
-
- while ($countRow0 = $db->fetch_array($countRows0)) {
- $total = $total+$countRow0[cost];
- $products = $countRow0[product_id];
- $title = $$countRow0[title];
- }
-
- include(CART_DIR."SimpleImage.php");
- $image = new SimpleImage();
- include(CART_DIR."ps_pagination.php");
-
- $sql = 'SELECT * FROM products';
- $pager = new PS_Pagination($db, $sql, 9, 5);
-
- $rs = $pager->paginate();
-
- echo "<table border=\"0\" cellpadding=\"20\" cellspacing=\"0\" align=center width='100%'>";
-
- while($row = mysql_fetch_assoc($rs)) {
-
- $image->load(CART_DIR."gallery/$row[image].jpg");
- $image->resize(100,100);
- $image->save(CART_DIR."gallery/$row[image]2.jpg");
-
- list($width, $height, $type, $attr) = getimagesize(CART_DIR."gallery/$row[image].jpg");
-
- if(preg_match("/group(4)([^\d]|$)/", $user_info['group'])) {
- $cost = $row[cost] - ($row[cost] * 0.10);
- } else {
- $cost = $row[cost];
- }
-
- echo"<tr>";
- while($row = mysql_fetch_assoc($rs)) {
-
- echo "<td>
- <img src=\"".CART_DIR."gallery/$row[image]2.jpg\" border=0>
- <br />Name: $row[title]
- <br />Type: $row[product_type]
- <br />Cost: <b> $cost C</b>
- <br /><a href=\"http://www.divineshadowsonline.com/store/includes/desc.php\" target=\"_blank\" onClick=\"window.open(this.href, this.target, 'width=300px,height=100px'); return false;\">View Description</a><br /><br />
-
- <form method=post action=\"index.php\" name=\"frm_add_to_cart\">
- <input type=hidden name=\"product_id\" value=\"$row[id]\">
- <input type=hidden name=\"session_id\" value=\"$_SERVER[REMOTE_ADDR]\">
- <input type=hidden name=\"title\" value=\"$row[title]\">
- <input type=hidden name=\"cost\" value=\"$cost\">
- <input type=hidden name=\"product_type\" value=\"$row[product_type]\">";
-
- if($logged_in) {
- echo "<input type=submit value=\"Add to cart\" name=\"add_to_cart\" class=\"atc\"></form>";
- }
- echo "</td>";
-
- }
- echo "</tr>";
- }
-
- echo "</table>";
-
- echo "<center>" . $pager->renderFullNav() . "</center>";
-
- $db->close();
- ?>
| |
| Michael Moderator
    
![[Avatar]](http://av.wservices.co.uk/av.png) Recoding the future Posts: 4,043 Status: Offline Gender: Male Location: UK Joined:
Additional Groups: Coding Team
  
pmvForum | Re: Pagination Help :-/ (3rd Feb 10 at 5:15pm UTC) | | on my phone atm so can't read the code. When you loop through information obtained with the query, have an integer increment. If it is a certain number then output br / | |
| dog199200 Guest | Re: Pagination Help :-/ (3rd Feb 10 at 11:38pm UTC) | | You'll have to wait to see the code, I'm not sure if that would work with how I have the loop setup | |
| Aiken Full Member
  
![[Avatar]](http://uploads.virtualforums.co.uk/forums/support/me-yat.jpeg) Posts: 333 Status: Offline Gender: Male Location: In a very lonely place, the domain of despair Age: 35 Joined:
pmskypemsnyahooxfire | | dog199200 Guest | Re: Pagination Help :-/ (3rd Feb 10 at 11:54pm UTC) | | Thinking about it, that wont work at all with how my loop is setup I'm not just calling a single time, i'm looping a whole array of date. and I have it all displayed inside of a table, the think is that if I up the <tr> inside the loop it loops over and over, creating a new line per, but if i keep it outside the loop, everything will show up in the same row no matter what because of the table.
Now i did think of using an increment and if it matches then display the <tr></tr> tags, but the problem is if the Increment isn't matched then there would be no <tr></tr> at all.
So as it stands I need to know how i can use an Increment inside my code in sequence with the <tr></tr> tags, in a place that wont cause problems Its not like I haven't tried XD | |
| Michael Moderator
    
![[Avatar]](http://av.wservices.co.uk/av.png) Recoding the future Posts: 4,043 Status: Offline Gender: Male Location: UK Joined:
Additional Groups: Coding Team
  
pmvForum | Re: Pagination Help :-/ (4th Feb 10 at 3:19am UTC) | | Instead of <br /> output </tr><tr>Then keep the <tr> before the loop and a </tr> after. Should work fine.
Failing that, post the loop please!
| |
| dog199200 Guest | Re: Pagination Help :-/ (4th Feb 10 at 6:05am UTC) | | OK before I do that I came up with something and I want someone honest opinion on it please:
http://www.divineshadowsonline.com/store/index.php
How does the shop look so far? Look to the right where it says Inventory to view how the shop looks as is it now. I modified it a bit to see how it look and would like someones opinion what looks better, as it is now (only displays 4 to prevent major stretching), or would it look better showing 9, each one being stacked up in the format seen in the New Store Item area: http://www.divineshadowsonline.com
I am personally torn between the two, displaying 9 in rows and columns would display more so there would be less pages, but it would also display less information, but doing the stack of 4 provides more info, but at the same time it means there would be more pages. I also have no idea how i can go about setting up part of the url as a variable on how many entries to display so the user can set how many they want to show i'm thinking about just adding in a dropdown manu | |
| Michael Moderator
    
![[Avatar]](http://av.wservices.co.uk/av.png) Recoding the future Posts: 4,043 Status: Offline Gender: Male Location: UK Joined:
Additional Groups: Coding Team
  
pmvForum | Re: Pagination Help :-/ (4th Feb 10 at 12:55pm UTC) | | You can use GET to get how many per page... something like &ppage=50
or something | |
| dog199200 Guest | Re: Pagination Help :-/ (4th Feb 10 at 1:00pm UTC) | | i figured that, but i mean I don't know how to take the get value if i was able to assign it to a variable I could then use the variable inside the display per page, but would also need to find a way to set a default.
Anyways do you think stacking it how I have looks good, or does it look tacky? | |
| Michael Moderator
    
![[Avatar]](http://av.wservices.co.uk/av.png) Recoding the future Posts: 4,043 Status: Offline Gender: Male Location: UK Joined:
Additional Groups: Coding Team
  
pmvForum | Re: Pagination Help :-/ (4th Feb 10 at 1:14pm UTC) | | The way you have it currently looks good.
You use $_GET['ppage'].
I'd do something like: if(isset($_GET['ppage']) && $_GET['ppage'] > 20) $per_page = $_GET['ppage']; else $per_page = 20;
That code checks if ppage is in the url, if it is, it returns the amount assigned after the equals. Checks if it's larger than 20, if it's either Not set in the URL, or is less than 20, then it sets the default per page to 20.
| |
| dog199200 Guest | | |
 |  |
|