-
Posts
24,573 -
Joined
-
Last visited
-
Days Won
824
Everything posted by Barand
-
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
-
So what are the ids of the records now in your table?
-
Did you already have a record with an id of "1"? The id would be the id of the record to be updated, not 1 every time.
-
You aren't inserting the id into the new record so you are not attempting to create a duplicate
-
-
Your date format is invalid for storing in a database table, it needs converting to YYYY-mm-DD. Numeric values cannot contain "£".
-
Whenever you have column names like room_type_1, room_type_2, ..., room_type_N, the database design is wrong. Database tables are not spreadsheets. You should normalize the data so each of those room_type values is in a row of its own. (See attached model.). Don't use SELECT *. Specify just the column you need. Use explicit join syntax instead of putting the join conditions in the WHERE clause. Using the attached model, the query you want would be SELECT h.hotel_num , h.name , SUM(hi.qty) as rooms FROM hotel h INNER JOIN event_hotels eh ON h.hotel_num = eh.hotel_num INNER JOIN hotels_inventory hi ON h.hotel_num = hi.hotel_num WHERE eh.event_num = 78 AND hi.inv_date BETWEEN '2015-12-01' and '2015-12-31' GROUP BY h.hotel_num ORDER BY rooms DESC;
-
You can calculate the distance in the query and then ORDER BY distance