Jump to content

Barand

Moderators
  • Posts

    24,603
  • Joined

  • Last visited

  • Days Won

    830

Everything posted by Barand

  1. String values in a query need to be inside single quotes $sql = "UPDATE `hsa_project_hub`.`rfis` SET `answered_by` = '$answeredBy', `time` = NOW() WHERE `rfis`.`no` = 23;";
  2. I see no title column in user_info table ???
  3. Personally I prefer to use print_r() and only use var_dump() when I need to check type and size and see if there is any hidden whitespace or non-printable characters. When using either, use between <pre>..</pre> tags. It makes it much more readable. eg $output= json_decode($geocode); echo '<pre>', print_r($output), '</pre>';
  4. I would go a step further than ch0cu3r and use the product's row id as the array indexes name="product[$id]" name="price[$id]" then you know which product the data relates to when processing the form
  5. You are listing all the products. Each one has dropdown menu with only a single option. What is the point of that?
  6. or you could combine the two arrays $array3 = array_combine($array1, $array2); foreach ($array3 as $k=>$v) echo "$k$v<br>";
  7. this should do it $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=91902&sensor=true'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); $data = json_decode($output,1); echo $data['results'][0]['formatted_address']; // Bonita, CA 91902, USA
  8. or, wholly DateTime $date1 = new DateTime("2013-03-15"); $date2 = new DateTime("2013-12-12"); echo $date1->diff($date2)->days; // 272
  9. As ginerjm said, your link would be <a href = 'my_edit.php?id=9'>EDIT</a> In my_edit.php, query the database to get the current data using the id passed to it from the link SELECT comments FROM mytable WHERE id=$id Display a form with a <textarea name='comments'>$comments</textarea>, where $comments is from the database and put the id in a hidden input field. When the form is POSTed, update the database with the new comments for the same id
  10. Barand

    JOIN Issues

    You need to specify the join condition for each join SELECT * FROM ps_product_supplier JOIN ps_product USING (id_product) JOIN ps_product_attribute USING (id_product) WHERE ps_product.active = '1' AND ps_product.ean13 = '' AND ps_product_attribute.ean13 = '' AND ps_product.id_category_default != '73'
  11. Here's a demo page of how I handle it. Sample output attached $page = isset($_GET['page']) ? $_GET['page'] : 1; $totalPages = 20; function pageNav ($page, $total) { $str = 'Pages '; if ($total < 11) { for ($p=1; $p <= $total; $p++) { $class = $page==$p ? 'nolink' : 'link'; $str .= "<div class='nav $class'>$p</div>"; } } else { $class = $page==1 ? 'nolink' : 'link'; $str .= "<div class='nav $class'>1</div>"; if ($page < 5) { $p1 = 2; $p2 = 6; } else { $p1 = min ($page-2, $total-5); $p2 = min ($page+2, $total); $str .= '... '; } for ($p=$p1; $p <= $p2; $p++) { $class = $page==$p ? 'nolink' : 'link'; $str .= "<div class='nav $class'>$p</div>"; } if ($total-$page > 3) $str .= '... '; $class = $page==$total ? 'nolink' : 'link'; if ($total > $page+2) $str .= "<div class='nav $class'>$total</div>"; } return $str; } ?> <html> <head> <title>Page Nav</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type="text/javascript"> $().ready(function() { $(".link").click(function() { var pgnum = $(this).html(); location.href = "?page="+pgnum; // specify action on click of page number here }) }) </script> <style type="text/css"> div.nav { display: inline-block; width: 16px; height: 16px; margin-right: 5px; padding: 0; text-align: center; font-family: sans-serif; font-size: 9pt; } div.link { border: 1px solid blue; } div.nolink { font-weight: 700; border: none; } </style> </head> <body> <h1>This is page <?=$page?></h1> <?=pageNav($page, $totalPages)?> </body> </html>
  12. If you use imagecreate() then, by default, the background colour is the first colour allocated with imagecolorallocate(). But, if you use imagecreatetruecolor() then you need to perform an explicit fill with the defined colour imagefill($image,0,0,$background);
  13. Instead of looping through the session array to see if pid already exists, why don't you make pid the key to the array element. Saves all that array searching and splicing eg <?php // check if in array if (isset($_SESSION['cart'][$pid])) { // it exists so increment the qty $_SESSION['cart'][$pid]['qty']++; } else { // add to cart $_SESSION['cart'][$pid] = array ('qty' => 1, 'engraving' => $engraving); } ?>
  14. This is your query 'SELECT * FROM ps_product WHERE ps_product.active = ' You need to use double quotes to enclose the query, not single quotes.
  15. Your subquery is missing the word "SELECT" It also has "from workout_routines x, workout_machines y ON" instead of "from workout_routines x INNER JOIN workout_machines y ON" When you join from workout_results to subquery a, you don't specify what you supposed to be joining on? Try $q = "select r.*, a.* from workout_results r right join ( SELECT x.*, y.* from workout_routines x INNER JOIN workout_machines y on x.machine_id = y.machine_id WHERE x.user_id = '$userid' and x.routine_id = '$routine' and ) a on r.machine_id = a.machine_id and r.user_id = '$userid' and r.workout_date = $seldate and r.routine_id = '$routine' order by a.machine_seq";
  16. Are sure you really want to match on a.player_id=b.exp_total? Seems strange to match an id against a total, or just bad column naming. If that is the case, why bother to select both columns if you know they are going to be the same in the results
  17. Of course there is a way to convert it - that's what STR_TO_DATE() is doing. BTW, date column name will need the backticks - I just noticed you haven't got rid of the spaces as advised.
  18. you would convert the date like this SELECT STR_TO_DATE('April 4th 2016', '%M %D %Y'); // --> 2016-04-04 So your query becomes this (you current query, BTW, searches the last 30 days, not the next 30) SELECT * FROM CleanedCalendar WHERE STR_TO_DATE(Completion Date, '%M %D %Y') BETWEEN CURDATE() AND CURDATE() + INTERVAL 30 DAY;
  19. this code will demonstrate how to use ajax to change the three prices when a different product is selected The form <?php $db = new mysqli(HOST,USERNAME,PASSWORD,'test'); function productOptions($db) { $sql = "SELECT id, name FROM product ORDER BY name"; $res = $db->query($sql); $opts = "<option value=''>- choose -</option>\n"; while (list($id,$name) = $res->fetch_row()) { $opts .= "<option value='$id'>$name</option>\n"; } return $opts; } ?> <html> <head> <title>Sample</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type='text/javascript'> $().ready(function() { $("#product").change(function() { var pid = $(this).val(); $.get( "get_prod_prices.php" , {"pid":pid} , function(data) { $.each(data, function(k,v) { $("#price"+k).val(v); if (v) $("#label"+k).html("€"+v); else $("#label"+k).html(""); }) }, "JSON" ) }) }) </script> </head> <body> <form> <select name="product" id="product" > <?=productOptions($db)?> </select> <input type="radio" name="price" id="price1" value="0"><label for="price1" id="label1"> </label> <input type="radio" name="price" id="price2" value="0"><label for="price2" id="label2"> </label> <input type="radio" name="price" id="price3" value="0"><label for="price2" id="label3"> </label> </form> </body> </html> the script call with AJAX request (get_prod_prices.php) <?php $db = new mysqli(HOST,USERNAME,PASSWORD,'test'); if (!isset($_GET['pid'])) { $prices = [1=>'','','']; exit(json_encode($prices)); } $pid = intval($_GET['pid']); $sql = "SELECT price1, price2, price3 FROM product WHERE id = $pid"; $res = $db->query($sql); list($p1, $p2, $p3) = $res->fetch_row(); $prices = [1=>$p1, $p2, $p3]; echo json_encode($prices); ?>
  20. FYI I ran a similar query on two of my table using a JOIN ON x LIKE ('%y%') as you were trying Table 1: 9,500 rows Table 2: 600,000+ rows. 5,000 results in 1.1 seconds.
  21. There should not be commas before "from" and before "right join" Queries are more efficient if you use explicit join syntax ie FROM A JOIN B ON ... instead of FROM A,B WHERE
  22. I am guessing that the key to join on is supplier ref, as per your last post. SELECT * FROM tmp_BF INNER JOIN ps_product USING (supplier_referance) WHERE tmp_BF.wholesale_price <> ps_product.wholesale_price
  23. Don't have column names containing spaces, use underscores. (If you really must, surround the name with backticks (note: not single quotes) eg `Completion Date`)
  24. Just those that you want filled in
  25. Specify the columns to receive the data INSERT INTO combinedList (col, names, go, here,) SELECT .....
×
×
  • 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.