-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
sending form results to a file to use the file include latter how pls?
Barand replied to Baxt01's topic in PHP Coding Help
Check your spellings for the database and the table names, In my experience if an error message says something doesn't exist then it doesn't. -
So are you saying that if the team id is 1 then this query works? SELECT title, link, description FROM ( 1 )
-
Just use the arithmetic, no string concatenation required. Try it out for yourself - rocket science it ain't $b = 5; // hours $c = .25; // mins $a = $b + $c; // add them echo $a; // see the result --> 5.25
-
PHP Syntax $a = $b + $c; http://www.php.net/manual/en/language.operators.arithmetic.php
-
The value passed for 15 mins is 0.25 so you can just add the the values together (5 + 0.25 = 5.25)
-
Also - you should put "exit;" after your header() call to stop the rest of the script executing. - instead of SELECT then INSERT or UPDATE (if exists) you can use a single query provided invoice_no is defined as unique INSERT INTO invoices (invoice_no, foo) VALUES ($invoice_no, $bar) ON DUPLICATE KEY UPDATE foo = $bar
-
$datar = fread($handler,filesize($my_filer)); fclose($handler); if ($data == 1)
-
Running MySQL Query with Union (2 SELECT) on PHP
Barand replied to cary1234's topic in PHP Coding Help
You have at least one syntax error - a missing "=" at the end of the first half of the query. Check the value of mysqli_error() after running the query. -
The simplest model would be something like this +------------+ +---------------+ +-------------+ | user | | user_schedule | | meeting | +------------+ +---------------+ +-------------+ | user_id |----+ | id | +----| meeting_id | | firstname | +----<| user_id | | | meeting_date| | lastname | | meeting_id |>--+ | description | | birthdate | | present | +-------------+ | address | +---------------+ +------------+ Schedule would be those users invited to a meeting. It would be simple to then construct a form listing invitees for a meeting and check boxes to indicate who attended. Don't store users' age. That can be calculated from birth date when required.
-
j0nnie, LIMIT 1 and LIMIT 0,1 are identical. It is more likely that $subject_id has no value but as the OP refuses to echo $query to verify then who knows. My view is that when more info (like echo $query) is requested but the OP can't be bothered then the only thing to do is walk away.
-
HoF, you're not an OOP Prior are you, complete with a big stick topped with a glowing orb and everything?
-
if inputs are always in pairs foreach ($_POST['d'] as $k => $d) { $q = $_POST['q'][$k]; // insert $d and $q into db table }
-
Check mysql_error() after the insert
-
No data so untested, try 1. SELECT username FROM users u INNER JOIN attendances a USING (userID) LEFT JOIN courses c ON a.courseID = c.courseID AND TeacherID = ? WHERE c.courseID IS NULL 2. SELECT username FROM users u INNER JOIN attendances a USING (userID) LEFT JOIN courses c ON a.courseID = c.courseID AND TeacherID = ? AND courseDate > CURDATE() - INTERVAL 6 MONTH WHERE c.courseID IS NULL
-
Perversely, you can use update syntax as an alternative to normal insert syntax but not vice versa
-
Looks like you need a date column in the attendance records, or are you just using course dates for the final requirement?
-
If the "all" option for Tipo is selected you need to leave it out of the query otherwise you are looking for tipo='' instead of all values
-
Would work for single-date gaps but wouldn't give all missing dates for larger gaps. This would $db = new mysqli(HOST, USERNAME, PASSWORD, DATABASE ); $sql = "SELECT thedate FROM dates"; $res = $db->query($sql); // first date record $row = $res->fetch_row(); $prevdate = new DateTime($row[0]); echo $prevdate->format('Y-m-d').'<br>'; // rest of dates in table while ($row = $res->fetch_row()) { $dt = new DateTime($row[0]); if ($dt->diff($prevdate)->days > 1) { while ($prevdate->modify('+1 day') < $dt) { echo '<strong>' . $prevdate->format('Y-m-d').' -- missing</strong><br>'; } } echo $dt->format('Y-m-d')."<br>"; $prevdate = $dt; }
-
You shouldn't have those dates in a database table, you should have these dates in DATE type fields (format yyyy-mm-dd): 2013-09-03 2013-09-05 2013-09-06 2013-09-09 Query the dates in the table ordered by date (which you can do if you use yyyy-mm-dd) and as you read each date compare with the previous date. If the date difference is greater that one day you have missing dates which can then be calculated.
-
First, create your table. ID and date fields will be populated automaticallyso yoou only need to insert the name and the points CREATE TABLE `player_points` ( `id` int(11) NOT NULL AUTO_INCREMENT, `date_entered` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `player` varchar(45) DEFAULT NULL, `points` int(11) DEFAULT NULL, PRIMARY KEY (`id`) ) ; This will process your text area $db = new mysqli(HOST, USERNAME, PASSWORD, 'test' ); if (isset($_POST['points']) && !empty($_POST['points'])) { $entries = explode("\n", $_POST['points']); $insertData = array(); foreach ($entries as $e) { if (trim($e) == '') continue; // ignore empty lines list ($name, $pts) = explode(' ', $e); $insertData[] = sprintf("('%s', %d)", $db->real_escape_string($name), intval($pts)); } // build multi-insert query $sql = "INSERT INTO player_points(player,points) VALUES " . join(',', $insertData); // add records $res = $db->query($sql); if ($res) { echo $db->affected_rows . " records added<br>"; } else { echo "Query failed<br>".$db->error.'<br>'.$sql; } } else { echo "Enter players and points<br>"; } ?> <form action="" method="post"> <textarea cols="40" rows="15" name="points"></textarea> <input type="submit" name="btnsub" value="Submit"> </form> You can get this month's data with this (without emptying the table and losing your data) SELECT player, SUM(points) as Total FROM player_points WHERE YEAR(date_entered) = YEAR(CURDATE()) AND MONTH(date_entered) = MONTH(CURDATE()) GROUP BY player ORDER BY Total DESC;
-
The relationships between data items is of fundamental concern to anyone trying to query that data. If it isn't our concern then it is yours alone. Goodbye and stop wasting our time.
-
read first paragraph - http://php.net/manual/en/intro.mysql.php
-
Counting number of columns with the same number
Barand replied to therocker's topic in PHP Coding Help
cataiin - where is column "count" coming from? therocker - exactly what problem are you having. Apart from the GROUP BY which is OK but unnecessary if you are selecting a single id it should work (so long as $forums_id contains a valid id. Try SELECT forums_id, count(*) as forums_counting FROM forums_comment GROUP BY forums_id to get a count for each forum -
You need a column alias for the MAX expression. Try SELECT MAX(ID) as ID ....