jazzman1
Staff Alumni-
Posts
2,713 -
Joined
-
Last visited
-
Days Won
12
Everything posted by jazzman1
-
Hey, Davie, as I've promised before to restructure your code a little. Take a look carefully at an example, and try to get the logic. We have 4 tables: users, categories, topics, posts users: +----+-----------+ | id | user_name | +----+-----------+ | 1 | jazzman | | 2 | Davie34 | +----+-----------+ categories: +----+---------------+------------------------------------------------------------------------+ | id | cat_title | cat_description | +----+---------------+------------------------------------------------------------------------+ | 1 | Announcements | New things we may add to site or site is disabled we will let all know | | 2 | Support | Need help ? ask and we will get back to you asap | | 3 | General | General chatting about YourArcadeScript | | 4 | Pictures | Pictures for test | +----+---------------+------------------------------------------------------------------------+ topics: +----+--------+-------------+---------------------+ | id | cat_id | topic_title | date | +----+--------+-------------+---------------------+ | 1 | 1 | THREAD 1 | 2012-05-10 09:17:38 | | 2 | 1 | THREAD 2 | 2012-05-10 12:16:43 | | 3 | 1 | THREAD 3 | 2012-06-13 10:36:16 | | 4 | 2 | THREAD 4 | 2012-06-05 15:21:25 | | 5 | 2 | THREAD 5 | 2012-06-12 10:24:34 | | 6 | 3 | THREAD 6 | 2012-08-10 05:23:15 | +----+--------+-------------+---------------------+ posts: +----+----------+---------+--------+-----------------------------------------+---------------------+ | id | topic_id | user_id | cat_id | post_body | post_time | +----+----------+---------+--------+-----------------------------------------+---------------------+ | 1 | 1 | 1 | 1 | POST 1, THREAD 1 , CREATED FROM JAZZMAN | 2012-01-10 06:16:26 | | 2 | 1 | 1 | 1 | POST 2, THREAD 1 , CREATED FROM JAZZMAN | 2012-03-07 05:16:22 | | 3 | 1 | 2 | 1 | POST 3, THREAD 1, CREATED FROM DAVIE33 | 2012-04-10 11:41:24 | | 4 | 4 | 1 | 2 | POST 4, THREAD 4, CREATED FROM JAZZMAN | 2012-09-03 07:34:25 | +----+----------+---------+--------+-----------------------------------------+---------------------+ My html code: <?php include 'dbConnect.php'; ?> <html> <head> <title>Forum Read Records</title> </head> <body> <table border="1" cellpadding="0" cellspacing="0"> <tr> <th>Category</th> <th>Threads</th> <th>Posts</th> <th>Last Poster</th> <th>Last Date Post</th> </tr> <?php $result = $mysqli->query("SELECT c.cat_title,COUNT(t.id) AS threads, SUM((SELECT COUNT(p.id) FROM posts p WHERE p.topic_id = t.id)) AS posts, MAX((SELECT u.user_name FROM posts p RIGHT JOIN users u ON u.id = p.user_id WHERE p.post_time IN (SELECT MAX(p1.post_time) FROM posts p1 WHERE p1.cat_id= c.id))) AS user_name, (SELECT MAX(p2.post_time) FROM posts p2 WHERE p2.cat_id= c.id) AS datetime FROM topics t RIGHT JOIN categories c ON c.id = t.cat_id GROUP BY t.cat_id ORDER BY c.id ASC"); while ($row = $result->fetch_assoc()): ?> <tr> <td><?php echo $row['cat_title']; ?></td> <td><?php echo $row['threads']; ?></td> <td><?php echo $row['posts']; ?></td> <td><?php echo $row['user_name'];?></td> <td><?php echo $row['datetime'];?></td> </tr> <?php endwhile; ?> </table> </body> </html> dbConnect.php <?php //set connection variables $host = "localhost"; $username = "jazzman"; $password = "password"; $db_name = "phpTest"; //database name //connect to mysql server $mysqli = new mysqli($host, $username, $password, $db_name); //check if any connection error was encountered if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; } ?> My query is a little complex, but.... compare to your code, there is 1 query to 4, and 1 while loop to 3 in your code. Just styling according your CSS file, and I thing everything is gonna be fine. Test the script and if you find errors just tell me Good luck P.S I didn't get it, what result you want to appear in the last <td></td> together with datatime and username, the last post or topic (thread)
-
Error corrupted Word file after downloading with PHP
jazzman1 replied to Stefany93's topic in PHP Coding Help
Matt, I've tested the script to two different hosting, their output_buffering are set to off in php.ini files. The code that I'm using is: <?php $file = 'syllabus.docx'; header('Content-Description: File Transfer'); header("Content-Type: application/vnd.openxmlformats"); header('Content-Disposition: attachment; filename='. basename($file)); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); readfile($file); Godaddy (php -5.3.3) - http://kaneffbrookside.ca/home.php Bulgarian hosting (php 4.3.) - http://canada.lesno.net/home.php -
Check this out, I've written for you - http://canada.lesno.net/info.php You can download the html adn js code if you want it and php code is: header('Content-type: text/xml'); $ip = $_SERVER['REMOTE_ADDR']; $location = "http://api.hostip.info?ip=".$ip; print file_get_contents($location);
-
Error corrupted Word file after downloading with PHP
jazzman1 replied to Stefany93's topic in PHP Coding Help
My output_buffering is set to Off in my php.ini file. Sorry about that PS, without buffering and header('Content-Length: ' . filesize($file));, I've got a error message, as Stefi, when I try to open a file with microsoft office word 2010. -
Error corrupted Word file after downloading with PHP
jazzman1 replied to Stefany93's topic in PHP Coding Help
Well, this is the script, that I've tested into my local server. ob_start(); $file = 'syllabus.docx'; header('Content-Description: File Transfer'); header("Content-Type: application/vnd.openxmlformats"); //open/save dialog box header('Content-Disposition: attachment; filename='. basename($file)); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); ob_clean(); flush(); //read from server and write to buffer readfile($file); My output_buffering is Off in my php file. Where did you find a problem in my script above ? -
Error corrupted Word file after downloading with PHP
jazzman1 replied to Stefany93's topic in PHP Coding Help
I think, that should be work. Try, ob_start(); header("Content-Type: application/vnd.ms-word"); //open/save dialog box header('Content-Disposition: attachment; filename="syllabus.docx"'); ob_clean(); flush(); //read from server and write to buffer readfile('uploaded_files/syllabuses/syllabus.docx'); -
Error corrupted Word file after downloading with PHP
jazzman1 replied to Stefany93's topic in PHP Coding Help
I don't have a problem following my post above: http://canada.lesno.net/home.php -
Error corrupted Word file after downloading with PHP
jazzman1 replied to Stefany93's topic in PHP Coding Help
Well, according MIME type files located on my local linux server in directory /etc/mime.types The proper MIME type for .docx files is: application/vnd.openxmlformats-officedocument.wordprocessingml.document You can also create a hidden .htaccess file in your home directory adding this code AddType application/vnd.openxmlformats .docx .pptx .xlsx .xltx . xltm .dotx .potx .ppsx http://www.freetutorialssubmit.com/apache-mime-type-configuration-to-open-docx-pptx-xlsx-ms-office-files/1436 For beginning, try to change MIME type header("Content-Type: application/vnd.ms-word"); to header("Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document"); Is it a Bulgarian hosting server? -
Error corrupted Word file after downloading with PHP
jazzman1 replied to Stefany93's topic in PHP Coding Help
Stefi, attach a piece of the file to look its content. -
My logic is not very clear regarding to your post. You have to filter a.asset to be easy....... Try, WHERE ah.hoursasset = (SELECT asset FROM assets WHERE asset = $_POST['asset']) AND p.pmasset = (SELECT asset FROM assets WHERE asset = $_POST['asset']) I don't like this way, b/s a query is too long. Take a time and learn more about sql join statements.....
-
Well, guys, you are younger than me and obviously you have much more knowledge than I am. When I've started as a programmer few years ago, my boss said - "All sensitive data must be save into the DB" and for good or for evil, I'm doing it in this way. As I mentioned before, I'm glad to be a part of this forum. @Christian, sorry for wasting your time to seek a post # 17
-
Davie, the problem lies on the line 70 - $result= mysql_query("SELECT * FROM forumtopics WHERE cat = $id") If you copy/paste a query in phpMyAdmin, you will get a correct result SELECT * FROM forumtopics WHERE cat = 1 (assuming that $id = 1 ) If you put echo '<pre>'.print_r($result,true).'</pre>'; exit;, immediately after $result= mysql_query("SELECT * FROM forumtopics WHERE cat = $id") you will get a message Resource id #8 . You have to fetch and loop this data, to get a correct result. Also, you have to restructure the code. If you need help, I'm going try to help you.
-
Well, b/s you need to filter ah.hoursasset and p.pmasset whit a subquery string to get only 1 unique value. You can make a simple test, just replace them with some static values and you will see a proper result.
-
I'm sure about that.... I could not explain my logic very well in English. My point of view about it, it's very near to post 17 - http://stackoverflow.com/questions/815626/to-do-or-not-to-do-store-images-in-a-database
-
That's okay, but..... what about next statement : if (strtotime($user_data->lock_date) > $current_gmt_time) What about it? I posted the two echoed amounts and not sure why it doesn't send the output array in that true statement. Exactly , 1346794857 is not greater than time() !
-
That's okay, but..... what about next statement : if (strtotime($user_data->lock_date) > $current_gmt_time)
-
Ah.... pretty cool, Jesi. I like your explanations
-
Why ? There is no problem to create "read only views" users permissions.
-
Put a mysql_error() function inside a die() function in the end of your query string. Give us a result back, please. $db->query("UPDATE assets a, assethours ah, pm p SET a.asset = '".$_POST['asset']."', a.category = '".$_POST['category']."', a.descrip = '".$_POST['descrip']."', a.year = '".$_POST['year']."', a.make = '".$_POST['make']."', a.model = '".$_POST['model']."', a.serial = '".$_POST['serial']."' ah.hoursasset = '".$_POST['asset']."' p.pmasset = '".$_POST['asset']."' WHERE id = '".$_POST['asset']."'") or die(mysql_error());
-
It is easier to control access to the images if they are in a database.
-
I meant, if you don't understand me correctly, which table it belongs this id ?
-
Do you get any mysql errors? Is it true, WHERE id = '".$_POST['asset']."'")
-
It really depends! If your images are very important as security documents, medical research, etc..... the best way for me to save them in DB, otherwise I prefer Pika's solution.
-
What content you have in a forumcats table ?
-
Do both of CMS on the same version?