-
Posts
24,551 -
Joined
-
Last visited
-
Days Won
821
Community Answers
-
Barand's post in Range with Letters and Numbers was marked as the answer
SELECT whatever FROM mytable WHERE mycol BETWEEN '1A' AND '5D' -
Barand's post in Best way to design these tables and query them? was marked as the answer
Yes.
SELECT member_name , studs.member_id , GROUP_CONCAT(school_name, '(', s.school_id, ')' SEPARATOR ', ') as schools FROM ( SELECT member_name , member_id FROM members WHERE created_by = 10 AND role_id = 2 UNION -- -- select students from schools -- created by admin #10 -- SELECT member_name , m.member_id FROM members m INNER JOIN school_members sm USING (member_id) INNER JOIN schools s USING (school_id) WHERE s.created_by=10 AND m.role_id = 2 UNION -- -- select students from schools -- where admin #10 is a member -- SELECT member_name , m.member_id FROM members m INNER JOIN school_members sm1 ON m.member_id = sm1.member_id INNER JOIN school_members sm2 ON sm1.school_id = sm1.school_id WHERE sm2.member_id = 10 AND m.role_id = 2 ) studs LEFT JOIN school_members USING (member_id) LEFT JOIN schools s USING (school_id) GROUP BY member_name ; -
Barand's post in Query help - looking for members of two different groups was marked as the answer
In that case you need to connect twice to the user_role table
SELECT users.uid, users.`name`, users.mail, users.created, ur1.rid as rid1, ur2.rid as rid2, field_data_field_first_name.field_first_name_value, field_data_node_venue_region.node_venue_region_tid FROM users INNER JOIN users_roles ur1 ON users.uid = ur1.uid AND ur1.rid = 7 INNER JOIN users_roles ur2 ON users.uid = ur2.uid AND ur2.rid = 8 INNER JOIN field_data_field_first_name ON field_data_field_first_name.entity_id = users.uid INNER JOIN field_data_node_venue_region ON field_data_node_venue_region.entity_id = users.uid -
Barand's post in Creating relationship tables from JSON data.... was marked as the answer
This should show you the logic you need to employee to process your data. (Note this is pseudocode, not runnable code)
$jsondata = '[{"payee":"John Doe","amount":5.25},{"payee":"Joe Smith","children":[{"amount":10.25,"category":"Groceries"},{"amount":5.75,"category":"Dining out"}]}]'; $data = json_decode($jsondata,1); foreach ($data as $trans) { if (isset($trans['children'])) { insert into transaction (payee) VALUES '{$trans[payee]}' $parentid = last_insert_id(); foreach ($trans['children'] as $child) { insert into transaction (parent,amount,category) VALUES ($parentid, $child[amount], $child[category]) } } else { insert into transactions (payee,amount) VALUES ($trans[payee], trans[amount]) } } -
Barand's post in I need some help. Trying to show label before showing pictures in a row. was marked as the answer
If you are looping through the items when outputting the results, why are you using $row['cid'] etc instead of $item['cid']?
-
Barand's post in Column 'description' cannot be part of FULLTEXT index was marked as the answer
You need MySQL 5.6+ for fulltext on InnoDB
-
Barand's post in Trouble with LOAD DATA INFILE was marked as the answer
I would think the "\r\n" is the cure. Let us know.
-
Barand's post in PDO delete mysql records from multiple tables where the id is the same was marked as the answer
I see, different in each table. Need to change the syntax
DELETE table1, table2, table3 FROM table1 LEFT JOIN table2 ON Rooms.id = Room_users.Roomid LEFT JOIN table3 ON Rooms.id = Room_chats.roomid WHERE table1.time < UNIX_TIMESTAMP() -
Barand's post in Very strange behavior was marked as the answer
Your second code doesn't "return" the rows it just prints the array containing the rows.
Is that code inside a function? If not you shouldn't be using return. If it is, how are you processing the results returned by the first code.
You should not be running queries inside a loop, you should use a JOIN to get all the results in a single query call, like this
SELECT p.id , p.title , p.description FROM posts as p JOIN post_members as pm ON p.id = pm.post_id WHERE pm.userid = :userid -
Barand's post in delete a SQL row after a week was marked as the answer
You would use Windows Scheduler or a cron job (linux) to invoke the query.
-
Barand's post in Left join and SUM problem was marked as the answer
I suspect that some of your rows are duplicated because of the joins
-
Barand's post in php login issue was marked as the answer
session_start() needs be called before any output is sent to the browser. You are currently sending the form fields first. Move the php code above the form code.
You are attempting to use the content of $_POST['mail'] and $_POST['pass'] before you check if any data was POSTed.
You only retrieve a single record with the query, so why is there a while() loop?
When you use header() to redirect, there should be an exit; command following it to prevent the rest of the script from being executed.
Use password_hash() and password_verify()
-
Barand's post in Retrieving Birthday from database MySQL php problem was marked as the answer
That will only get those who were born today, not whose birthday falls today.
SELECT username , pdob , YEAR(CURDATE())-YEAR(pdob) as age FROM table WHERE MONTH(pdob)=MONTH(CURDATE()) AND DAY(pdob)=DAY(CURDATE()) -
Barand's post in Insert multiple rows in mysqli prepared statement was marked as the answer
then
$beneficiary = 123; // or whatever $bank_data = array ( array($branchId1 , $acc1), array($branchId2 , $acc2) ); $sql = "INSERT INTO user_bank (beneficiary_id, branch_id, account VALUES (?,?,?))"; $stmt = $db->prepare($sql); $stmt->bind_param('ii', $benficiary,$branch, $acc); foreach ($bank_data as $bdata) { list($branch, $acc) = $bdata; $stmt->execute(); } -
Barand's post in Finding a route in mysql was marked as the answer
Having seen your data reminded me you need to join on SectorDate too.
Mk III version
SELECT * FROM ( SELECT Dep as depA , BeginTime as deptimeA , Arr as arrA , EndTime as arrtimeA , SectorDate FROM rosters WHERE Dep='MAN' AND BeginTime > '03:00' AND SectorDate = '2015-11-26' ) a LEFT JOIN ( SELECT Dep as depB , BeginTime as deptimeB , Arr as arrB , EndTime as arrtimeB , SectorDate FROM rosters ) b ON arrA = depB AND arrtimeA < deptimeB AND a.SectorDate = b.SectorDate LEFT JOIN ( SELECT Dep as depC , BeginTime as deptimeC , Arr as arrC , EndTime as arrtimeC , SectorDate FROM rosters ) c ON arrB = depC AND arrtimeB < deptimeC AND b.SectorDate=c.SectorDate WHERE 'DUB' IN (arrA, ArrB, ArrC) -
Barand's post in Error when using mysql sub query was marked as the answer
If you want the count for each team
JOIN ( SELECT team_id, status, COUNT(*) AS nap FROM `team_players` WHERE status = '1' GROUP BY team_id ) AS tp ON td.team_id = tp.team_id -
Barand's post in how to create timezone select menu using PHP was marked as the answer
perhaps
$arr = timezone_identifiers_list(); foreach ($arr as $tz) { if (strpos($tz, '/')===false ) continue; list ($region, $city) = explode('/', $tz, 2); $d = new DateTimeZone($tz); $secs = $d->getOffset(new DateTime()); $offset = number_format($secs/3600, 2); $tzArray[$offset][$region][] = $city; } ksort($tzArray); $menu = "<option value=''>- select timezone -</option>\n"; foreach ($tzArray as $o => $regzones) { $menu .= sprintf("<optgroup label='GMT %+0.2f'>\n", $o); ksort($regzones); foreach ($regzones as $region => $cities) { foreach ($cities as $city) $menu .= "<option >$region/$city</option>\n"; } $menu .= "</optgroup>\n"; } ?> <select name='tzone'> <?=$menu?> </select> -
Barand's post in swap column values was marked as the answer
Look again!
before: ID: 14 Cover:1 after: ID: 14 Cover:0 Both the image and cover are changed.
If your objective is to switch which is the main image, just change cover and not the image name (or vice versa)
-
Barand's post in search a MySql table using PHP was marked as the answer
According to my IDE, the {s at the ends of these three lines have no corresponding closing }s
<?php if(isset($_POST['submit'])){ if(isset($_GET['go'])){ if(preg_match("/^[ a-zA-Z]+/", $_POST['search'])){ -
Barand's post in blank spaces in my textarea was marked as the answer
Everything between the textarea tags is part of the value, including all the whitespace in your source.
Use
<textarea name="comments"><?php echo $comments; ?></textarea> -
Barand's post in SELECT ALL Query using IN was marked as the answer
The simple answer is "No".
If you want to select all, don't specify the IN() condition
-
Barand's post in Help with Query issues... was marked as the answer
you could use something like this
SELECT a.user , group_concat(b.user) as guests , count(b.guestof) as total FROM userlist a LEFT JOIN userlist b ON b.guestof = a.user GROUP BY a.user ; +-------+-----------+-------+ | user | guests | total | +-------+-----------+-------+ | Bill | Jason | 1 | | Frank | NULL | 0 | | Gwen | NULL | 0 | | Jack | Gwen,Matt | 2 | | Jason | Jill,Jack | 2 | | Jill | Frank,Stu | 2 | | Matt | NULL | 0 | | Stu | NULL | 0 | +-------+-----------+-------+ -
Barand's post in Array extraction & variables was marked as the answer
Do it all in the query
SELECT ..., COUNT(*) as total FROM ... WHERE status='Done' GROUP BY student_email -
Barand's post in Optaining the clicked value from a table in an input was marked as the answer
I'd make use of data attributes to get the data in one place when clicked. Here's an example using a couple of your rows
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Primes & Factors</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type="text/javascript"> $().ready(function() { $(".old-price, .orange-price").click(function() { var vol = $(this).data('vol'); var price = $(this).html(); $("#vol").val(vol); $("#price").val(price); }) }) </script> <style type="text/css"> .old-price, .orange-price { cursor: pointer; } caption { font-size: 14pt; font-weight: 600; } </style> </head> <body> <table id="myTable" class="demo"> <caption> Sisteme de cosuri fum TONA <span class="orange-price">- 15% REDUCERE</span> </caption> <thead> <tr> <th> Inaltime / Dimensiune </th> <th>Ø 14</th> <th>Ø 16</th> <th>Ø 18</th> <th>Ø 20</th> <th>Ø 25</th> </tr> </thead> <tbody> <tr> <td>5 ml <br> </td> <td><span data-vol='5' class="old-price">583 EUR</span> <br> <span data-vol='5' class="orange-price">496 EUR</span> </td> <td><span data-vol='5' class="old-price">630 EUR</span> <br> <span data-vol='5' class="orange-price">536 EUR</span> </td> <td><span data-vol='5' class="old-price">661 EUR</span> <br> <span data-vol='5' class="orange-price">562 EUR</span> </td> <td><span data-vol='5' class="old-price">704 EUR</span> <br> <span data-vol='5' class="orange-price">598 EUR</span> </td> <td><span data-vol='5' class="old-price">1125 EUR</span> <br> <span data-vol='5' class="orange-price">956 EUR</span> </td> </tr> <tr> <td>5.5 ml</td> <td><span data-vol='5.5' class="old-price">608 EUR</span> <br> <span data-vol='5.5' class="orange-price">517 EUR</span> </td> <td><span data-vol='5.5' class="old-price">659 EUR</span> <br> <span data-vol='5.5' class="orange-price">560 EUR</span> </td> <td><span data-vol='5.5' class="old-price">692 EUR</span> <br> <span data-vol='5.5' class="orange-price">588 EUR</span> </td> <td><span data-vol='5.5' class="old-price">737 EUR</span> <br> <span data-vol='5.5' class="orange-price">626 EUR</span> </td> <td><span data-vol='5.5' class="old-price">1187 EUR</span> <br> <span data-vol='5.5' class="orange-price">1009 EUR</span> </td> </tr> </tbody> </table> <br> Chosen volume <input type="text" name="vol" id="vol" size="5"> Chosen price <input type="text" name="price" id="price" size="8"> </body> </html>