-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Then include that condition in your WHERE clause WHERE (sales.sales_date BETWEEN ? AND ?) AND products.product_id BETWEEN 50 AND 56
-
Your post yesterday said you had given up - feel free.
-
Of course it showed TVs in each category - that's what you selected. Why is that wrong? - - - I would advise you add a category table and store the catgory id in the product records and not repeat the name in every product of that type. +-------------+ +-----------------+ | product | | category | +-------------+ +-----------------+ | id | +----| id | | name | | | cat_name | | cat_id |>--+ | cat_image | | code | | cat_price | | price | +-----------------+ | image | +-------------+
- 1 reply
-
- 1
-
Php and javascript with timestamp and countdown
Barand replied to PNewCode's topic in PHP Coding Help
Fixed -
Php and javascript with timestamp and countdown
Barand replied to PNewCode's topic in PHP Coding Help
No. Don't store derived data. If you have the start and duration then the finish is known . EG to find next, or current, auction SELECT id , start_time as start , duration , addtime(start_time, duration) as finish FROM auction WHERE addtime(start_time, duration) > NOW() order by start_time LIMIT 1; -
Php and javascript with timestamp and countdown
Barand replied to PNewCode's topic in PHP Coding Help
Keep it simple for the user with datetime and time input fields <form method='POST'> <label for='start'>Auction Start</label> <input type='datetime-local' name='start' id='start'> <br> <label for='duration'>Duration</label> <input type='time' name='duration' id='duration'> <br><br> <input type='submit'> </form> Store these values in your auction table CREATE TABLE `auction` ( +----+---------------------+----------+ `id` int(11) NOT NULL AUTO_INCREMENT, | id | start_time | duration | `start_time` datetime DEFAULT NULL, +----+---------------------+----------+ `duration` time DEFAULT NULL, | 1 | 2023-07-17 15:00:00 | 02:30:00 | PRIMARY KEY (`id`) | 2 | 2023-07-18 12:00:00 | 03:00:00 | ) ENGINE=InnoDB;</body> +----+---------------------+----------+ When you want the auction end time for your countdown, query the database and use sql's addtime() function... SELECT id , start_time as start , duration , addtime(start_time, duration) as finish FROM auction; +----+---------------------+----------+---------------------+ | id | start | duration | finish | +----+---------------------+----------+---------------------+ | 1 | 2023-07-17 15:00:00 | 02:30:00 | 2023-07-17 17:30:00 | | 2 | 2023-07-18 12:00:00 | 03:00:00 | 2023-07-18 15:00:00 | +----+---------------------+----------+---------------------+ -
Php and javascript with timestamp and countdown
Barand replied to PNewCode's topic in PHP Coding Help
Because you put the $duration inside single quotes it is treating it as the string literal "$duration" and not "+30 minute". EG $duration = '+30 minute'; echo '$duration' . '<br>'; echo $duration . '<br>'; gives $duration +30 minute -
php array format from the mysqli_fetch_assoc rows
Barand replied to amirelgohary1990's topic in PHP Coding Help
You have a situation where a job can have many categories and a category can contain many jobs; a many-to-many relationship. These a resolved by an intermediate table. Your data model should like this ... +-------------+ +-----------------+ | job | | category | +-------------+ +--------------------+ +-----------------+ | id |---+ | job_category | +-----| id | | job_title | | +--------------------+ | | cat_description | +-------------+ | | id | | +-----------------+ +---<| job_id | | | category_id |>---+ +--------------------+ so that where you now the equivalent of this for your job table, +--------+--------------+ | job_id | category_id | +--------+--------------+ | 3 | 2, 4, 5 | | 4 | 1, 2 | +--------+--------------+ you would have a job_category table like this +----+--------+--------------+ | id | job_id | category_id | +----+--------+--------------+ | 1 | 3 | 2 | | 2 | 3 | 4 | | 3 | 3 | 5 | | 4 | 4 | 1 | | 5 | 4 | 2 | +----+--------+--------------+ Now it's a simple to find which jobs are in a particular category as it is to find which categories a job belongs to. -
php array format from the mysqli_fetch_assoc rows
Barand replied to amirelgohary1990's topic in PHP Coding Help
The understatement of the year - it's terrible. -
I'd do a print_r($_POST) when the post data is received to check what is being posted. (comment out the header() line so you see the array output)
-
php array format from the mysqli_fetch_assoc rows
Barand replied to amirelgohary1990's topic in PHP Coding Help
If you are storing serialized, base64encoded lists of ids in a column in a relational database table then you are on your own. Come back when you have correctly normalized data. -
Php and javascript with timestamp and countdown
Barand replied to PNewCode's topic in PHP Coding Help
Does this thread help? ... -
-
Is that an assigned table design or are you able to make your own changes? I ask because it is need of some normalization... you have repeating data in the days column. you have dependent data (the dayplate is derived from the days). it would be better to store 2 time columns (start and end) instead of the timeplate to make it easier to determine, say, "show streets where there is a restriction at 8:30am." ie WHERE 08:30 BETWEEN start AND end
-
If we start with this data currentyeardata (targets) tiv_data (actuals) +----+-----------+----------+-------+ +----+-----------+----------+-------+----------+ | id | category | dealerid | total | | id | category | dealerid | brand | quantity | +----+-----------+----------+-------+ +----+-----------+----------+-------+----------+ | 1 | EXCAVATOR | 81019218 | 100 | | 1 | EXCAVATOR | 81019218 | XCMG | 25 | | 2 | GRADER | 81019218 | 150 | | 2 | GRADER | 81019218 | XCMG | 50 | +----+-----------+----------+-------+ +----+-----------+----------+-------+----------+ then run your query SELECT tiv.Category , sum(tiv.Quantity) AS Actual , sum(cyd.Total) AS Target FROM currentyeardata cyd Inner join tiv_data tiv ON tiv.Dealerid = cyd.DealerID WHERE tiv.Dealerid = '81019218' AND tiv.Brand = 'XCMG' GROUP BY tiv.Category ORDER BY Actual ASC; +-----------+--------+--------+ | Category | Actual | Target | +-----------+--------+--------+ | EXCAVATOR | 50 | 250 | | GRADER | 100 | 250 | +-----------+--------+--------+ These are obviousy wrong, as you are experiencing. Let's look at the actual rows that query selects without the grouping/aggregations but using your join SELECT * FROM currentyeardata cyd Inner join tiv_data tiv ON tiv.Dealerid = cyd.DealerID WHERE tiv.Dealerid = '81019218' AND tiv.Brand = 'XCMG'; +----+-----------+----------+-------+----+-----------+----------+-------+----------+ | id | category | dealerid | total | id | category | dealerid | brand | quantity | +----+-----------+----------+-------+----+-----------+----------+-------+----------+ | 1 | EXCAVATOR | 81019218 | 100 | 1 | EXCAVATOR | 81019218 | XCMG | 25 | | 1 | EXCAVATOR | 81019218 | 100 | 2 | GRADER | 81019218 | XCMG | 50 | | 2 | GRADER | 81019218 | 150 | 1 | EXCAVATOR | 81019218 | XCMG | 25 | | 2 | GRADER | 81019218 | 150 | 2 | GRADER | 81019218 | XCMG | 50 | +----+-----------+----------+-------+----+-----------+----------+-------+----------+ Beacuse you join on dealerid, each target record joins with two actual records so you are totalling twice as many records as you expected. You need to join on category and dealerid... SELECT tiv.Category , sum(tiv.Quantity) AS Actual , sum(cyd.Total) AS Target FROM currentyeardata cyd Inner join tiv_data tiv USING (category, dealerid) -- REVISED JOIN WHERE tiv.Dealerid = '81019218' AND tiv.Brand = 'XCMG' GROUP BY tiv.Category ORDER BY Actual ASC; +-----------+--------+--------+ | Category | Actual | Target | +-----------+--------+--------+ | EXCAVATOR | 25 | 100 | | GRADER | 50 | 150 | +-----------+--------+--------+
-
Alternatively <?php $result = $conn->query("SELECT * FROM animals "); ?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html" charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Sample</title> <style type='text/css'> label { padding: 4px; width: 120px; display: inline-block; background-color: #ccc; border: 1px solid white; margin-right: 10px; font-variant: small-caps; } </style> </head> <body> <?php foreach ($result as $row) { foreach ($row as $k => $v) { echo "<label>" . ucwords( str_replace('_', ' ', $k) ) . "</label>$v<br>"; } echo '<hr>'; } ?> </body> </html> test table... +----+-------------+--------------+--------+-------------+ | id | animal_type | animal_breed | colour | owner_name | +----+-------------+--------------+--------+-------------+ | 1 | Cat | Persian | white | Lucy Lastik | | 2 | Dog | Labrador | black | Scott Chegg | +----+-------------+--------------+--------+-------------+ results...
-
Issue generating student class position based on the grand exam score
Barand replied to Royal's topic in PHP Coding Help
Here's one way $student_scores = [ [ 'name' => 'Student A', 'score' => 68, 'pos' => '' ], [ 'name' => 'Student B', 'score' => 52, 'pos' => '' ], [ 'name' => 'Student C', 'score' => 73, 'pos' => '' ], [ 'name' => 'Student D', 'score' => 80, 'pos' => '' ], [ 'name' => 'Student E', 'score' => 56, 'pos' => '' ], [ 'name' => 'Student F', 'score' => 77, 'pos' => '' ], [ 'name' => 'Student G', 'score' => 73, 'pos' => '' ], [ 'name' => 'Student H', 'score' => 49, 'pos' => '' ], [ 'name' => 'Student I', 'score' => 88, 'pos' => '' ], [ 'name' => 'Student J', 'score' => 90, 'pos' => '' ] ]; $scores = array_column($student_scores, 'score'); rsort($scores); foreach ($student_scores as &$s) { $s['pos'] = array_search($s['score'], $scores) + 1; } // sort scores by position uasort($student_scores, fn($a, $b) => $a['pos']<=> $b['pos']); // show results echo '<pre>' . print_r($student_scores, 1) . '</pre>'; giving Array ( [9] => Array ( [name] => Student J [score] => 90 [pos] => 1 ) [8] => Array ( [name] => Student I [score] => 88 [pos] => 2 ) [3] => Array ( [name] => Student D [score] => 80 [pos] => 3 ) [5] => Array ( [name] => Student F [score] => 77 [pos] => 4 ) [2] => Array ( [name] => Student C [score] => 73 [pos] => 5 ) [6] => Array ( [name] => Student G [score] => 73 [pos] => 5 ) [0] => Array ( [name] => Student A [score] => 68 [pos] => 7 ) [4] => Array ( [name] => Student E [score] => 56 [pos] => 8 ) [1] => Array ( [name] => Student B [score] => 52 [pos] => 9 ) [7] => Array ( [name] => Student H [score] => 49 [pos] => 10 ) )- 1 reply
-
- 1
-
Not according to that code... if (trim($option_second) == "") { echo ""; } else { echo "<strong>Option:</strong> $option_second"; }
-
If you remove the SELECT and GROUP BY clauses from your original query and just SELECT salesdetails.*, giving something like this SELECT salesdetails.* FROM `sales` JOIN salesdetails ON salesdetails.salesdetails_salesticketnr = sales.sales_ticketnr JOIN products ON products.product_id IN (51,55) WHERE salesdetails.salesdetails_productid IN (51,55) AND sales.sales_date BETWEEN ? AND ? ... it will list the actual details records that are being processed in the query - some probably more than you expected because of the wrong join.
-
Your query evidently isn't processing the records you think it should. Check.
-
If you want to hide them, why include them in the query in the first place?
-
Oooh! thanks. Christmas in July.
-
if (expression) return true else return false is equivalent to return expression
-
Your second function needs to return $result, but all you need is function emptyInputSignup($name,$email,$username,$pwd,$pwdRepeat) { return empty($name) || empty($email) || empty($username) || empty($pwd) || empty($pwdRepeat); } function invalidUid($username) { return !preg_match("/^[a-zA-Z0-9]*$/", $username) ; } It never was.