-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Date arithmetic (and all other MySQL datetime functions, comparisons and sorting) will not work with dates in mm-dd-yyyy format. Don't use varchar for dates, use DATE type fields (format YYYY-MM-DD). Also, if working with just dates, use CURDATE() and not NOW() as the latter contains time element. Unless it is exactly midnight 2013-09-08 doesn't = NOW() You can convert varchar dates to DATE using STR_TO_DATE() but then you need it in every date calculation. edit: If you date is actual birthdate, including year of birth, then it won't be in the range of the next 4 days
-
It could be that the user does not have the privileges to create database Try connecting as that user and SHOW GRANTS
-
Sample of function selection menu <?php function aaa() {echo "You selected function 'aaa'<hr>";} function bbb() {echo "You selected function 'bbb'<hr>";} function ccc() {echo "You selected function 'ccc'<hr>";} if (isset($_GET['choice'])) { $func = $_GET['choice']; // call chosen function $func(); } ?> <form> Choose a function <select name="choice"> <option value="aaa">a</option> <option value="bbb">b</option> <option value="ccc">c</option> </select> <br><br> <input type="submit" value="Submit" name="btnSub"> </form>
-
I ran your code for 2013-10-27 (day UK DST changes) and still got Cursor = 2013-10-27 00:00:00 Cursor = 2013-10-27 00:15:00 Cursor = 2013-10-27 00:30:00 Cursor = 2013-10-27 00:45:00 Cursor = 2013-10-27 01:00:00 Cursor = 2013-10-27 01:15:00 Cursor = 2013-10-27 01:30:00 Cursor = 2013-10-27 01:45:00 Cursor = 2013-10-27 02:00:00 Cursor = 2013-10-27 02:15:00 Cursor = 2013-10-27 02:30:00 Cursor = 2013-10-27 02:45:00 Cursor = 2013-10-27 03:00:00 Cursor = 2013-10-27 03:15:00 Cursor = 2013-10-27 03:30:00 Cursor = 2013-10-27 03:45:00 so that kills the DST theory
-
Change in daylight saving time
-
try $dt = new DateTime("2012-10-07 00:00:00"); $di = new DateInterval('PT15M'); $dp = new DatePeriod($dt, $di, 16); foreach ($dp as $d) { echo $d->format('Y-m-d H:i') . '<br>'; } Output 2012-10-07 00:00 2012-10-07 00:15 2012-10-07 00:30 2012-10-07 00:45 2012-10-07 01:00 2012-10-07 01:15 2012-10-07 01:30 2012-10-07 01:45 2012-10-07 02:00 2012-10-07 02:15 2012-10-07 02:30 2012-10-07 02:45 2012-10-07 03:00 2012-10-07 03:15 2012-10-07 03:30 2012-10-07 03:45 2012-10-07 04:00
-
Quite a short reply for .josh
-
isset() is for checking if a variable has been assigned a value. I don't know what your $html->find() function returns if the string isn't found but that is what you should be checking for. If it returns "false" you can if (!$html->find('blah') { ... }
-
Looks like you need to get $hid from $_POST['id'] when you process the form
-
Create Real Estate Report With Demographics and Maps
Barand replied to bankman3000's topic in PHP Coding Help
- Look at all the business processes that will be required - Look at the data that will be required to support those processes. - Construct a relational data model. - Validate that the model is viable for the processes - Then start coding -
Alternatively, save this version of the query as a VIEW, say "current_version" and use the view instead of the table when required SELECT v.* FROM version v JOIN ( SELECT nidt, noeud, MAX(version) as maxversion FROM version GROUP BY nidt, noeud ) latest USING (nidt, noeud) LEFT JOIN ( SELECT nidt, noeud, MAX(version) as maxoper, 1 AS isoper FROM version WHERE etat_fonct = 'OPERATIONAL' GROUP BY nidt, noeud ) oper USING (nidt, noeud) WHERE (isoper AND (etat_fonct='OPERATIONAL') AND (version = maxoper)) OR (isoper IS NULL AND version = maxversion)
-
use DELETE vtest FROM vtest JOIN ( SELECT nidt, noeud, MAX(version) as maxversion FROM version GROUP BY nidt, noeud ) latest USING (nidt, noeud) LEFT JOIN ( SELECT nidt, noeud, MAX(version) as maxoper, 1 AS isoper FROM version WHERE etat_fonct = 'OPERATIONAL' GROUP BY nidt, noeud ) oper USING (nidt, noeud) WHERE (isoper AND ((etat_fonct<>'OPERATIONAL') OR (version < maxoper))) OR (isoper IS NULL AND version < maxversion)
-
Quote text and date values. Do not quote numeric values. MySQL won't error if you quote numbers but you give it the overhead of converting strings to numeric types.
-
This query should give the records to be deleted from your test data SELECT v.nidt, v.noeud, v.version, v.id FROM version v JOIN ( SELECT nidt, noeud, MAX(version) as maxversion FROM version GROUP BY nidt, noeud ) latest USING (nidt, noeud) LEFT JOIN ( SELECT nidt, noeud, MAX(version) as maxoper, 1 AS isoper FROM version WHERE etat_fonct = 'OPERATIONAL' GROUP BY nidt, noeud ) oper USING (nidt, noeud) WHERE (isoper AND ((etat_fonct<>'OPERATIONAL') OR (version < maxoper))) OR (isoper IS NULL AND version < maxversion) You could write these results to a temporary table then join the version table to that to either DELETE or UPDATE a deleted_flag. Alternatively you could LEFT JOIN to this query (as a subquery) to select the active records. According to the query, these should be deleted: nidt noeud version id 00000001B2 16 11 2 00000001B2 17 11 3 00000001B2 18 10 5 00000001F3 16 11 11
-
PS. your table needs a unique/primary key ALTER TABLE `version` ADD COLUMN `id` INT NOT NULL AUTO_INCREMENT FIRST , ADD PRIMARY KEY (`id`) ;
-
Images of your data are difficult to load into a test table. A dump would be easier.
-
how I make a single query for both insert and update?
Barand replied to thara's topic in PHP Coding Help
In what way? You can insert data into one table that is selected from another. -
how I make a single query for both insert and update?
Barand replied to thara's topic in PHP Coding Help
That looks good - I see you found the VALUES() function needed for multiple updates -
how I make a single query for both insert and update?
Barand replied to thara's topic in PHP Coding Help
And...? -
how I make a single query for both insert and update?
Barand replied to thara's topic in PHP Coding Help
To use ON DUPLICATE KEY you first need a unique key. Userid is not unique so the unique key would need to be (userid, days). Then when you try to add, say, (3, 'Monday') again there would be a duplicate so you can update the time fields -
To compare dates you need the elements of the date in YMD order ie CONCAT(ryear,rmonth,rday). Use MySQL DATE type fields for date storage (format yyyy-mm-dd)
-
Helped you once but you rejected it. Why should I help more?
-
try something like this $db = new mysqli(HOST, USERNAME, PASSWORD, 'test' ); $pid = 5; $sql = "SELECT productName, category_id FROM product WHERE product_id = $pid"; $res = $db->query($sql); list($prod, $catid) = $res->fetch_row(); $trail = array($prod); getBreadcrumbs($catid, &$trail, $db); $trail = array_reverse($trail); echo join(' ยป ', $trail) . '<br>'; function getBreadcrumbs($catid, &$trail, $db) { $sql = "SELECT name, parent, level FROM category WHERE category_id = $catid"; $res = $db->query($sql); if ($res->num_rows > 0) { list($name, $parent, $level) = $res->fetch_row(); $trail[] = $name; if ($level > 1) getBreadcrumbs($parent, $trail, $db); } }
-
I normalized the data into table randomn. id int, seq int ball int then SELECT CONCAT_WS(',', A,B,C) as balls, COUNT(*) as occ FROM ( SELECT a.id, a.ball as A, b.ball as B, c.ball as C FROM randomn a JOIN randomn b ON a.id = b.id AND a.seq < b.seq JOIN randomn c ON c.id = b.id AND b.seq < c.seq ) as X GROUP BY balls ORDER BY occ DESC
-
Ah, at last! Webdev, you have now given us a clue about what you are looking for. That last post (+ sample data) is one you should have made a page back.