Jump to content

bbmak

Members
  • Posts

    50
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

bbmak's Achievements

Member

Member (2/5)

0

Reputation

  1. I think it is personal perference... I used #2, and I like the { } vertical allign
  2. Can you show an example of dynamic binding in PDO? I planned to move PDO in future, but I stayed with mysqli for now. I have to rewrite my functions and classes in pdo. I may switch to hybrid mode though.
  3. Hi, How do you split a search string by space and put it into a prepare query? $strings = $_POST['strings']; $string_array = explode(" ", $strings); $search = $mysqli->prepare(" SELECT * FROM core_table where item_name in ( ? ) "); $search->bind_param("s", $string_array); ...
  4. Thanks This seems even better than putting a case when statement in the query for my case.
  5. Instead of writing 2 separated query, are there anyway to put a case statement when in the where clause of the query? $category_id will be null if on front page and not null on category pages. So, I want to put a statement on the highlighted part. However, it seems not working. Can someone help with my syntax. case when $category_id is Null THEN "" when $category_id is not Null THEN ci.cat_id = ? function next24($category_id, $lastItemID) { if(!empty($lastItemID)) { if($next24item = $this->mysqli->prepare(" SELECT ci.id as item_id, ci.cat_id as cat_id, ci.item_name, ci.item_description, ci.item_note, ci.item_price, ci.item_discount, ci.item_url, ci.date_created, ci.date_updated, ci.date_expired, cii.item_id as cii_item_id, cii.item_image_filename, cm.merchant_name, cm.merchant_url, cm.merchant_description, cm.merchant_logo_thumb From core_item ci LEFT JOIN core_merchant cm on ci.merchant_id = cm.id LEFT JOIN core_item_image cii on cii.item_id = ci.id WHERE ci.id < ? AND case when $category_id is Null THEN "" when $category_id is not Null THEN ci.cat_id = ? ORDER BY ci.id DESC LIMIT 24 ")) { $next24item->bind_param("ii", $lastItemID,$category_id); $next24item->execute(); $next24results = $next24item->get_result(); return $next24results->fetch_all(MYSQLI_BOTH); } } else { break; } } Thanks
  6. thanks, got it echo '<li><a href="#" onclick="openLink(\'item.php?merchant_id=' . $cat_id . '\')">' . $cat_name . '</a></li>';
  7. Hi Having problem with putting ' in to my link . this is what i want on the link <li><a href="#" onclick="openLink('item.php?merchant_id=x')>Category 1</a></li> this is my mess echo '<li><a href="#" onclick="openLink('''; ?>item.php?merchant_id=<? echo $cat_id . ''')">' . $cat_name . '</a></li>'; & try this echo '<li><a href="#" onclick="openLink('''item.php?merchant_id=' . $cat_id . ''')">' . $cat_name . '</a></li>';
  8. Hi, 1. I got my code working, but not sure this is the proper way to return an array from a prepare statement. 2. when I use bind_result($var), are there anyway to include all columns without typing them all? if($next24item = $this->mysqli->prepare("SELECT ci.id as item_id, ci.item_name, ci.item_description, ci.item_note, ci.item_price, ci.item_discount, ci.item_url, ci.date_created, ci.date_updated, ci.date_expired, cii.item_id as cii_item_id, cii.item_image_filename, cm.merchant_name, cm.merchant_url, cm.merchant_description, cm.merchant_logo_thumb From core_item ci LEFT JOIN core_merchant cm on ci.merchant_id = cm.id LEFT JOIN core_item_image cii on cii.item_id = ci.id WHERE ci.id < ? ORDER BY ci.id DESC LIMIT 24")) { $next24item->bind_param("i", $lastItemID); $next24item->execute(); $next24results = $next24item->get_result(); return $next24results->fetch_all(MYSQLI_BOTH); }
  9. I go back and check my connection. The file include the wrong path for the connection folder. I fixed that, and now I got this. PHP Fatal error: Call to undefined method mysqli_stmt::fetch_array()
  10. ummm.... I have other functions in the class using $this->mysqli-query(), and they work fine. Somehow the prepare() is not working. I am new to prepare(), and not sure my syntax is correct or not.
  11. Hi Trying to implement with the prepare statement, and it gives me this error. "PHP Fatal error: Call to a member function prepare() on null." Anybody knows what is wrong? function listMerchant() { $merchant = array(); $merchantList = $this->mysqli->prepare("SELECT * FROM core_merchant"); $merchantList->execute(); while($merchantRows = $merchantList->fetch_array()) { $merchant[] = $merchantRows; } $merchantList->close(); return $merchant; }
  12. I am writing php as a hobby, not professional, always curious on programming langs How do you suggest the templates? If I have include $pages in the templates?
×
×
  • 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.