Jump to content

Barand

Moderators
  • Posts

    24,319
  • Joined

  • Last visited

  • Days Won

    794

Everything posted by Barand

  1. Yes - it has been serialized twice. Serialize the array into a string Serialize the resulting string To unravel it, unserialize twice print_r( unserialize(unserialize('s:287:"a:8:{s:5:"price";a:2:{s:5:"value";s:5:"38000";s:8:"original";s:0:"";}s:17:"custom_tax_inside";s:0:"";s:15:"custom_tax_page";s:0:"";s:8:"city_mpg";a:1:{s:5:"value";s:0:"";}s:11:"highway_mpg";a:1:{s:5:"value";s:0:"";}s:12:"custom_badge";s:0:"";s:5:"video";s:0:"";s:10:"short_desc";s:0:"";}"'))); Gives Array ( [price] => Array ( [value] => 38000 [original] => ) [custom_tax_inside] => [custom_tax_page] => [city_mpg] => Array ( [value] => ) [highway_mpg] => Array ( [value] => ) [custom_badge] => [video] => [short_desc] => )
  2. It's always better to post the relevant code (using code tags). Many people will not click links to external sites any more than they would if they received emails with an invitation to "click here"
  3. Welcome. I suggest you read the forum rules.
  4. Having created a mysqli connection object and stored it in $con the next thing you do is destroy that object by overwriting it with a string value (your sql code). Secondly, just creating a string of sql code does not execute it. You need to use mysqli::query() eg $sql = "SELECT whatever ..." $con->query($sql);
  5. Here's your pseudocode intialize 6 variables to 0 loop 5000 times get N = random number between 1 and 6 increment variable N by 1 endloop output the 6 variables
  6. I have already given you a link to a solution to this in your previous topic here. If you don't read replies then you are just wasting our time.
  7. Do you mean SELECT * FROM table WHERE ddate BETWEEN UTC_DATE() - INTERVAL 3 DAY AND UTC_DATE() + INTERVAL 3 DAY
  8. Either loop through the rows, opening a new table when the occupation changes, or store records in a 2 dimensional array by occupation then process that array foreach (data as occupation => records) open table for occupation foreach (records as row) write row endforeach close table endforeach
  9. Your data isn't tabular, so why are you trying to shoehorn it into a table? Use divs.
  10. The second query is finding the category whose id matches that in the product. So that is the candidate for the join. I.E. FROM products INNER JOIN categories ON products.category_id = categories.category_id or FROM products INNER JOIN categories USING (category_id) Do not use "SELECT * ". Specify the columns you need (and use aliases) SELECT p.name , p.slug as prodslug , c.slug as catslug FROM FROM products p INNER JOIN categories c ON p.category_id = c.category_id WHERE p.status='1' AND p.featured='1' ORDER BY p.product_id LIMIT 12 See my signature re mysql_ library
  11. I couldn't even get your query from reply #7 to run - you need two variables but you only provide one. It would need to be $parent= 13425; $sql = "SELECT id , dogname , mother_id as dam , father_id as sire , gender FROM dog WHERE mother_id= :parent1 OR father_id = :parent2 ORDER BY id"; $dogs = []; $dogs[0] = ['name' => 'N/A', 'gender' => 'N/A', 'pups' => [] ]; $stmt = $db->prepare($sql); $stmt->bindParam(':parent1', $parent, PDO::PARAM_INT); $stmt->bindParam(':parent2', $parent, PDO::PARAM_INT); $stmt->execute(); However, that is academic as you wouldn't want that query anyway.
  12. I am not sure what you are saying. Using $dog_id = 13425; descendants($dog_id, $dogs); // 3rd parameter used internally to track generation depth (indent) I get Alka Volání Karpat (female) ----- Connor from Bandit's World (male) ----- ----- A.- Magnus the Wolf I. Lord of Lasvegas (male) ----- ----- A.- Marny the Wolf I. Lady of Lasvegas (female) ----- ----- A.- Melody the Wolf I. Lady of Lasvegas (female) ----- ----- A.- Mercedes the Wolf I. Lady of Lasvegas (female) ----- ----- A.- Merlin the Wolf I.Lord of Lasvegas (male) ----- ----- A.- Milena the Wolf I. Lady of Lasvegas (female) ----- ----- A.- Miles the Wolf I. Lord of Lasvegas (male) ----- ----- A.-Minerva the Wolf I. Lady of Lasvegas (female) ----- ----- A.- Mirabell the Wolf I. Lady of Lasvegas (female) ----- ----- A.- Morgan the Wolf I. Lord of Lasvegas (male) ----- ----- Basilea the Wolf I. Lady of Lasvegas (female) ----- ----- Beatrix the Wolf I. Lady of Lasvegas (female) ----- ----- Ben the Wolf I. Lord of Lasvegas (male) ----- ----- Bogdan the Wolf I. Lord of Lasvegas (male) ----- ----- Bonita the Wolf I. Lady of Lasvegas (female) ----- ----- Bozena the Wolf I. Lady of Lasvegas (female) ----- ----- Brix the Wolf I. Lord of Lasvegas (male) ----- ----- Brixius Jack the Wolf I. Lord of Lasvegas (male) ----- ----- Camilo the Wolf I. Lord of Lasvegas (male) ----- ----- Cedric the Wolf I. Lord of Lasvegas (male) ----- ----- Chrysanthus the Wolf I. Lord of Lasvegas (male) ----- ----- Chandra the Wolf I. Lady of Lasvegas (female) ----- ----- Can the Wolf I. Lord of Lasvegas (male) ----- ----- Conan the Wolf I. Lord of Lasvegas (male) ----- ----- El Cid Grey Diamond (male) ----- ----- Eddi the Wolf I. Lord of Lasvegas (male) ----- ----- Elvis the Wolf I. Lord of Lasvegas (male) ----- ----- Ezra the Wolf I. Lord of Lasvegas (male) ----- ----- Emmi the Wolf I. Lady of Lasvegas (female) ----- ----- Esma the Wolf I. Lady of Lasvegas (female) ----- Chunami from Bandit's World (female) ----- ----- Djumana from Bandit's World (female) ----- ----- Delphi from Bandit's World (female) ----- ----- ----- Gangster from Bandit's World (male) ----- ----- ----- Gaucho from Bandit's World (male) ----- ----- ----- Gauner from Bandit's World (male) ----- ----- ----- Ganove from Bandit's World (male) ----- ----- ----- Greedy from Bandit's World (male) ----- ----- ----- Gwendy from Bandit's World (female) ----- ----- ----- Gil from Bandit's World (female) ----- ----- ----- Genesis from Bandit's World (female) ----- ----- Dynamite from Bandit's World (female) ----- ----- Dunbar from Bandit's World (male) ----- ----- Excalibur from Bandit's World (male) ----- ----- Efia-Eliska from Bandit's World (female) ----- ----- Feivel from Bandit's World (male) ----- ----- Fabulous from Bandit's World (male) ----- ----- Floyd from Bandit's World (male) ----- ----- Fraser from Bandit's World (male) ----- ----- Fiasco from Bandit's World (male) ----- ----- For Me from Bandit's World (female) ----- ----- ----- Heartbreaker from Bandit's World (male) ----- ----- ----- Hero from Bandit's World (male) ----- ----- ----- Highlander from Bandit's World (male) ----- ----- ----- Hashtag Houston from Bandit's World (female) ----- ----- Fanny from Bandit's World (female) ----- Chica from Bandit's World (female) ----- Cherina from Bandit's World (female) ----- Chandra from Bandit's World (female) ----- Cazan from Bandit's World (male) ----- Aiyana from Bandit's World (female) ----- Akela from Bandit's World (female) ----- Amy from Bandit's World (female) ----- Bakira from Bandit's World (female) ----- Balko from Bandit's World (male) ----- Bayana from Bandit's World (female) ----- Blaidd from Bandit's World (female) ----- Bruce from Bandit's World (male)
  13. For the record My method Get and store all dogs data : 0.467 seconds Output : 0.001 seconds Jaques' method mysql> SELECT -> d1.id -> , d1.dogname as name1 -> , d1.gender -> , d2.dogname as name3 -> , d3.dogname as name3 -> , d4.dogname as name4 -> , d5.dogname as name5 -> FROM dog d1 -> LEFT JOIN dog d2 ON d1.id IN (d2.mother_id, d2.father_id) -> LEFT JOIN dog d3 ON d2.id IN (d3.mother_id, d3.father_id) -> LEFT JOIN dog d4 ON d3.id IN (d4.mother_id, d4.father_id) -> LEFT JOIN dog d5 ON d4.id IN (d5.mother_id, d5.father_id) -> WHERE d1.id = 8032; 411 rows in set (1 min 46.40 sec)
  14. Use one query to put the dogs into an array, each dog having an array of pups. Then use a recursive function on the array. More efficient than recursive queries $sql = "SELECT id , dogname , mother_id as dam , father_id as sire , gender FROM dog ORDER BY id"; $dogs = []; $dogs[0] = ['name' => 'N/A', 'gender' => 'N/A', 'pups' => [] ]; $res = $db->query($sql); $results = $res->fetchAll(); // // get the dogs // foreach ($results as $d) { if (!isset($dogs[$d['id']])) { $dogs[$d['id']] = [ 'name' => $d['dogname'], 'gender' => $d['gender'], 'pups' => [] ]; } } // // assign their pups // foreach ($results as $d) { $dogs[$d['dam']]['pups'][] = $d['id']; $dogs[$d['sire']]['pups'][] = $d['id']; } function descendants($id, &$dogs, $level=0) { if (!isset($dogs[$id])) return; $indent = str_repeat(' ----- ', $level); echo "$indent{$dogs[$id]['name']} ({$dogs[$id]['gender']})<br>"; if (!empty($dogs[$id]['pups'])) { foreach ($dogs[$id]['pups'] as $pupid) { descendants($pupid, $dogs, $level+1); } } } // // CALL THE RECURSIVE FUNCTION // $dog_id = 8032; descendants($dog_id, $dogs, 0);
  15. You could rearrange the array structure, thus $mydata['note'] = 'hello'; $mydata['other'] = 'test'; $mydata['data'][0]['name'] = 'John Doe'; $mydata['data'][0]['age'] = '32'; $mydata['data'][1]['name'] = 'Jane Doe'; $mydata['data'][1]['age'] = '37'; Now you can count($mydata['data'])
  16. Two words - variable scope. $link is not defined within your function. You need to pass it as a parameter when you call the function. Have you considered indenting your code to make it easier to read?
  17. See this similar problem
  18. When I need to extract chart data covering a range of dates I find it easier to create a temporary table containing all the dates that I need to show on the chart. I use a DatePeriod object to create the range of dates EG mysql> select * from tempdate; +---------+ | month | +---------+ | 2016-01 | | 2016-02 | | 2016-03 | | 2016-04 | | 2016-05 | | 2016-06 | | 2016-07 | | 2016-08 | | 2016-09 | | 2016-10 | | 2016-11 | | 2016-12 | +---------+ So if I have a revenue table like yours ... mysql> select * from revenue; +---------+---------+ | month | revenue | +---------+---------+ | 2016-05 | 20 | | 2016-08 | 10 | | 2016-11 | 50 | +---------+---------+ ... I can fill in the gaps with SELECT t.month , IFNULL(r.revenue, 0) as revenue FROM tempdate t LEFT JOIN revenue r USING (month); +---------+---------+ | month | revenue | +---------+---------+ | 2016-01 | 0 | | 2016-02 | 0 | | 2016-03 | 0 | | 2016-04 | 0 | | 2016-05 | 20 | | 2016-06 | 0 | | 2016-07 | 0 | | 2016-08 | 10 | | 2016-09 | 0 | | 2016-10 | 0 | | 2016-11 | 50 | | 2016-12 | 0 | +---------+---------+
  19. Simpler: $outp = $result->fetch_all(MYSQLI_ASSOC); echo json_encode($outp);
  20. You have the variable inside single quotes - remove them. (The value it is looking for is the literal string $-k-e-y instead of the variable's value)
  21. I'd separate the time check from the day check if it is a work day if it is work hour we are open else we are closed endif else we are closed endif
  22. So for it to work as it did with a separate time column, are the time elements the same in the two datetime columns? When comparing a date with a datetime column you need to use only the date portion of the datetime. So if my opening assumption is true SELECT id , schedule_start , schedule_end WHERE UTC_DATE() BETWEEN DATE(schedule_start) AND DATE(schedule_end) AND EXTRACT(HOUR_MINUTE FROM UTC_TIME()) = EXTRACT(HOUR_MINUTE FROM schedule_start)
×
×
  • 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.