Re: [PHP-DB] Pagination
Hi you all, here is how I am doing in a veery big class of mine.. Course that uses class's specific terms, but it's very easy to understand. = /* * Fetch paginated results */ function fetch_paginated($query='',$page=1,$itens=20) { $this->query($query.' LIMIT '.(($page*$itens)-$itens).','.$itens); <- IMPORTANT IT APPENDS A XXX,XXX LIMIT IN THE END OF QUERY. if($this->num_rows() > 0) { while($this->fetch_array()) { $results[] = $this->row; } } else { return null; } $this->query($query.' LIMIT 0,'.(($page*$itens)-$itens)); $this->page_prev = $this->num_rows(); <- HOW MANY ROWS BEFORE $this->query($query.' LIMIT '.(($page*$itens)-$itens).',1'); $this->page_next = $this->num_rows(); <- HOW MANY ROWS AHEAD $this->page_pages_before = ($this->page_prev/$itens); <- HOW MANY PAGES BEFORE $this->page_pages_after = ($this->page_next/$itens); <- HOW MANY PAGES AHEAD $this->query($query); $this->page_total = $this->num_rows(); <- TOTAL RECORDS (INCLUDING CURRENT, BEFORE AND AFTER PAGES) $this->page_from = (($page*$itens)-$itens); <- NEXT PAGE $this->page_to = ($page*$itens); <- PAGE AFTER return $results; } = The important thing here is how you build the limit statement: " LIMIT (($page_number*$itens_per_page)-$itens_per_page),$itens_per_page" Where page number MUST start at 1, NOT 0. Regards, Bruno B B Magalhaes On Dec 16, 2004, at 8:38 PM, David Ziggy Lubowa wrote: Hey guys, I am working on an internal db and i have a script[below] which does some searching for me, now i am no expert in php but atleast i can always read up, i want to add some kind of pagination because just incase i search for somethign in particular i dont want it to display 100 entries on my form, how can i incorperate a pagination script in the script below, all help is highly appreciated [snip] $var = @$_GET['q'] ; $trimmed = trim($var); // check for an empty string and display a message. if ($trimmed == "") { echo "Please enter a search..."; exit; } $link = mysql_connect("localhost", "beef","b33f"); mysql_select_db("ip", $link); $qry = mysql_query("SELECT * FROM IP_Addresses where free like '%". $_GET['q']."%'", $link); ?> if (mysql_num_rows($qry)==0 ) { print " Oops No records found "; ?> http://localhost/ipsearch2.html";>Back exit(); } if (mysql_num_rows($qry) > 0) { for ($i = 0; $i echo "" . mysql_field_name($qry, $i) . ""; echo "" . mysql_field_name($qry, $i) . ""; } } ?> if (mysql_num_rows($qry) > 0) { for ($j = 0; $j ?> for ($k = 0; $k echo "" . mysql_result($qry,$j, $k) . ""; } ?> } } ?> [/snip] cheers -Z -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] A language mather
Hi guys, I am thinking about content translation... Current I am using for example: contentId | contentTitle | contentBody | contentLanguage So each row has its own language definition... But would it be better using cols as language fields and retrieve only need cols...: contentId | contentTitle_en_uk | contentBody_en_uk The second option would be less space consuming? Any others ideas? Best Regards. Bruno B B Magalhaes -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] A language question
Hi guys, I am thinking about content translation... Current I am using for example: contentId | contentTitle | contentBody | contentLanguage So each row has its own language definition... But would it be better using cols as language fields and retrieve only need cols...: contentId | contentTitle_en_uk | contentBody_en_uk The second option would be less space consuming? Any others ideas? Best Regards. Bruno B B Magalhaes -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Reverse (or backward?) Infinity Loop
[categoryParents] => Array ( [2] => Array ( [categoryId] => 3 [categoryParentId] => 2 [translationId] => 123456789 [translationLanguage] => pt-br [field01] => Casa [field02] => [field03] => [field04] => [field05] => [field06] => [field07] => [field08] => [field09] => [field10] => ) ) ) [5] => Array ( [categoryId] => 2 [categoryParentId] => 1 [translationId] => 123456789 [translationLanguage] => pt-br [field01] => Casa [field02] => [field03] => [field04] => [field05] => [field06] => [field07] => [field08] => [field09] => [field10] => [categoryParents] => Array ( [1] => Array ( [categoryId] => 2 [categoryParentId] => 1 [translationId] => 123456789 [translationLanguage] => pt-br [field01] => Casa [field02] => [field03] => [field04] => [field05] => [field06] => [field07] => [field08] => [field09] => [field10] => ) ) ) [4] => Array ( [categoryId] => 1 [categoryParentId] => 0 [translationId] => 123456789 [translationLanguage] => pt-br [field01] => Casa [field02] => [field03] => [field04] => [field05] => [field06] => [field07] => [field08] => [field09] => [field10] => ) [3] => Array ( [categoryId] => 1 [categoryParentId] => 0 [translationId] => 123456789 [translationLanguage] => pt-br [field01] => Casa [field02] => [field03] => [field04] => [field05] => [field06] => [field07] => [field08] => [field09] => [field10] => ) ) Many thanks, Bruno B B Magalhaes On Oct 20, 2004, at 12:30 PM, Bobo Wieland wrote: this is some code i've written once that gets all supercategories from a mysql db... Take it as it is... It prints out a html-string of links like this: Category : sub_cat1 : sub_cat2 : sub_cat3. Maybe you can figure it out... it takes the current id (in your example catId13) as a parameter and goes up to the root... function catPathRec($id, $show_lnk = false, $rtn_val="") { global $link_id; $katname = strtoupper(mysql_result(mysql_query("SELECT kat_namn AS kat FROM text_kat WHERE id = ".$id, $link_id), "kat")); $hid = mysql_result(mysql_query("SELECT h_id AS hkat FROM text_kat WHERE id = ".$id, $link_id), "hkat"); if ($rtn_val == "") { if ($show_lnk) { return ($hid == 0) ? ("".$katname."") : (catPathRec($hid, $show_lnk, " : ".$katname."")); } else { return ($hid == 0) ? ($katname) : (catPathRec($hid, $show_lnk, " : ".$katname)); } } else if ($hid != 0) { return catPathRec($hid, $show_lnk, " : ".$katname."".$rtn_val); } return "".$katname."".$rtn_val."\n"; } - Original Message - From: "Bruno B B Magalhães" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>; "php-db" <[EMAIL PROTECTED]> Sent: Wednesday, October 20, 2004 4:47 AM Subject: [PHP-DB] Reverse (or backward?) Infinity Loop Hi guys, I have a normal categories table: catId catParentId catName catStatus But I want when a user enters on: http://hostname/site/products/catId1/catId7/catId13/../../ contentId.html A listing should apear like that: • Category 1 • Category 7 • Category 13 • Category 2 • Category 3 • Category 4 • Category 5 A reverse (or backward) loop! We need to get the last category and then follow the ParentId until the 0 ParentId. Have anybody made this before (I hope so)? Many Thanks, Bruno B B Magalhaes -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Reverse (or backward?) Infinity Loop
Hi guys, I have a normal categories table: catId catParentId catName catStatus But I want when a user enters on: http://hostname/site/products/catId1/catId7/catId13/../../contentId.html A listing should apear like that: • Category 1 • Category 7 • Category 13 • Category 2 • Category 3 • Category 4 • Category 5 A reverse (or backward) loop! We need to get the last category and then follow the ParentId until the 0 ParentId. Have anybody made this before (I hope so)? Many Thanks, Bruno B B Magalhaes -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] CMS Translation Systen: DB Desiging
Hi, I do have a flat file with all the translations for the interface and everything, but the problem is de dynamic content that must be multilingual... Regards, Bruno On Oct 18, 2004, at 5:29 AM, M Saleh EG wrote: I'd always preffer to keep language stuff in files instead of DB. A question or a problem u might face later is: How are you going to store the text in the proper Charset in ur tables? I'd do it this way. -A field in DB to keep the current default language -Every module in the app should have it's own language pack -Write a set of routines to read my language files and return the right values. With DB-Method u gotta hit a trip to ur database for every element or every language pack. Try checking phpMyAdmins way of managing language or any other application to get inspired. On Sun, 17 Oct 2004 23:23:03 -0300, bruno b b magalhaes <[EMAIL PROTECTED]> wrote: Hi everone, I am building a multilingual content management systen, and I am studying the best way to have the content translated, with minimal Database queries and load. So I have: CONTENTS contentId contentCreationDate contentModificationDate translationId contentStatus CATEGORIES categoryId categoryParentId categoryModulePath translationId categoryStatus TRANSLATIONS translationId field01 field02 field03 field04 field05 field06 field07 field08 field09 field10 translationLanguage translationStatus So just run a simple join query: SELECT contents.*,translations.* FROM contents,translations WHERE contents.translationId=translations.translationId AND translations.translationLanguage='en-uk' AND translations.translationStatus = 1 Or with categories: SELECT categories.*,translations.* FROM categories,translations WHERE categories.translationId=translations.translationId AND translations.translationLanguage='en-uk' AND translations.translationStatus = 1 AND categories.categoryModulePath='products' Any better idea to handle that? Regards, Bruno B B Magalhaes -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- M.Saleh.E.G 97150-4779817 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php