-
Posts
24,566 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Can't get my innerjoin to work with select sum groupby
Barand replied to alphamoment's topic in PHP Coding Help
If you give the count an alias, say 'total', then you can reference that eg echo $row['total']; and also order by the total too SELECT t2.PlayerName , COUNT(t1.ID) as total FROM Table2 t2 LEFT JOIN Table1 ON t2.PlayerID = t1.ID GROUP BY PlayerName ORDER BY total DESC -
Yes, he did. http://forums.phpfreaks.com/topic/296326-foreach-or-while-table-columns-and-rows/ Going around in circles with this one.
-
If you post your code we can see what you are doing and where you are going wrong
-
Can't get my innerjoin to work with select sum groupby
Barand replied to alphamoment's topic in PHP Coding Help
Oops. I forgot the GROUP BY SELECT t2.PlayerName , COUNT(t1.ID) FROM Table2 t2 LEFT JOIN Table1 ON t2.PlayerID = t1.ID GROUP BY PlayerName -
Can't get my innerjoin to work with select sum groupby
Barand replied to alphamoment's topic in PHP Coding Help
try SELECT t2.PlayerName , COUNT(t1.ID) FROM Table2 t2 LEFT JOIN Table1 ON t2.PlayerID = t1.ID -
Doing it this way would require you pass just the application id (I'm guessing at the column name for the user_id in the application table) UPDATE applications a INNER JOIN users u ON a.user_id = u.id SET a.status = 2, u.verifypend = 0, u.verified = 1 WHERE a.id = :appid ;
-
Alternatively, you could use an ENUM type column CREATE TABLE `users` ( `id` int(5) NOT NULL AUTO_INCREMENT, `username` varchar(45) DEFAULT NULL, `status` enum('yes','no','maybe') NOT NULL DEFAULT 'no', PRIMARY KEY (`id`) ) ; INSERT INTO users (username,status) VALUES ('Peter', 1), ('Paul', 3), ('Mary', 2); Then when you select mysql> SELECT * FROM users; +----+----------+--------+ | id | username | status | +----+----------+--------+ | 1 | Peter | yes | | 2 | Paul | maybe | | 3 | Mary | no | +----+----------+--------+
-
SELECT CASE colname WHEN 1 THEN 'Yes' WHEN 2 THEN 'No' ELSE 'Maybe' END as Selection FROM tablename
-
Getting an array from a table with PHP and MySql
Barand replied to pixelz's topic in PHP Coding Help
A single joined query should do it SELECT author , osid , type , postdate FROM friends f INNER JOIN statuses s ON f.user2_id = s.user_id ORDER BY author -
How would I remove an instance of a class inside a array
Barand replied to Supervan's topic in PHP Coding Help
Don't use a for() loop, use foreach() foreach ($_SESSION['cart'] as $id => $item) { echo "<table><tr>" . "<td>" . $id. "</td>" . "<td>" . $item->getName() . "</td>" . "<td><a href=\"index1.php?delinfo=" . $id . ">Delete </a></td>" . "</tr></table"; } -
How would I remove an instance of a class inside a array
Barand replied to Supervan's topic in PHP Coding Help
If you stored them as I suggested, the index of each cart item in the array would be its id. To see if it already exists $item = new Item($result->id, $result->name); if (isset($_SESSION['cart'][$result->id]) { echo "Item already exists in cart"; } Unfortunalely, as soon as you do this $cart = array_values($cart); $_SESSION['cart'] = $cart; you lose the id keys that you assigned so you can't find them anymore. -
You are inserting a record into the drive_routes table. That table has a column called "start" Therefore it is trying to put something into that column. As you haven't specified what to put in there it will try to put NULL. But you have said it is not allowed to be null, hence the error. So, as I have said, give a value when you insert, or define a default value. Sorry but I don't know how to say it any clearer than that.
-
You are not giving the "start" column a value in the INSERT statement so it will try to give it a null value. You must either Give a value in the insert query, or define a default non-null value in the table definition edit: Columns defined as NOT NULL should have a default value.
-
Create a gd image from the jpg image file $im = imagecreatefromjpg('pathToImageFile'); Add the text using imagettftext() or imagestring() Output the new image with imagejpg()
-
A luxury after using MS_SQL
- 7 replies
-
- select count
- date
-
(and 1 more)
Tagged with:
-
try <html> <head> <meta name="generator" content="PhpED 14.0 (Build 14039, 64bit)"> <title>Sample</title> <meta name="creation-date" content="05/27/2015"> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script> $(document).ready(function() { $(".view").hide(); // hide all $('#viewSelector').change(function() { // hide all $(".view").hide(); // show current $("#"+$(this).val()).show(); }); }); </script> </head> <body> Have you been part of any other VTC's before this application?<br> <select id="viewSelector"> <option value="0">---Select one---</option> <option value="YES">Yes</option> <option value="NO">No</option> </select> <div id="YES" class='view'> If so, which VTC's have you been in and what was your reason for quitting?<br> <input type="text" name="otherVTC" class="form-control" placeholder="Example: <vtc name>: reason, <vtc name>: reason, etc." required><br /> </div><br> <div id="NO" class='view'> <p>Visible if NO selected</p><br /> </div><br> </body> </html>
-
How would I remove an instance of a class inside a array
Barand replied to Supervan's topic in PHP Coding Help
Perhaps use the id as the key inside the array $item = new Item($result->id, $result->name); $_SESSION['cart'][$result->id] = $item; then unset($_SESSION['cart'][$id]; -
I don't see any element with class='viewMap'
-
I know I am stating the obvious, but if permissions haven't changed and the code hasn't changed then it has to be something else that changed. You need to put on your "detective" hat and figure out what has changed between the time it last worked and the time it stopped working.
-
In fact, as long as the date is in the correct format it works with VARCHAR datetimes too CREATE TABLE `test_date` ( `id` int(11) NOT NULL AUTO_INCREMENT, `date` datetime DEFAULT NULL, `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `str_date` varchar(20) DEFAULT NULL, PRIMARY KEY (`id`) ) mysql> SELECT -> date -> , DATE(date) as date_only -> , timestamp -> , DATE(timestamp) as ts_date_only -> , str_date -> , DATE(str_date) as s_date_only -> FROM test_date; +---------------------+------------+---------------------+--------------+---------------------+-------------+ | date | date_only | timestamp | ts_date_only | str_date | s_date_only | +---------------------+------------+---------------------+--------------+---------------------+-------------+ | 2015-05-26 17:55:00 | 2015-05-26 | 2015-05-26 18:03:31 | 2015-05-26 | 2015-05-26 17:55:00 |2015-05-26 | +---------------------+------------+---------------------+--------------+---------------------+-------------+
- 7 replies
-
- select count
- date
-
(and 1 more)
Tagged with:
-
If it were stored as DATETIME then DATE(`history_date`) would work just the same.
- 7 replies
-
- select count
- date
-
(and 1 more)
Tagged with:
-
Timestamps have a date and time element (2015-05-26 16:53:30) so will not be equal to today's date (2015-05-26) which has 00:00:00 as its time element. You need to use DATE() function to extract the date portion. SELECT ... WHERE DATE(history_date) = CURDATE()
- 7 replies
-
- select count
- date
-
(and 1 more)
Tagged with:
-
'01-01-1970' is what you get when formatting an invalid or 0 date. As the error message states, the fetch_assoc is failing but you still try to output it. if(mysql_num_rows($note_query)!=0) { $note_rs=mysql_fetch_assoc(); } Above is where you call the first row, the function call is missing the argument
-
From your data +--------+--------+------+ | worker | client | main | +--------+--------+------+ | w1 | c1 | 1 | | w1 | c3 | 0 | | w1 | c4 | 0 | | w1 | c5 | 0 | | w2 | c1 | 0 | | w2 | c2 | 1 | | w2 | c4 | 0 | | w3 | c3 | 0 | | w3 | c4 | 0 | | w3 | c5 | 1 | | w4 | c1 | 0 | | w4 | c2 | 0 | | w4 | c4 | 0 | | w4 | c5 | 1 | | w5 | c1 | 0 | | w5 | c3 | 1 | | w5 | c4 | 0 | | w6 | c2 | 0 | | w6 | c3 | 1 | | w7 | c1 | 0 | | w7 | c2 | 1 | | w7 | c4 | 0 | +--------+--------+------+ I got this assessment schedule (which is as even as I can get it) c1 c2 c3 c4 c5 w1 M A w2 A M w3 A M w4 A M w5 M A w6 A M w7 A M The code $sql = "SELECT worker , client , main FROM worker_client"; $worker = []; // worker assessments $client = []; // client assessed by $res = $db->query($sql); while (list($w,$c,$m) = $res->fetch_row()) { $client[$c][$w] = 0; if ($m) { // allocate assessments of main clients first $worker[$w][] = $c; $client[$c][$w] = 1; } } // while still workers with < 2 assessments while (array_filter($worker, 'assess1')) { // sort to get clients with least assessments first uasort($client, function($a,$b){ return array_sum($a) - array_sum($b);}); foreach ($client as $c => $warr) { asort($warr); foreach ($warr as $w => $k) { if ($k==0) { // if worker has < 2 assessments, add client to their list if (count($worker[$w])<2) { $worker[$w][] = $c; $client[$c][$w]++; break; } } } } } echo '<pre>',print_r($worker, true),'</pre>'; // assessment schedule function assess1($var) // array filter function { return count($var) < 2; }
-
What attribute of an evaluation has to be proportional? To what should it be proportional? Perhaps the number of words in each evaluation should be proportional to the client's weight? Give us a clue.