-
Posts
24,605 -
Joined
-
Last visited
-
Days Won
831
Everything posted by Barand
-
Strange that your sub-categories do not belong to any category in that diagram
-
You can only create the foreign key constraint if all records in chat have a matching uid in account table. You first need to fix those that do not match.
-
So you need to find at least one record where the specific_id has both the value 15 and the value 19 at the same time. Good hunting!
-
It appears that most of the tables in that query are just fluff. Most of those tables that are LEFT JOINed are not used. For example, your subquery "s" will contain all rows from specifics table (since the others are left joined) and the only condition you're using on that subquery is from the specifics table. Also you have no join condition for that subquery.
-
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]) } }
-
I need some help. Trying to show label before showing pictures in a row.
Barand replied to vet911's topic in PHP Coding Help
If you are looping through the items when outputting the results, why are you using $row['cid'] etc instead of $item['cid']? -
What is this "XY problem" to which you keep alluding?
-
I need some help. Trying to show label before showing pictures in a row.
Barand replied to vet911's topic in PHP Coding Help
You need to build an array for each label. You just keep overwriting the single element each time. Try $custResArray[$row['label']][] = array('list_images'=>$row['list_images'], 'image_th'=>$row['image_th'], 'image'=>$row['image'], 'cid'=>$row['cid'], 'comment'=>$row['comment']); Note the added [] in $custResArray[$row['label']][] -
Sorry,
-
Not tested UPDATE Room_users INNER JOIN Users2 u ON u.mxitid = Room_users.mxitid INNER JOIN Rooms u ON u.mxitid = Rooms.mxitid SET Room_users.User = u.Username ,Rooms.creator = u.Username Duplicating the username across three tables is destroying your database normalization. You should store it in one place only (Users) and retrieve it with a join when needed.
-
No, it is a keyword but not reserved. Example mysql> CREATE TABLE nametest (name varchar(30)); Query OK, 0 rows affected (0.27 sec) mysql> INSERT INTO nametest VALUES ('Peter'),('Paul'),('Mary'); Query OK, 3 rows affected (0.00 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> SELECT name FROM nametest; +-------+ | name | +-------+ | Peter | | Paul | | Mary | +-------+ 3 rows in set (0.00 sec)
-
Merry Christmas!
-
... WHERE exrdate BETWEEN LAST_DAY(CURDATE()) + INTERVAL 1 DAY - INTERVAL 3 MONTH AND LAST_DAY(CURDATE())
-
That query will get you those records with dates between "2015-09-24 16:51:43" and "2015-12-24 16:51:43". Is that what you want?
-
What happened to your GROUP BY and ORDER BY?
-
You will need a WHERE clause otherwise you will get all months in the table.
-
The echo would be inside the while loop
-
Column 'description' cannot be part of FULLTEXT index
Barand replied to Destramic's topic in MySQL Help
You need MySQL 5.6+ for fulltext on InnoDB -
I need some help. Trying to show label before showing pictures in a row.
Barand replied to vet911's topic in PHP Coding Help
Check for changes in the title value. When a new value is encountered, output the new title. pseudocode: prev = ''; while (fetch next row) { if (title != prev) { output title prev = title // reset previous value } output image } -
Help understanding why this Mysql Query is badly designed.
Barand replied to blmg2009's topic in MySQL Help
I am surprised it runs as quickly as it does given all those dependent subqueries. For every record read you perform 15+ subqueries. Get rid of those subqueries and use JOINS. -
Seems a pointless question but, yes, so long as you don't want to change the company name.
-
As long as your existing id is "1" then the version you had in #3 should work. (It worked for me)
-
This is an example of a function I use for UK holidays, but should be easily adaptable. In UK, if the holiday falls at weekend, the day-off is the following Monday. function publicHols($yr) { // CALC PUBLIC HOLS FOR $yr $hols = array(); $newyr = "$yr-01-01"; switch (date('w', strtotime($newyr))) { case 6: $newyr = "{$yr}-01-03"; break; case 0: $newyr = "{$yr}-01-02"; break; } $hols['New Year'] = array($newyr,$newyr); $easter = easter_date($yr); $hols['Easter'] = array(date('Y-m-d', strtotime('-2 days', $easter)), date('Y-m-d', strtotime('+1 days', $easter))); $mayday = (new DateTime("first monday of may $yr"))->format('Y-m-d'); $hols['May Day'] = array($mayday,$mayday); $sbank = (new DateTime("last monday of may $yr"))->format('Y-m-d'); $hols['Spring Bank'] = array($sbank,$sbank); $abank = (new DateTime("last monday of august $yr"))->format('Y-m-d'); $hols['August Bank'] = array($abank,$abank); $x1 = "$yr-12-25"; $x2 = "$yr-12-26"; switch (date('w', strtotime($x1))) { case 5: $x2 = "$yr-12-28"; break; case 6: $x1 = "$yr-12-27"; $x2 = "$yr-12-28"; break; case 0: $x1 = "$yr-12-26"; $x2 = "$yr-12-27"; break; } $hols['Christmas'] = array($x1,$x2); return $hols; } function showReminders($yr) { $hols = publicHols($yr); $today = new DateTime(); $today->setTime(0,0); foreach ($hols as $h=>$dates) { $dh = new DateTime($dates[0]); $days = $dh->diff($today)->format('%a days'); if ($dh==$today) { echo "It's $h!<br>"; } elseif ($dh > $today && $days <= 7) { echo $today->format('jS F Y')." reminder, $h in $days<br>"; } } } $year = date('Y'); showReminders($year); showReminders($year+1);
-
Split numbers from '-' delimited list and enter them into an array
Barand replied to bluefrog's topic in PHP Coding Help
Yes, explode() will put the numbers into an array. sort() will put the array in ascending values. Use a foreach() loop to echo the elements in the array. -
If there should only ever be a single record in that table why have an auto_incrementing id why even attempt to insert a new record? Just update the existing one