Jump to content

bbmak

Members
  • Posts

    50
  • Joined

  • Last visited

Everything posted by bbmak

  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?
  13. What happen if your product page is include page? index.php <html> <head> <title></title> </head> <? include $left; include $center; <----product pages right here. include right; ?>
  14. Hi, sorry, if I got a crappy title because I do not know what this called. I want to have a dynamic meta tag with php. I have a shopping site. I try to put each product description on meta tag, however, the php mysql variable is below the </head> tag. Are there anyway to get the bottom variable at the top of the script? I know I can do the query on top of meta name, but I want to know are there any convenience way other people are doing this. <?php <head> <meta name="product_description" content="<?php echo $product_description ?>"></meta> <--------call the variable right here. </head> ... $product_result = $mysqli->query("SELECT..."); while($product_row = $product_result->fetch_array()) { $product_description = $product_row['description']; <-----------declaring right here }
  15. Actually thank you very much, I actually use your method to solve the problem, REGEXP '^[0-9]'
  16. In my front page, I have this 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z Generated with this foreach(array_merge(array('0-9'),range('A','Z')) as $alphabet) { echo ' <a href=?menu=merchant_letter&letter=' .$alphabet. '>' .$alphabet. '</a> '; } when I click each letter, I want to only show merchants start with A, B, C...Z, however, 0-9 is not going to return anything, I have to make the query to 0 1 2 3 4 5...9 because in the database is like 1store, 2store, 3store...
  17. Thank you for reply. Actually, it works if I put the while($row fetch->array) in the if statement. it works, but I have to type everything twice, 0-9 and A-Z if ($letter == '0-9') { foreach (range('0','9') as $letter0_9) { $merchant_09az_query = mysql_query("SELECT * FROM merchant WHERE merchant_name LIKE '$letter0_9%' ORDER BY 'merchant_name' ASC "); echo '<font size=+2><b><a name=' .$letter0_9. '>' .$letter0_9. '</a></b></font>'; while (){...} } } but I want to put the while fetch_array->() outside the if statement, so I can just type once. So, I just wonder are there any other way to do this. In a shorter and better way.
  18. I want to do a query of each letter, but somehow, I want to group them like this 0-9 and A, B, C,D...Z In 0-9, I want all the 0, 1, 2, 3...9 groups in 0-9, and A-Z, each of them have them own page. I can do them separately , but I want to do them in one page. This is what I have, but it is not working. I hope somebody can help me. $letter = $_GET['letter']; if ($letter == '0-9') { foreach (range('0','9') as $letter0_9) { $merchant_09az_query = mysql_query("SELECT * FROM merchant WHERE merchant_name LIKE '$letter0_9%' ORDER BY 'merchant_name' ASC "); echo '<font size=+2><b><a name=' .$letter0_9. '>' .$letter0_9. '</a></b></font>'; } } if ($letter !== '0-9') { foreach (range('A','Z') as $letterA_Z) { $merchant_09az_query = mysql_query("SELECT * FROM merchant WHERE merchant_name LIKE '$letterA_Z%' ORDER BY 'merchant_name' ASC "); echo '<font size=+2><b><a name=' .$letterA_Z. '>' .$letterA_Z. '</a></b></font>'; } } while(...) ...
  19. Sorry for the messy. Basically it is 3 parts of my code. Now !empty is working. Can anybody tell me why isset is not working in my case? Top validation, name, link, and price. //errors checking if (empty($item_name) || empty($item_link) || empty($item_price) && '0' != $item_price) { $errors[] = 'Item Name, Item Link, and Item Price Cannot Be Empty.'; } else { $validate = new validate(); if(!$validate->validateURL($item_link)) { $errors[] = 'This is not a URL.'; } if (!is_numeric($item_price)) { $errors[] = 'Item Price Must be a number.'; } } if (!empty($errors)) { foreach ($errors as $error) { echo '<strong>', $error, '</strong><br />'; } } else { URL Upload: //URL UPLOAD CHECK $item_url = $_POST['item_url']; if (!empty($item_url)) { $item_image_name = explode("/", $item_url); //spliting file name $item_image_name = end($item_image_name); $imgData = file_get_contents($item_url); $myFile = "../tmp_download/" .$item_image_name; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $imgData); fclose($fh); $item_image_size = getimagesize($myFile); //rename file name $splitName = explode(".", $item_image_name); //spliting file name $fileExt = end($splitName); //getting file extension //rename file name $newFileName = preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', '', str_replace(" ", "", str_replace('"', "", stripslashes(strtolower($item_image_name.'.'.$fileExt))))); //check if image or not using $image_size if ($item_image_size==FALSE) echo "This is not an image file."; //check if image or not using $image_size else { $target = "$home_root/public_html/item_image/$newFileName"; if (copy($myFile,$target)) { unlink($myFile); } } } //URL UPLOAD CHECK File Upload Check: //Image Upload Check $item_image = $_FILES['item_image']['tmp_name']; if (!empty($item_image)) { $item_image = addslashes(file_get_contents($_FILES['item_image']['tmp_name'])); $item_image_name = addslashes($_FILES['item_image']['name']); $item_image_size = getimagesize($_FILES['item_image']['tmp_name']); //rename file name $splitName = explode(".", $item_image_name); //spliting file name $fileExt = end($splitName); //getting file extension //rename file name $newFileName = preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', '', str_replace(" ", "", str_replace('"', "", stripslashes(strtolower($item_image_name.'.'.$fileExt))))); //check if image or not using $image_size if ($item_image_size==FALSE) echo "This is not an image file."; //check if image or not using $image_size else { $target = "$home_root/public_html/item_image/$newFileName"; if(move_uploaded_file($_FILES['item_image']['tmp_name'], $target)) { echo "image is uploaded <br />"; } else { echo "image uploaded fail <br />"; } } } //Image Upload Check
  20. It is driving me crazy. When I use if (!empty($item_url)) and if (!empty($item_image)) are working, the script is good. However, when I just use if (isset($item_url)) and if (isset($item_image)) are not working. when I use isset, it keeps saying the other one is empty, and cannot get_file_contents(). For example, if I upload with file, it will say the url's get_file_contents() cannot be empty. when I upload with url, it will say the file's get_file_contents() cannot be empty.
  21. This is my code, but somehow it is not working. When I insert the image, the url's file_get_contents() will give me an error. On the other hand, when I insert an url, the file upload's file_get_contents() will give me an error. I hope somebody can help me a littlebit, I have actually no idea what is wrong. //errors checking if (empty($item_name) || empty($item_link) || empty($item_price) && '0' != $item_price) { $errors[] = 'Item Name, Item Link, and Item Price Cannot Be Empty.'; } else { $validate = new validate(); if(!$validate->validateURL($item_link)) { $errors[] = 'This is not a URL.'; } if (!is_numeric($item_price)) { $errors[] = 'Item Price Must be a number.'; } } if (!empty($errors)) { foreach ($errors as $error) { echo '<strong>', $error, '</strong><br />'; } } else { //errors checking $item_url = $_POST['item_url']; if(isset($item_url)) { $item_image_name = explode("/", $item_url); //spliting file name $item_image_name = end($item_image_name); $imgData = file_get_contents($item_url); $myFile = "../tmp_download/" .$item_image_name; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $imgData); fclose($fh); $item_image_size = getimagesize($myFile); //rename file name $splitName = explode(".", $item_image_name); //spliting file name $fileExt = end($splitName); //getting file extension //rename file name $newFileName = preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', '', str_replace(" ", "", str_replace('"', "", stripslashes(strtolower($item_image_name.'.'.$fileExt))))); //check if image or not using $image_size if ($item_image_size==FALSE) echo "This is not an image file."; //check if image or not using $image_size else { $target = "$home_root/public_html/item_image/$newFileName"; if (copy($myFile,$target)) { unlink($myFile); } } } //URL UPLOAD CHECK $item_image = $_FILES['item_image']['tmp_name']; //Image Upload Check if (isset($item_image)) { $item_image = addslashes(file_get_contents($_FILES['item_image']['tmp_name'])); $item_image_name = addslashes($_FILES['item_image']['name']); $item_image_size = getimagesize($_FILES['item_image']['tmp_name']); //rename file name $splitName = explode(".", $item_image_name); //spliting file name $fileExt = end($splitName); //getting file extension //rename file name $newFileName = preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', '', str_replace(" ", "", str_replace('"', "", stripslashes(strtolower($item_image_name.'.'.$fileExt))))); //check if image or not using $image_size if ($item_image_size==FALSE) echo "This is not an image file."; //check if image or not using $image_size else { $target = "$home_root/public_html/item_image/$newFileName"; if(move_uploaded_file($_FILES['item_image']['tmp_name'], $target)) { echo "image is uploaded <br />"; } else { echo "image uploaded fail <br />"; } } } //Image Upload Check
×
×
  • 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.