-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
If images can belong to multiple categories then you need three tables, the third defining which categories the image belongs to +----+----------------+-------------+ +-----+---------------------+ | id | image | path | | id | categoryName | +----+----------------+-------------+ +-----+---------------------+ | 1 | image_1.jpg | /images | | 1 | People | | 2 | image_2.jpg | /images/xx | | 2 | Landscape | +----+----------------+-------------+ | 3 | Sport | | | 4 | Animals | | | 5 | Friends and family | | +-----+---------------------+ | | +---------------------------+ +------------------+ | | | | | | +-----+--------+---------+ | id | img_id | cat_id | +-----+--------+---------+ | 1 | 1 | 1 | | 2 | 1 | 5 | | 3 | 2 | 2 | | 4 | 2 | 4 | +-----+--------+---------+
-
The error means your query failed. In this case because CALL is a mysql reserved word, so you need to enclose it in backticks. $sql = "SELECT * FROM qsolog WHERE `call` = '$call' "; Also you need to sanitize the post data with mysqli_real_escape_string() and not with htmlentities() prior to using it in the query. Or use a prepared statement. Check data has been posted before attempting to query and output the table
-
If the 4 structures are the same they should be in a single "comments" table with an added "section" column to distinguish them. However, given what you have SELECT `comment`, 0 as section FROM threaded_comments WHERE author = '$username' UNION SELECT `comment`, 1 as section FROM threaded_comments1 WHERE author = '$username' UNION SELECT `comment`, 2 as section FROM threaded_comments2 WHERE author = '$username' UNION SELECT `comment`, 3 as section FROM threaded_comments3 WHERE author = '$username'
-
Sorry, I forgot you were usinf MSSQL and not MySQL. Use SELECT p.pc_id, p.pc_name, p.makemodel, r.room_name, r.building FROM tblpc as p INNER JOIN tblroom as r ON p.room_id = r.room_id ORDER BY p.pc_name
-
http://uk1.php.net/manual/en/mysqli.query.php http://uk1.php.net/manual/en/mysqli-result.fetch-assoc.php iit certainly would if you wanted user_name rather than video_name
-
What is it that you are trying to produce from all these arrays? I haven't managed to work that out since your very first post.
-
Until the form is submitted, $_POST['Title'] does not exist so when the page first loads you get the error. Check it is set before trying to use it and update the db
-
Except for a missing imagedestroy($gd); after the imagepng($gd), that code was fine and ran without a hitch. That missing line wouldn't stop it running, it would just waste memory.
- 6 replies
-
- imagecreatetruecolor
- unexpected t_variable
-
(and 1 more)
Tagged with:
-
gd or gd2? imagecreatetruecolor() requires the latter;
- 6 replies
-
- imagecreatetruecolor
- unexpected t_variable
-
(and 1 more)
Tagged with:
-
The last thing you want to do is query one table then, as you process that table's records, run a separate query on each record. Do not run queries in loops, use a JOIN instead. You first query should be SELECT p.pc_id, p.pc_name, p.makemodel, r.room_name, r.building FROM tblpc as p INNER JOIN tblroom as r USING (room_id) ORDER BY p.pc_name By using a join it finds the matching room record using the room_id and you can get the room name and building in the one query
-
You are already constructing $email_message and you want the disclaimer to go at the end of it. Also, there is no point in adding the disclaimer after the email has been sent. So, have a look at your code and think about where a suitable place would be.
-
Don't use "SELECT * ", specify just the columns you need. Use mysql_fetch_assoc() instead of mysql_fetch_array(). $video_info3 will contain an array of the columns in the row. You can view its contents with echo '<pre>', print_r($video_info3, true), '</pre>'; Seeing what is in there should help you process the contents. You should stop using mysql and change to mysqli ASAP as the mysql functions will soon be no longer available.
-
pseudocode <table> <?php if no storms output "no storms" row else output headings rows while stormdata output storm data row endwhile endif ?> </table>
-
Left Join values from non-existing table to a real one
Barand replied to jazzman1's topic in MySQL Help
On my server mysql> SHOW VARIABLES LIKE 'collation%'; +----------------------+------------------+ | Variable_name | Value | +----------------------+------------------+ | collation_connection | cp850_general_ci | | collation_database | utf8_general_ci | | collation_server | utf8_general_ci | +----------------------+------------------+ and mysql> SHOW VARIABLES LIKE 'character%'; +--------------------------+---------------------------------------------------------+ | Variable_name | Value | +--------------------------+---------------------------------------------------------+ | character_set_client | cp850 | | character_set_connection | cp850 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | cp850 | | character_set_server | utf8 | | character_set_system | utf8 | +--------------------------+---------------------------------------------------------+ -
Left Join values from non-existing table to a real one
Barand replied to jazzman1's topic in MySQL Help
1:20am - I need all the beauty sleep I can get. Back in 8 hours -
Left Join values from non-existing table to a real one
Barand replied to jazzman1's topic in MySQL Help
mysql> select version(); +------------------+ | version() | +------------------+ | 5.1.57-community | +------------------+ -
Left Join values from non-existing table to a real one
Barand replied to jazzman1's topic in MySQL Help
have you tried mysql> SELECT HEX(T1col) FROM t1; +------------+ | HEX(T1col) | +------------+ | 61 | | 64 | +------------+ -
Left Join values from non-existing table to a real one
Barand replied to jazzman1's topic in MySQL Help
I changed mine to varchar(45) mysql> describe t1; +-------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | T1col | varchar(45) | YES | | NULL | | +-------+-------------+------+-----+---------+----------------+ 2 rows in set (0.03 sec) mysql> select * from t1; +----+-------+ | id | T1col | +----+-------+ | 1 | a | | 2 | d | +----+-------+ 2 rows in set (0.00 sec) mysql> SELECT tmp.string -> FROM ( SELECT 'a' AS string -> UNION ALL -> SELECT 'b' -> UNION ALL -> SELECT 'c' -> UNION ALL -> SELECT 'd' -> ) AS tmp -> LEFT JOIN T1 ON (T1.T1col = tmp.string) -> WHERE T1.T1col IS NULL; +--------+ | string | +--------+ | b | | c | +--------+ 2 rows in set (0.00 sec) Same! -
Left Join values from non-existing table to a real one
Barand replied to jazzman1's topic in MySQL Help
Should work mysql> describe t1; +-------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | T1col | char(1) | YES | | NULL | | +-------+---------+------+-----+---------+----------------+ 2 rows in set (0.02 sec) mysql> select * from t1; +----+-------+ | id | T1col | +----+-------+ | 1 | a | | 2 | d | +----+-------+ 2 rows in set (0.00 sec) mysql> SELECT tmp.string -> FROM ( SELECT 'a' AS string -> UNION ALL -> SELECT 'b' -> UNION ALL -> SELECT 'c' -> UNION ALL -> SELECT 'd' -> ) AS tmp -> LEFT JOIN T1 ON (T1.T1col = tmp.string) -> WHERE T1.T1col IS NULL; +--------+ | string | +--------+ | b | | c | +--------+ 2 rows in set (0.00 sec) -
Left Join values from non-existing table to a real one
Barand replied to jazzman1's topic in MySQL Help
Do the values in T1col contain whitespace? -
Multiple LEFT JOINS not returning expected results
Barand replied to jalinidy's topic in PHP Coding Help
That makes sense. It seemed to me that when a solution needs several table subqueries to knock the data into a shape suitable for querying then there ought to be another way. -
The above is keyed by player.venue. The totals in the query are by player Is that the reason for your discrepancy? PS I mentioned in the other thread how to change it to get totals by player/venue
-
Multiple LEFT JOINS not returning expected results
Barand replied to jalinidy's topic in PHP Coding Help
Would it not be possible to store the holiday_id in the request record. You would then easily know by matching that TestA and TestB had not been taken yet without using the hours taken - ie match on dates and ids rather than the hours (incidentally the hol_bal is derived as a cumulative hours remaining through the year) and is the map table required? -
Yes, the WHERE is fine. In answer to the other question see http://forums.phpfreaks.com/topic/285539-question-about-inner-join/?p=1465944&do=findComment&comment=1465944
-
Select unique records, aggregating on a date in datetime format.
Barand replied to skania's topic in MySQL Help
You sholdn't be repeating the students' names in every attendance record. The name should be stored once in a student table. Only the ids should be in both tables. That said, here's one way My test data My code <?php $db = new mysqli(HOST,USERNAME,PASSWORD,'monty'); $monday = '2014-01-06'; // week commencing date $dt = new DateTime($monday); $dp = new DatePeriod($dt, new DateInterval('P1D'), 4); // // table headings // $heads = "<tr><th class='name'>Student Name</th>"; foreach ($dp as $d) { $datesArray[$d->format('Y-m-d')] = ''; // create empty array $heads .= '<th>' . $d->format('D jS') . '</th>'; } $heads .= "</tr>\n"; // // table data // $sql = "SELECT DISTINCT student_id , student_name , DATE(swipe_in) FROM attendance WHERE DATE(swipe_in) BETWEEN '$monday' AND '$monday' + INTERVAL 4 DAY ORDER BY student_id"; $curname = $curid = ''; $tdata = ''; $res = $db->query($sql); while (list($id, $name, $date) = $res->fetch_row()) { // check if student has changed if ($id != $curid) { if ($curid) { // output row for the current student $tdata .= "<tr><td class='name'>$curname</td><td>".join('</td><td>', $studentData)."</td></tr>\n"; } $curname = $name; // reset name and id $curid = $id; $studentData = $datesArray; // reset empty array ready for next student } $studentData[$date] = '✓'; // flag student as attended } $tdata .= "<tr><td class='name'>$curname</td><td>".join('</td><td>', $studentData)."</td></tr>\n"; ?> <html> <head> <style type="text/css"> td,th { padding: 4px; } td { font-family: sans-serif; font-size: 9pt; text-align: center; } .name { text-align: left; width: 200px; } table { border-collapse: collapse; } </style> </head> <body> <h4>Week Commencing <?php echo $dt->format('l, jS F, Y'); ?></h4> <table border='1'> <?php echo $heads, $tdata ; ?> </table> </body> </html> Results attached