-
Posts
24,566 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
The query you posted returns nothing but a syntax error. There is a missing ")" after the first "signed"
-
try $startStamp = 1487156507; $endStamp = 1487156573; $dt1 = new DateTime("@$startStamp"); $dt2 = new DateTime("@$endStamp"); echo $dt1->diff($dt2)->format('%H:%I:%S').'<br>'; //--> 00:01:06
-
'value'=>'Valor de referencia de 1 bitcoin incluindo taxas: R$ ' . number_format($ask * 1.025, 2);
-
Then alter the solution, adapting it to your needs.
-
Putting the first 20 sets of data into excel and plotting a polynomial trendline gave y = 2.3226x3 - 1.5788x2 - 22.829x + 43.886 So you could use that or approximate it to $y = 2.323 * pow($x, 3);
-
That code that I linked you to was in a thread of yours from a few weeks ago, yet here you are again with the same problems Have another look at the linked code - particularly at how parameters are used in prepared queries.
-
Looks like it may be a problem similar to this one
-
Perhaps it is suffering from a surfeit of parentheses.
-
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] => )
-
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"
-
Welcome. I suggest you read the forum rules.
-
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);
-
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
-
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.
-
Do you mean SELECT * FROM table WHERE ddate BETWEEN UTC_DATE() - INTERVAL 3 DAY AND UTC_DATE() + INTERVAL 3 DAY
-
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
-
Your data isn't tabular, so why are you trying to shoehorn it into a table? Use divs.
-
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
-
getting all offsprings (with x generations) from a given id
Barand replied to Tanja's topic in PHP Coding Help
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. -
getting all offsprings (with x generations) from a given id
Barand replied to Tanja's topic in PHP Coding Help
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) -
getting all offsprings (with x generations) from a given id
Barand replied to Tanja's topic in PHP Coding Help
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) -
getting all offsprings (with x generations) from a given id
Barand replied to Tanja's topic in PHP Coding Help
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); -
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'])
-
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?
-
See this similar problem