-
Posts
24,602 -
Joined
-
Last visited
-
Days Won
830
Everything posted by Barand
-
So long as that "higher value" isn't higher than 2147483648
-
Your syntax is wrong. UNION should be inside the quotes otherwise PHP assumes it is defined constant. When it then finds no definition then it assumes (correctly) that it meant to be a string value. $query = $query1 . " UNION " . $query2;
-
The moral is "Don't use 'SELECT * '. Specify the columns you want."
-
It's a SELECT query. It is not changing any data in your database.
-
mysqli prepared statements on tables joined by a common value
Barand replied to ajoo's topic in MySQL Help
An explicit JOIN, as Ch0cU3r used, is more efficient and also better shows the structure of the query by separating the join conditions from the selection criteria in the WHERE clause. Also the purpose of prepared queries is to prevent injection from user-supplied data via variables. 'active' is a constant and therefore just include it in the statement SELECT ud.User_club_ID, ud.fname, ud.lname, ud.email, ud.club_No c.CLUBCODE, c.club_id FROM user_details AS ud JOIN club AS c ON ud.club_No = c.CLUBCODE WHERE c.club_id = ? AND ud.user_status = 'active' "; -
1. I am not on your payroll and therefore do not respond well to comments like 2. I haven't a clue what you are talking about when you say
-
A signed integer will hold up to 2,147,483,648 (ie 2^31)
-
Use a JOIN to find the matching records instead of IN (SELECT ...) $tblsell = PRFX.'sell'; $tblskipped = PRFX.'skipped'; $sql = "SELECT * FROM $tblsell AS sel INNER JOIN $tblskipped AS sk ON sel.id = sk.id_ AND sk.uid = $u WHERE sel.draft = 0 ORDER BY sk.id" ;
-
Use foreign keys with the ON UPDATE and/or ON DELETE actions set to CASCADE http://dev.mysql.com/doc/refman/5.6/en/create-table-foreign-keys.html
-
Opening a file with "w" mode creates the file. $firstgroup=fopen('firstgroup.txt', "w");
-
$firstgroup=fopen('firstgroup.txt', "w"); foreach ($groupone as $row) { fputcsv($firstgroup, $row); } fclose($firstgroup);
-
use foreach() loops to iterate through your group1 and group2 arrays. use fputcsv() to write to the output files.
-
You need to pass $conn to the function function graphdata($conn) { ... } print json_encode(graphdata($conn));
-
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);