Jump to content

Barand

Moderators
  • Posts

    24,607
  • Joined

  • Last visited

  • Days Won

    831

Everything posted by Barand

  1. Foreach () takes an array and loops through it. You have the array, $dpts, from which you created the comma-delimited string $departmento.
  2. Use code tags ( <> button in toolbar) when posting code. lol
  3. You are getting an error on $_REQUEST['step'] So perhaps that is is the one you should be checking with isset() ?
  4. If you can't remember the manual is there to jog your memory
  5. Change 'options' => array_values($category_str) to 'options' => $category_str;
  6. for ($i=$y+1; $i >= $y-11; $i--)
  7. There are several things in this job that can lead to insanity. One of them is accepting free-form text as input. It only takes a small spelling mistake (like your "strops" above) and the whole thing collapses like a house of cards.
  8. It could be they have an ancient version of PHP that doesn't support [..] array definition syntax. To verify try array( 'id' => $_GET['id']) instead of [ 'id' => $_GET['id'] ]
  9. Rerunning #3, #4, #5 is a definite no-no. You could end up with completely different set of ids. That was, as previously stated, a one-off exercise. How do you create the csv at present? How many test_db records do you typically add at a time? How often do you have new whiskies?
  10. You could try reading thara's post again and use the function he gave you. edit - alternatively you can do it in PHP $dtobj = new DateTime($row['date']); echo $dtobj->format('d/m/Y'); //--> 23/01/2017, for example
  11. That is what that query was designed to do - just the latest record with price and date plus the average price. When you list all the results for a whisky, what do you want to show?
  12. Sorry, I forgot to change it to INNER JOIN in that last version of the query.
  13. There is a "Donate to me" link underneath my avatar on the left. Thanks.
  14. url_img and whsky_id are not in the fields selected in the query.
  15. You have left the id hard coded instead of " = :id ". This version below may also be more efficient SELECT w.whisky_name , price , date , avprice FROM test_db t JOIN whisky w USING (whisky_id) JOIN ( SELECT whisky_id , AVG(price) as avprice FROM test_db WHERE whisky_id = :id GROUP BY whisky_id ) avcalc USING (whisky_id) ORDER BY date DESC LIMIT 1;
  16. Then SELECT w.whisky_name , price , date , avprice FROM test_db t JOIN whisky w USING (whisky_id) JOIN ( SELECT whisky_id , AVG(price) as avprice FROM test_db GROUP BY whisky_id ) avcalc USING (whisky_id) WHERE w.whisky_id = 1 ORDER BY date DESC LIMIT 1;
  17. Is the average price the only thing you want to show as a result of the query on that page?
  18. In records.php, for example, if you want the whisky name then you need to join the test_db table to the whisky table SELECT whisky_id , date , whisky_name as name , price FROM test_db INNER JOIN whisky USING (whisky_id) -- required to get the name WHERE t.whisky_id = :id ORDER BY date DESC
  19. Change query to SELECT rEmail , eMail , c.fullname FROM realtors r LEFT JOIN customers c ON pow(clatitude-rlatitude, 2) + pow((clongitude-rlongitude)*cos(radians(rlatitude)), 2) < pow(willtotravel/69.13, 2) ORDER BY rid, id
  20. If you haven't already, add an index to test_db on the whisky_id column. CREATE INDEX `idx_test_db_whisky_id` ON `test_db` (whisky_id);
  21. Change LEFT JOIN to INNER JOIN. That way only realtors with customers will be found.
  22. It's a one-off operation so slowness isn't a real issue.
  23. Better eyes than me. I could barely make out the last line of that screenshot.
  24. works for me mysql> INSERT INTO whisky (whisky_name) -> SELECT DISTINCT name -> FROM test_db -> ORDER BY name; Query OK, 2 rows affected (0.04 sec) Records: 2 Duplicates: 0 Warnings: 0
  25. The whole point of a database is that each item of information, like a name, is stored once. The only things that appear more than once are the ids which are used to link the tables. 1 ) start with the test_db you had originally and add a new column (type INT) called "whisky_id". 2 ) Create the table "whisky". CREATE TABLE `whisky` ( `whisky_id` int(11) NOT NULL AUTO_INCREMENT, `whisky_name` varchar(40) DEFAULT NULL, `url_img` varchar(45) DEFAULT NULL, PRIMARY KEY (`whisky_id`) ) ENGINE=InnoDB; 3 ) populate the whisky table with the unique name from test_db. The whisky ids will be auto generated. INSERT INTO whisky (whisky_name) SELECT DISTINCT name FROM test_db ORDER BY name; 4 ) Now you need to put those ids from the whisky table into the new column in test_db UPDATE test_db t JOIN whisky w ON t.name=w.whisky_name SET t.whisky_id = w.whisky_id; 5 ) Similarly (but in opposite direction) transfer url_img from test_db to the matching whisky table record. UPDATE test_db t JOIN whisky w USING (whisky_id) SET w.url_img = t.url_img; Job done. Now you can drop the redundant name and url_img columns from the test_db table.
×
×
  • 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.