Jump to content

bbmak

Members
  • Content Count

    50
  • Joined

  • Last visited

Community Reputation

0 Neutral

About bbmak

  • Rank
    Regular Member

Profile Information

  • Gender
    Not Telling
  1. anyway to fix that? I tried it without an array. It works fine with google chrome.
  2. I try to addslashes to an array $_POST form. The code works fine, and it updates the database. However, google chrome gives me an error. Not sure anyone know how to fix this. I am writing a block of java script into database as text. Code below: echo '<form name="misc_settings" action="?action=misc_settings_submit" method="POST" enctype="multipart/form-data">'; foreach($miscsettings as $miscsetting){ $misc_id = $miscsetting['id']; $misc_name = $miscsetting['name']; $misc_text = stripslashes($miscsetting['text']); echo '<input type="hidden" name="misc_id[]" value="' . $misc_id . '">'; echo '<input type="hidden" name="misc_name[]" value="' . $misc_name . '">'; echo '<div class="field_name">' . $misc_name . ': <div class="field_value"><textarea name="misc_text[]">' . $misc_text . '</textarea></div></div>'; } echo '<div class="submit_field"><input type="submit" value="Submit"> <input type="reset" value="Clear"></div>'; echo '</form>'; $misc_id = $_POST['misc_id']; $misc_name = $_POST['misc_name']; $misc_text = array_map('addslashes', $_POST['misc_text']); for($i=0;$i<count($misc_id);$i++) { if($misc_name[$i]!="" && $misc_text[$i]!="") { echo $misc_id[$i] . '<br />'; echo $misc_name[$i] . '<br />'; echo $misc_text[$i] . '<br /><br />'; $miscClass->updateMiscSetting($misc_id[$i], $misc_text[$i]); } }
  3. After I added the div tab, the AJAX sub-menu is not working anymore. I am stuck here for whole day. <div class="tab"> <button class="tablinks" onclick="openProgram(event, 'add_item')" id="defaultOpen">Add Item</button> <button class="tablinks" onclick="openProgram(event, 'list_item')">List Items</button> </div> <!--------------------------------------------------------------------------------------------------------------------------------> <div id="add_item" class="tabcontent"> <div id="list_item" class="tabcontent"> ... //not working here echo '<select name="listcategory" onchange="showsubcat(this.value)">'; foreach ($categoryRows as $categoryRow){ echo '<option value="' . $categoryRow['id'] . '">' . $categoryRow['category_name'] . '</option>'; } echo '</select>'; echo '<div id="subcatchooser"><b>No Subcategory</b></div>'; //not working here <script> function showsubcat(str) { if (str.length == 0) { document.getElementById("subcatchooser").innerHTML = ""; return; } else { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("subcatchooser").innerHTML = this.responseText; } }; xmlhttp.open("GET", "ajax.php?action=showsubcat&parent_id=" + str, true); xmlhttp.send(); } } </script>
  4. Hi, New to PDO, stucked on binding params in the dynamic query. $searchTerms = explode(' ', $search_string); foreach ($searchTerms as $searchTerm){ $condition .= "ci.item_name LIKE ':searchTerm' OR "; } $condition = substr($condition, 0, -4); $searchQuery = "(SELECT ci.id, ci.item_name, ci.item_description FROM core_item ci WHERE " . $condition . ")"; if($searchStmt = $this->pdo->prepare($searchQuery)) { foreach ($searchTerms as $key => $value){ $seachTerms->bindParam($key, '%' . $value . '%'); } $searchStmt->execute(); return $searchStmt->fetchAll(); } }
  5. I think it is personal perference... I used #2, and I like the { } vertical allign
  6. 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.
  7. 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); ...
  8. Thanks This seems even better than putting a case when statement in the query for my case.
  9. 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
  10. thanks, got it echo '<li><a href="#" onclick="openLink(\'item.php?merchant_id=' . $cat_id . '\')">' . $cat_name . '</a></li>';
  11. 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>';
  12. 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); }
×
×
  • 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.