-
Posts
24,573 -
Joined
-
Last visited
-
Days Won
824
Everything posted by Barand
-
try SELECT mname , @tot := @tot + opened - closed as open_at_end FROM ( SELECT MONTH(change_date) as mth , MONTHNAME(change_date) as mname , SUM(status='Open') as opened , SUM(status='Closed') as closed FROM project_status WHERE QUARTER(change_date) = 1 GROUP BY mth ) totals JOIN (SELECT @tot:=0) as init
-
At what point in the script are inserting the F word? Because $game is reset to Dragonball3 when you execute the findOrFail() method above.
-
I suspect that some of your rows are duplicated because of the joins
-
Basically, instead of $num = 43; echo $num; // --> 43 you would use $num = 43; echo "<img src='/path/$num.jpg'>"; // --> outputs image 43.jpg
-
It will improve the appearance if you make it wide enough for a character and center the text <div style="width:10px; text-align:center;">C L A S S</div>
-
$word = 'CLASS'; echo join('<br>', str_split($word));
-
The logic flow seems all over the place. Try something like this if ($_SERVER['REQUEST_METHOD'] == 'POST') { // was data posted? if (empty($_POST['id'])) { // insert record } else { // update that record } } if (isset($_GET['id']) && !empty($_GET['id'])) { // get data from table and display in form for edit } else { // display blank form for new record }
-
session_start() needs be called before any output is sent to the browser. You are currently sending the form fields first. Move the php code above the form code. You are attempting to use the content of $_POST['mail'] and $_POST['pass'] before you check if any data was POSTed. You only retrieve a single record with the query, so why is there a while() loop? When you use header() to redirect, there should be an exit; command following it to prevent the rest of the script from being executed. Use password_hash() and password_verify()
-
Functions with identical names - how to call them.
Barand replied to enveetee's topic in PHP Coding Help
Why namespaces? Each script has its own scope, so if you call it with, say DoThis('Hello world'); then it will call the version that is defined in the same script -
Getting statistics from 3 different tables using foreign keys
Barand replied to blmg2009's topic in MySQL Help
The results for questions 2, 3 and 4 can be got from a single query SELECT m.gender, COUNT(*) as total FROM teams_info ti LEFT JOIN team_players tp ON ti.team_id = tp.team_id LEFT JOIN members m ON tp.members_id = m.members_id WHERE ti.entry_year = 2015 GROUP BY gender WITH ROLLUP ; +--------+-------+ | gender | total | +--------+-------+ | female | 3 | | male | 4 | | NULL | 7 | <--- ROLLUP gives the total of the subtotals +--------+-------+ 3 rows in set (0.00 sec) -
When you first generate the page, populate the first menu. Then use the onchange event to generate an ajax call, passing the selected state. The script on the server will then query the database for counties in that state and pass them back as an array. Use that array to populate the second menu.
-
Getting statistics from 3 different tables using foreign keys
Barand replied to blmg2009's topic in MySQL Help
try SELECT COUNT(*) as accepted FROM team_players tp JOIN teams_info ti USING (team_id) WHERE ti.entry_year = 2015 AND tp.status = 1; +----------+ | accepted | +----------+ | 4 | +----------+ 1 row in set (0.00 sec) -
Getting statistics from 3 different tables using foreign keys
Barand replied to blmg2009's topic in MySQL Help
First, look at the PRIMARY KEY/FOREIGN KEY relationships +------------+ +------------+ | teams_info | | members | +------------+ +------------+ | team_id |------+ +-------| members_id | | team_name | | | | first_name | | entry_year | | | | surname | | status | | | | gender | +------------+ | | +------------+ | | | | | +--------------+ | | | team_players | | | +--------------+ | | | player_id | | +----<| team_id | | | status | | | members_id |>-----+ | position | +--------------+ Those will be the JOINS in your queries, for example FROM teams_info JOIN team_players USING (team_id) So start by looking at the fields you need in your result and which tables you need to get those fields. SELECT fields, needed FROM tables needed Then look at the conditions imposed and put those in a WHERE clause SELECT fields, needed FROM tables needed WHERE conditions If you can get it to list the correct records, you are on your way. You can then worry about how to count them. -
Why are there two $conn = xxx ? (Line 4 and line 71) Do you need to connect to two servers in the same script?
-
That's the theory. Whatever the current month is, you will get the total for that month.
-
Of course you don't (unless you want "February" output every time). That is what is known as "an example". Strangely, the writers of the MySQL manual did not know that your date field would be "exrdate", so you need to substitute that yourself. SELECT MONTHNAME(exrdate) as month, .... then you would output it with " $row['month'] "
-
Yes, SQL has a MONTHNAME() function http://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html
-
... WHERE MONTH(exrdate) = MONTH(CURDATE()) AND YEAR(exrdate) = YEAR(CURDATE())
-
exrdate is not a function. SELECT SUM(job_cost) as job_cost, SUM(profit) as profit FROM repairs WHERE exrdate >= CURDATE() - INTERVAL 1 MONTH
-
You need two separate SUM()s SELECT SUM(job_cost) as job_cost, SUM(profit) as profit .....
-
Retrieving Birthday from database MySQL php problem
Barand replied to cobusbo's topic in PHP Coding Help
That will only get those who were born today, not whose birthday falls today. SELECT username , pdob , YEAR(CURDATE())-YEAR(pdob) as age FROM table WHERE MONTH(pdob)=MONTH(CURDATE()) AND DAY(pdob)=DAY(CURDATE()) -
Insert multiple rows in mysqli prepared statement
Barand replied to thara's topic in PHP Coding Help
then $beneficiary = 123; // or whatever $bank_data = array ( array($branchId1 , $acc1), array($branchId2 , $acc2) ); $sql = "INSERT INTO user_bank (beneficiary_id, branch_id, account VALUES (?,?,?))"; $stmt = $db->prepare($sql); $stmt->bind_param('ii', $benficiary,$branch, $acc); foreach ($bank_data as $bdata) { list($branch, $acc) = $bdata; $stmt->execute(); } -
Insert multiple rows in mysqli prepared statement
Barand replied to thara's topic in PHP Coding Help
If your bank_branch table stores the bank_id then you don't need it in user_bank table. -
Insert multiple rows in mysqli prepared statement
Barand replied to thara's topic in PHP Coding Help
When using prepared statements in a situation like this you define query, prepare and bind parameters once only. After doing that, loop through the data values to set the parameters and execute. $beneficiary = 123; // or whatever $bank_data = array ( $branchId1 , $branchId2 ); $sql = "INSERT INTO user_bank (beneficiary_id, branch_id VALUES (?,?))"; $stmt = $db->prepare($sql); $stmt->bind_param('ii', $benficiary, $branch); foreach ($bank_data as $branch) { $stmt->execute(); }