Jump to content

kslakhani

Members
  • Posts

    16
  • Joined

  • Last visited

kslakhani's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. @mac_gyver, First of all thanks for taking your personal attention to my question. I am converting mysql_ to PDO and am noob to this. I got your above post. That logic will definately work. I got one issue though, I am using wrapper/class and that class I need to bind each values seperately means It dosnt use array below is that function public function bind($param, $value, $type = null) { if (is_null($type)) { switch (true) { case is_int($value): $type = PDO::PARAM_INT; break; case is_bool($value): $type = PDO::PARAM_BOOL; break; case is_null($value): $type = PDO::PARAM_NULL; break; default: $type = PDO::PARAM_STR; } } $this->stmt->bindValue($param, $value, $type); } suppose my query is like ( SELECT * FROM users WHERE age = :age AND balance >= :balance); so I do bind the values is like: $db->bind(':age' , $age); $db->bind(':balance' , intval($balance)); so How would I bind according to your suggestion
  2. $query = "SELECT count(*) AS total FROM " . $DBPrefix . "auctions au " . $userjoin . " WHERE au.suspended = 0 AND ". $wher . $ora . " au.starts <= " . $NOW . " ORDER BY " . $by; The above query contains $wher. This $wher is a string containing diff. variables like $wher .= "(au.description like '%" . $something . "%') OR "; if (isset($_SESSION['one'])) { $wher .= "(au.bn_only = " . $x .") AND "; } if IF statements is true $wher will be like " (au.description like '%" . $something . "%') OR (au.bn_only = " . $x . " ) AND " So how would I put placeholders and bind values to them
  3. How do i bind values to a variable which is partially processed with diffrent statements and then concatenated using php .= operator below is piece of code $wher = ''; now I have added few varibles to $wher like if (!empty($_SESSION['advs']['title'])) { $wher .= '('; if (isset($_SESSION['advs']['desc'])) { $wher .= "(au.description like '%" . $system->cleanvars($_SESSION['advs']['title']) . "%') OR "; } $wher .= "(au.title like '%" . $system->cleanvars($_SESSION['advs']['title']) . "%' OR au.id = " . intval($_SESSION['advs']['title']) . ")) AND "; } more addition to $wher if (isset($_SESSION['advs']['buyitnow'])) { $wher .= "(au.buy_now > 0 AND (au.bn_only = 'y' OR au.bn_only = 'n' && (au.num_bids = 0 OR (au.reserve_price > 0 AND au.current_bid < au.reserve_price)))) AND "; } if (isset($_SESSION['advs']['buyitnowonly'])) { $wher .= "(au.bn_only = 'y') AND "; } if (!empty($_SESSION['advs']['zipcode'])) { $userjoin = "LEFT JOIN " . $DBPrefix . "users u ON (u.id = au.user)"; $wher .= "(u.zip LIKE '%" . $system->cleanvars($_SESSION['advs']['zipcode']) . "%') AND "; } now I am using $wher in database SELECT query like // get total number of records $query = "SELECT count(*) AS total FROM " . $DBPrefix . "auctions au " . $userjoin . " WHERE au.suspended = 0 AND ". $wher . $ora . " au.starts <= " . $NOW . " ORDER BY " . $by; $wher is being used in SQL select query. My problem is, How do I put placeholders to $wher and bind the values??
  4. Hey Jacques1, categories are not serialized in DB even main categories have id like1,2,4,8,29, 75 etc etc. How do I assign keys in $children[]?? is it multi-dimentional array?? Sorry pal, again I am blank here
  5. Hey Jacques1, I am nearly there function display_category_level(&$children, $parent=1) { if (isset($children[$parent])) { echo '<ul>'; foreach ($children[$parent] as $id=>$name) { echo "<li><strong>$name</strong>"; echo "<ul>"; display_category_level($children, $id); echo "<li>$name</li>"; } echo '</ul>'; echo "</li>"; } echo '</ul>'; } only 1 problem is it repeats everything like Art & AntiquesAmateur Art Amateur Art Ancient World Ancient World Books & Manuscripts Books & Manuscripts Cameras Cameras Ceramics & Glass GlassArt Glass Art Glass Carnival Carnival Chalkware Chalkware Chintz & Shelley Chintz & Shelley Contemporary Glass Contemporary Glass Decorative Decorative Porcelain Porcelain Glass Ceramics & Glass Fine Art Fine Art General General Musical Instruments Musical Instruments Orientalia Orientalia Painting Painting Photographic Images Photographic Images Post-1900 Post-1900 Pre-1900 Pre-1900 Prints Prints Scientific Instruments Scientific Instruments Silver & Silver Plate Silver & Silver Plate Textiles & Linens Textiles & Linens Art & Antiques BooksAnimals Animals Arts, Architecture & Photography Arts, Architecture & Photography Audiobooks Audiobooks Biographies & Memoirs Biographies & Memoirs Business & Investing Business & Investing Catalogs Catalogs Children Children Computers & Internet Computers & Internet Contemporary Contemporary Cooking, Food & Wine Cooking, Food & Wine Entertainment Entertainment Foreign Language Instruction Foreign Language Instruction General
  6. her is my code $children = []; while (list($cid, $name, $pid) = mysql_fetch_row($res)) { $children[$pid][$cid] = $name; } display_category_level($children); function display_category_level(&$children, $parent=1) { if (isset($children[$parent])) { echo '<div class="dropdown">'; echo '<ul class="dropdown-menu " role="menu" >',"\n"; foreach ($children[$parent] as $id=>$name) { echo "<strong>$name</strong>"; display_category_level($children, $id); echo "<li>". $name."</li>"; echo "</ul>"; } } echo '</div>'; } i got result like Ancient World Ancient World Books & Manuscripts Books & Manuscripts Cameras Cameras Ceramics & GlassCarnival Carnival Chalkware Chalkware Chintz & Shelley Chintz & Shelley Contemporary Glass Contemporary Glass Decorative Decorative Porcelain Porcelain Glass Ceramics & Glass Fine Art Fine Art General General Musical Instruments Musical Instruments Orientalia Orientalia Painting Painting Photographic Images Photographic Images Post-1900 Post-1900 Pre-1900 Pre-1900 Prints Prints Scientific Instruments Scientific Instruments Silver & Silver Plate.......................... tried it different ways but not getting it. I know I am nearly there but like I am unluckily not getting it I want to display it like master_cat(main Dropdown) > main_cat1(drp) > parent_cat parent_cat parent_cat parent_cat parent_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat parent_cat parent_cat parent_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat main_cat2(drp) > parent_cat parent_cat parent_cat parent_cat parent_cat parent_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat parent_cat parent_cat parent_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat ain_cat3(drp) > parent_cat parent_cat parent_cat parent_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat parent_cat parent_cat parent_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat sub_cat
  7. i dont understand for category in children[parent] :
  8. Hey Jaques1, can you show me how do i do your pseudo-code in PHP? will be much appreciated.
  9. @Barand Sorry for the late reply as I was trying to make it with BS3. the above code works fantastic as plain html. However I cant make it work with Bootstrap 3 dropdown menu, I want to make dropdown with all parent_id = 1(these are like master parents) like shown pic on very first post my code is: display_category_level($children); function display_category_level(&$children, $parent=1) { echo '<div class="dropdown" > '; echo '<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <span class="caret"></span>categories</button>'; if (isset($children[$parent])) { echo '<ul class="dropdown-menu " role="menu" >',"\n"; foreach ($children[$parent] as $id=>$name) { echo "<li>$name</li>\n"; display_category_level($children, $id); } echo "</ul>\n"; } } the problem is dropdown works on very first level but on parents category its not working like the above pic shows, been playing with almost 2 days now Any help will be much appreciated.
  10. how do i write in PHP code sorry, I am not that expert
  11. Thanks Jacques1, I have got working query now it fetches all arrays Thanks for your suggestion regarding PDO as I am aware of but at the i am using an olld my_sql.* coz i need to change the my entire queries. And will soon to jump on that how do I implement Thanks
  12. for that i use $query = "SELECT cat_id, cat_name, parent_id, level FROM " .$DBPrefix. "categories ORDER BY cat_name"; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); $items = mysql_fetch_assoc($res); $html = ''; $parent = 0; $parent_stack = array(); $children = array(); foreach ( $items as $item ) $children[$items['parent_id']][] = $item; var_dump($children); $children dosnt fetch all rows gives me like array(1) { [9]=> array(4) { [0]=> string(2) "10" [1]=> string(18) "40s, 50s & 60s" [2]=> string(1) "9" [3]=> string(1) "3" } }
  13. Hi Jacques, the above code gives me nothing i am completely blank on recursive stuff
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.