-
Posts
24,565 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
If you are submitting form data you can put it in a hidden field, otherwise you can use AJAX call to pass it to the server
-
Note that doing it that way only works for your table with username and email as unique keys and will require separate code for each table with unique keys, whereas maxxd's solution will work with any table
-
You said they should be visible when the page reloads so you know they start off visible. If you need to know the state store it in a JS variable (which would be initially set to "visible") and set to "hidden" when a link is clicked.
-
To use jquery you need the jquery library EG <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> Also PHP has finished by the time the javascript executes so you cannot use php expressions within javascript
-
The function would go in your PHP file with the HTML output, not in phpMyAdmin. example.php: <?php $db = new mysqli(localhost,XXXXXXXX,XXXXXXXXX,XXXXXXXX); function salesmenOptions($db) { $opts = "'<option value=''>- select salesmen -</option>\n"; $sql = "SELECT id, last_name, first_name FROM salesmen ORDER BY last_name"; $res = $db->query($sql); while (list($id, $last_name, $first_name) = $res->fetch_row()) { $opts .= "<option value='$id'>$first_name $last_name </option>\n"; } return $opts; } ?> <html> <head> <title>Example</title> </head> <body> <select name='salesmen'> <?php echo salesmenOptions($db); ?> </select> </body> </html>
-
try getting the error message (or error info) as well as the error code
-
With MySQL the error message will tell you which key. What RDBMS are you using?
-
Then it's time to re-read the early bits of the PHP manual http://php.net/manual/en/language.basic-syntax.php
-
Here's an example for you The data mysql> SELECT * FROM timetest; +----+----------+---------------------+---------------------+ | id | staff_id | start_time | end_time | +----+----------+---------------------+---------------------+ | 1 | 1 | 2015-04-06 08:35:00 | 2015-04-06 17:35:00 | | 2 | 1 | 2015-04-07 08:30:00 | 2015-04-07 17:50:00 | | 3 | 1 | 2015-04-08 09:35:00 | 2015-04-08 17:55:00 | | 4 | 1 | 2015-04-09 08:30:00 | 2015-04-09 17:20:00 | | 5 | 1 | 2015-04-10 08:20:00 | 2015-04-10 17:50:00 | | 6 | 2 | 2015-04-06 08:15:00 | 2015-04-06 18:10:00 | | 7 | 2 | 2015-04-07 08:25:00 | 2015-04-07 18:50:00 | | 8 | 2 | 2015-04-08 08:30:00 | 2015-04-08 17:20:00 | | 9 | 2 | 2015-04-09 08:10:00 | 2015-04-09 17:00:00 | | 10 | 2 | 2015-04-10 08:00:00 | 2015-04-10 17:00:00 | +----+----------+---------------------+---------------------+ The query to total the times SELECT staff_id , DATE(start_time) , SEC_TO_TIME(SUM(TIMESTAMPDIFF(SECOND, start_time, end_time))) as tot FROM timetest GROUP BY staff_id, DATE(start_time) WITH ROLLUP; The results +----------+------------------+----------+ | staff_id | DATE(start_time) | tot | +----------+------------------+----------+ | 1 | 2015-04-06 | 09:00:00 | | 1 | 2015-04-07 | 09:20:00 | | 1 | 2015-04-08 | 08:20:00 | | 1 | 2015-04-09 | 08:50:00 | | 1 | 2015-04-10 | 09:30:00 | | 1 | NULL | 45:00:00 | <- TOTAL FOR staff 1 | 2 | 2015-04-06 | 09:55:00 | | 2 | 2015-04-07 | 10:25:00 | | 2 | 2015-04-08 | 08:50:00 | | 2 | 2015-04-09 | 08:50:00 | | 2 | 2015-04-10 | 09:00:00 | | 2 | NULL | 47:00:00 | <- TOTAL FOR staff 2 | NULL | NULL | 92:00:00 | <- GRAND TOTAL +----------+------------------+----------+
-
you don't want the the : after case: and you dont need those internal {..}s switch ($_GET['page']) { case 'home': echo "<center><h1>Home Page</h1></center>"; break; case 'Language': echo "<center><h1>LanguagePage</h1></center>"; break; }
-
user login - if user =xxx then login to table xxx
Barand replied to Grumps's topic in PHP Coding Help
You don't even need to reconnect to query another database - the connection is to the server. -
I am assuming you have a table of materials. EG +----------------------+ | id | material | +----+-----------------+ | 1 | wool | | 2 | steel | | 3 | paper | +----+-----------------+ Create a function to build the options from the table $db = new mysqli(HOST,USERNAME,PASSWORD,DATABASE); function materialOptions($db) { $opts = "'<option value=''>- select material -</option>\n"; $sql = "SELECT id, material FROM material ORDER BY material"; $res = $db->query($sql); while (list($id, $mat) = $res->fetch_row()) { $opts .= "<option value='$id'>$mat</option>\n"; } return $opts; } Then <html> <body> <select name='material'> <?php echo materialOptions($db); ?> </select> </body> </html>
-
Sounds like you need an UPDATE query UPDATE users SET trial_date_ended = 'expired' WHERE trial_date_started < CURDATE() - INTERVAL 30 DAY
-
try SELECT DISTINCT s.store_id , s.zip_code FROM store s INNER JOIN merchandise m1 ON s.store_id = m1.storeID AND m1.description = 'clock' INNER JOIN merchandise m2 ON s.store_id = m2.storeID AND m2.description = 'paper' INNER JOIN merchandise m3 ON s.store_id = m3.storeID AND m3.description = 'food'
-
Relational theory says it is necessary - the only things that should appear in multiple records are ids (keys). The shop table saves you from repeating the shop name in thousands of records. Does this work for you? UPDATE babyfoontest JOIN ( SELECT minprice.eancode as ean , webshop.price , webshop.producturl , webshop.shopnaam FROM webshop INNER JOIN ( SELECT eancode , MIN(price) as price FROM webshop GROUP BY eancode ) as minprice USING (eancode,price) ) wsrec USING (ean) SET babyfoontest.prijs = wsrec.price , babyfoontest.deeplink = wsrec.producturl; WHERE wsrec.shopnaam = 'babypark'
-
I would set it up as shown below. Then with "... WHERE cat_name = 'television' ..." you automatically include all webshop records for shops that sell televisions.
-
If there are over a 1m records then there's going to be a lot of shops. If you use the shop names in the WHERE clause, how can you be sure you include all the shops that sell televisions? Also, by doing it the way you propose, you are are going to process every product that those shops sell - not just televisions but mouse-mats, dvds, microwaves etc
-
Sorry, Gizmola, but going to have to argue with you over that one. 1. print returns a value (always 1), echo does not (void function) 2. echo will accept multiple arguments whereas with print you have to use concatenation eg echo 'Today is ', date('Y-m-d'); // multi args works print 'Today is ', date('Y-m-d'); // multi args - error print 'Today is '. date('Y-m-d'); // concatenation works
-
If you are, for example, only interested in televisions then surely this is an attribute of the product (product type or product category) and not of the shop
-
Your WHERE clause is in the wrong place. It should be UPDATE ... SET ... WHERE ... (http://dev.mysql.com/doc/refman/5.6/en/update.html) You are now completely changing the nature of the query. You originally wanted the minimum price but your WHERE clause will update with the price and url from the babyfarm records, which isn't necessarily the same thing. What are you really trying to achieve?
-
In that case the url belongs in the webshop table. The sql gets a bit more complicated though and needs an extra step. We currently have a subquery to find the min price for each product. We now need to use that to match against the webshop table to find the record for that ean that matches the min price and get the url from that record. So your update would now be UPDATE babyfoontest JOIN ( SELECT minprice.eancode as ean , webshop.price , webshop.producturl FROM webshop INNER JOIN ( SELECT eancode , MIN(price) as price FROM webshop GROUP BY eancode ) as minprice USING (eancode,price) ) wsrec USING (ean) SET babyfoontest.prijs = wsrec.price , babyfoontest.deeplink = wsrec.producturl;
-
That wasn't quite the question regarding urls If product X is sold in 100 different shops, will all those 100 records have the same url? (if the answer is yes then the url should be in the product table and not the shop table)
-
Given a fairly large table mysql> SELECT COUNT(*) FROM test.votes; +----------+ | COUNT(*) | +----------+ | 182685 | +----------+ Finding the the min value for a particular type takes 0.03 seconds mysql> SELECT type, MIN(votes) -> FROM test.votes -> WHERE type = 9 -> GROUP BY type; +------+------------+ | type | MIN(votes) | +------+------------+ | 9 | 50 | +------+------------+ 1 row in set (0.03 sec) + + + Regarding the producturl, do all records for ean=X in webshop have the same url or can it vary from shop to shop?
-
try UPDATE babyfoontest JOIN ( SELECT eancode as ean , MIN(price) as price FROM webshop GROUP BY ean ) as minprice USING (ean) SET babyfoontest.prijs = minprice.price; If the product is always the min webshop price then don't store it in the product table, get it when you need it in a query. Also typenummer should be in only one table, probably product.