-
Posts
24,573 -
Joined
-
Last visited
-
Days Won
824
Everything posted by Barand
-
alter table add column ... like this other column over here?
Barand replied to fatkatie's topic in MySQL Help
You can create a table which has exactly the same structure as another CREATE TABLE table2 LIKE table1; I know of nothing similar down at the ADD COLUMN level. -
Sorry, careless with my column aliases Try SELECT DATE(payments.date) as dateportion , users.username , COUNT(*) as tot from payments INNER JOIN users ON payments.user_id = users.id WHERE payments.membership_id IN (6,7) GROUP BY payments.user_id, dateportion HAVING tot > 1
-
Work with just the date parts of the fields using DATE(payments.date) SELECT DATE(date) as date , userid , COUNT(*) as tot FROM payments GROUP BY user_id, date HAVING tot > 1
-
try $results = array( array("SALE_ID"=>"1","SALE_DATE"=>"2017-01-01"), array("SALE_ID"=>"2","SALE_DATE"=>"2017-02-15"), array("SALE_ID"=>"3","SALE_DATE"=>"2017-03-25"), array("SALE_ID"=>"4","SALE_DATE"=>"2017-04-10"), array("SALE_ID"=>"5","SALE_DATE"=>"2017-01-08"), array("SALE_ID"=>"6","SALE_DATE"=>"2017-02-23"), array("SALE_ID"=>"7","SALE_DATE"=>"2017-03-15"), array("SALE_ID"=>"8","SALE_DATE"=>"2017-04-09") ); $results_by_week = []; foreach ($results as $sale) { $w = week_number($sale['SALE_DATE']); $results_by_week[$w][] = (object)$sale; } ksort($results_by_week);
-
Are you sure that is the same form - the hidden fields you originally posted are text fields in that form?
-
edit row if hashtag field already exists with the varible
Barand replied to dropfaith's topic in PHP Coding Help
reverse the array first (array_reverse()) -
edit row if hashtag field already exists with the varible
Barand replied to dropfaith's topic in PHP Coding Help
try removing the (..)s from around the insert statement. -
You only show part of the html for the form. What is the whole form code?
-
Have you tried doing a var_dump($_POST) to check that the custname isn't null?
-
Your query has five columns with five parameters - so why nine placeholders for those parameters?
-
edit row if hashtag field already exists with the varible
Barand replied to dropfaith's topic in PHP Coding Help
Put unique key on hashtag column. CREATE TABLE `hashtag` ( `hashtag_id` int(11) NOT NULL AUTO_INCREMENT, `hashtag` varchar(45) DEFAULT NULL, `link` varchar(45) DEFAULT NULL, PRIMARY KEY (`hashtag_id`), UNIQUE KEY `idx_hashtag_hashtag` (`hashtag`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; mysql> insert into hashtag (hashtag, link) VALUES -> ('abc', 'xyz'), -> ('bcd', 'stu'); Query OK, 2 rows affected (0.05 sec) mysql> select * from hashtag; +------------+---------+------+ | hashtag_id | hashtag | link | +------------+---------+------+ | 1 | abc | xyz | | 2 | bcd | stu | +------------+---------+------+ 2 rows in set (0.00 sec) Instead of querying to see if it exists then doing a second query to update, do it in one query using "INSERT .. ON DUPLICATE KEY" mysql> INSERT INTO hashtag (hashtag, link) VALUES ('abc', 'def') -> ON DUPLICATE KEY UPDATE link = values(link); Query OK, 2 rows affected (0.06 sec) mysql> select * from hashtag; +------------+---------+------+ | hashtag_id | hashtag | link | +------------+---------+------+ | 1 | abc | def | | 2 | bcd | stu | +------------+---------+------+ 2 rows in set (0.00 sec) -
Categories and subcategories array and dynamic dropdown list
Barand replied to z4z07's topic in PHP Coding Help
When the first category menu changes, send an AJAX request with the selected category id. On the server, on receipt of the request, retrieve from the database those categories whose parent is the received id. Send back the options required to populate the second category menu. Repeat the process with the second menu to retrieve the options for the third. -
You need a WHERE clause in the cart update query so you can specify the correct cart and product within that cart UPDATE ...SET ... WHERE ...
-
Using your current method (but with arrays and PDO) it becomes $databases = [ 'database1', 'database2', 'database3', 'database4', 'database5' ]; $baseSQL = "SELECT FirstName, LastName, Email, Mobile, PromoCode FROM <DB>.tablename WHERE (Email LIKE ?) OR (Mobile LIKE ?) OR (PromoCode LIKE ?) "; $queries = []; $params = []; $srch = isset($_GET['search']) ? '%' . $_GET['search'] . '%' : '%'; foreach ($databases as $dbname) { $queries[] = str_replace('<DB>', $dbname, $baseSQL ); array_push($params, $srch, $srch, $srch); } $sql = join("\nUNION\n", $queries); // build set of UNION queries /********** DEBUG ONLY _ DISPLAY QUERY **************/ echo '<pre>', $sql, '</pre>'; /****************************************************/ $stmt = $db->prepare($sql); $stmt->execute($params);
-
Why are you messing around with string concatenation and then worrying about removing trailing commas or UNION keywords. Use arrays with join(). You will also find it a lot simpler with PDO. Its parameter binding is far more streamlined.
-
I use SQL variables to save repetition of bound parameters. For example $sql = "SELECT FirstName, LastName, Email, Mobile, PromoCode FROM <database1>.<table> JOIN (@srch := ?) init_var WHERE (Email LIKE @srch) OR (Mobile LIKE @srch) OR (PromoCode LIKE @srch) UNION SELECT FirstName, LastName, Email, Mobile, PromoCode FROM <database2>.<table> WHERE (Email LIKE @srch) OR (Mobile LIKE @srch) OR (PromoCode LIKE @srch) UNION SELECT FirstName, LastName, Email, Mobile, PromoCode FROM <database3>.<table> WHERE (Email LIKE @srch) OR (Mobile LIKE @srch) OR (PromoCode LIKE @srch) "; $stmt = $db->prepare($sql); $search = '%xxx%'; $stmt->bind_param('s', $search); Note the first has a subquery to set the varaible value to the param value.
-
1 ) No one has mentioned a LEFT join. 2 ) If you read the replies you would see that taquitosensei spoonfed you the solution (reply #3)
-
I chose June for a test month as it was the first one I found with 5 Fridays.
-
That's what I said.
-
->d gives the number of days left after the months have been calculated ->days gives the total days difference EG $startdate = new DateTime('2017-01-01'); $enddate = new dateTime(); // today // output difference in months and days $months = $enddate->diff($startdate)->m; $days = $enddate->diff($startdate)->d; echo "$months months $days days<br>"; // 1 months 20 days // output difference in days only $days = $enddate->diff($startdate)->days; // 51 days echo "$days days";
-
You need to convert the database datetime field to a PHP DateTime object $dtobj = new DateTime($dbdatetime);
-
I think you need $diff->days and not $diff->d
-
Each hashtag should be in its own row in a separate table (google database normalization)
-
The algorithm seems to break down in June June 2017 Su Mo Tu We Th Fr Sa -------------------- 1 2 2 2 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 5 5 5 1 1 1 1 1
-
Sounds like you want a cartesian join (cross join). What have you tried so far?