-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
And the missing id=7 matters because...? Your database should function just the same if ids were allocated randomly rather than sequentially. The only thing that matters is that it should be unique.
-
Does this get you any closer? (not tested) function graphdata() { $array['cols'][] = array( 'id' => '', 'label' => 'DateCreated', 'pattern' => '', 'type' => 'string' ); $array['cols'][] = array( 'id' => '', 'label' => 'UnitPrice', 'pattern' => '', 'type' => 'number' ); $result = sqlsrv_query($conn, $query); while($row = sqlsrv_fetch_object($result)){ $array['rows'][] = array ( 'c' =>array( array ('v' => $row->DateCreated->format('d-m-Y'), 'f' => ''), array ('v' => $row->UnitPrice, 'f' => ''), ) ); } return $array; }
-
You're right, the subquery is superfluous.
-
Perhaps SELECT s.shoe_id , s.shoe_name FROM shoe s INNER JOIN ( SELECT shoe_id FROM shoe_type WHERE type_id IN (1,3) ) t USING (shoe_id) GROUP BY shoe_id HAVING COUNT(*) = 2;
-
The answer is "data normalization" http://forums.phpfreaks.com/topic/273634-best-way-to-set-up-tables-when-multiple-values/?do=findComment&comment=1408360 So if shoe 1 is available in brown and suitable for hiking and walking shoe 2 is available in brown and white and suitable for running color shoe type +----------+-------+ +---------+-----------+ +---------+-----------+ | color_id | color | | shoe_id | shoe_name | | type_id | type | +----------|-------+ +---------+-----------+ +---------+-----------+ | 1 | brown | | 1 | Nike | | 1 | Walking | | 2 | white | | 2 | Adidas | | 2 | Running | +----------+-------+ +---------+-----------+ | 3 | Hiking | | | | +---------+-----------+ | | | | +--------------+ | +----------------------+ | | | | | shoe_color | | shoe_type | | +-----+-----------+---------+ +----+---------+---------+ | id | color_id | shoe_id | | id | shoe_id | type_id | +-----+-----------+---------+ +----+---------+---------+ | 1 | 1 | 1 | | 1 | 1 | 1 | | 2 | 1 | 2 | | 2 | 1 | 3 | | 3 | 2 | 2 | | 3 | 2 | 2 | +-----+-----------+---------+ +----+---------+---------+
-
MySQL has an "INSERT ... ON DUPLICATE KEY UPDATE ... " option so you can update records where on with the same key already exists and insert a new record when it doesn't. http://dev.mysql.com/doc/refman/5.6/en/insert-on-duplicate.html
-
If you find one, let me know. I haven't a clue what you are asking unless it is something like this SELECT s.studentid , s.lastname , c.classname , SUM(CASE WHEN period=1 THEN grade ELSE NULL END) as Period_1 , SUM(CASE WHEN period=2 THEN grade ELSE NULL END) as Period_2 , SUM(CASE WHEN period=3 THEN grade ELSE NULL END) as Period_3 , SUM(CASE WHEN period=4 THEN grade ELSE NULL END) as Period_4 FROM students s INNER JOIN classes c USING (studentid) LEFT JOIN grades USING (studentid) GROUP BY s.lastname
-
In which case you would pass the mod name and your array to the function. Make the mod name the index of the array. function getMod($mod, &$modarray) { $page = file_get_contents($modarray[$mod][0]); $posStart = strpos($page, "Newest File: ") + $modarray[$mod][1]; $posStop = strpos($page, "<",$posStart) + $modarray[$mod][2]; $version = substr($page, $posStart, $posStop-$posStart); $output = "<br>{$mod}<br>version $version<br>"; return $output; } $mods = array ( "RailCraft" => array("http://www.curse.com/mc-mods/minecraft/railcraft",23,0), "Tinker's Construct" => array("http://www.curse.com/mc-mods/minecraft/tinkers-construct",31,-4), ); // IF YOU WANT ALL THEN foreach ($mods as $mod => $modArray) { echo getMod($mod, $mods); } // IF YOU WANT ONE THEN echo getMod("RailCraft", $mods);
-
The way it is at the moment you need to pass the array echo getMod( array("RailCraft","http://www.curse.com/mc-mods/minecraft/railcraft",23,0) );
-
As well as the array, use a function instead of repeating the code every time function getMod($mod) { $page = file_get_contents($mod[1]); $posStart = strpos($page, "Newest File: ") + $mod[2]; $posStop = strpos($page, "<",$posStart) + $mod[3]; $version = substr($page, $posStart, $posStop-$posStart); $output = "<br>{$mod[0]}<br>version $version<br>"; return $output; } $mods = array ( array("RailCraft","http://www.curse.com/mc-mods/minecraft/railcraft",23,0), array("Tinker's Construct","http://www.curse.com/mc-mods/minecraft/tinkers-construct",31,-4), ); foreach ($mods as $mod) { echo getMod($mod); }
-
That is how I would interpret the results that I got. Regex is powerful but slow compared to native string functions.
-
functioncall(array(),$variable) is calling the function and passing two parameters. The first is an empty array, the second is whatever is in $variable. No different from $a = array(); $b = array(1,2,3); functioncall ($a, $b);
-
Return Multiple Values from picklist using $_REQUEST
Barand replied to jlam1021's topic in PHP Coding Help
You need to append [] to the select name so the choices are posted as an array <select multiple name='Status[]' id='Status'> -
Your query is duplicating information. The counts from the subqueries are the same in every row. The count from the browser XXX subquery is always the same as the total count in the XXX row so you would get as much information by omitting the subqueries altogether.
-
Running both methods 100 times gave me STRPOS: 0.002000 sec REGEX : 0.004000 sec
-
You should read the manual for substr() $version = substr($page, $posStart, $posStop-$posStart);
-
sql is works in phpmyadmin but not working in php with special case
Barand replied to gratsami's topic in PHP Coding Help
Having just Googled "PDO rowCount" there appears to be issues on unbuffered result sets always returning a zero count. It certainly worked ok with mysqli $mysqli = new mysqli(HOST,USERNAME,PASSWORD,'test'); $plate = isset($_GET['plate']) ? $_GET['plate'] : ''; $sql = "SELECT * FROM vehicles WHERE platenumber = ?"; $stmt = $mysqli->prepare($sql); $stmt->bind_param('s', $plate); $stmt->execute(); $res = $stmt->get_result(); if ($res->num_rows) { $row = $res->fetch_row(); echo $row[0] . ' | ' . $row[1]; } else echo "No results"; ?> <html> <head> <style type='text/css'> td {text-align: center;} </style> </head> <body> <form> Plate <input type='text' name='plate' value=''> <input type='submit' name='btnSub' value='Submit'> </form> </body> </html> -
sql is works in phpmyadmin but not working in php with special case
Barand replied to gratsami's topic in PHP Coding Help
The question that immediately springs to mind is "Why the hell would anyone do that?" -
With a few test records mysql> SELECT * FROM browsers; +----+---------+-----------------+---------+ | id | browser | ip | country | +----+---------+-----------------+---------+ | 1 | Chrome | 123.123.123.123 | UK | | 2 | Chrome | 123.123.124.124 | UK | | 3 | Chrome | 123.123.123.125 | USA | | 4 | Firefox | 12.12.12.12 | FRA | | 5 | Safari | 23.23.23.23 | UK | | 6 | Safari | 25.25.25.25 | USA | +----+---------+-----------------+---------+ Your query gave me
-
See http://forums.phpfreaks.com/topic/292890-invalid-selection/?do=findComment&comment=1498515
-
I can attest to that
-
Alex, There is <input type='image'> which will submit the form when clicked, and also pass the x.y coordinates of where the image was clicked
-
If your arrays and options are always sorted in the same order function test($map,$array1) { $value=false; foreach($map as $elem) { if($array1 == $elem['options']) { $value=$elem['name']; break; } } return $value; }
-
If all you want is a row count then selecting all the records and counting them is the inefficient way to do it. You should use SELECT COUNT(*) as count FROM mxit Then look at value returned in $row['count']
-
Yes - Step 1 = get array "c" for unique combinations of a and b while (list($a, $b, $c) = $result->fetch_row()) { $data[$a][$b][] = $c; } // STEP 2 foreach ($data as $a => $adata) { foreach ($adata as $b => $c) { $result[] = array('a' => $a, 'b' => $b, 'c' => $c); } }