PHP - News Publishing Script Required..
i want a script which should be easily integrated with the website and should fully customizable like cutephp.. the problem with cutephp is that it can't handle large data since it stores all the news articles in one .txt file on the server.. as the number of articles grow.. the size of .txt file increases and it becomes impossible for the server to handle the script.. i want a script which should be easily integrated into the website and should have the following features.
- article categories - admin panel to add news - should use mySQL to store articles or it should create .htm files for articles.. i hope you get the point.. by the way if i want to write my own script.. what is the easiest way to write a script which should have categories, show news on webpages, have admin password protected add news area.. should create seperate files on the server or use mysql..nothing complicated.. simple news posting script.. Similar TutorialsHi, I'm currently coding a script, where I would like to post news & versions changes etc into my client's portal. So my client install the script, they login to the admin area, and they see messages from me, optionally if there's a new version available. I was thinking about doing this with cUrl, and just have a page that display my news, and then call it from the client portal, not sure about it though. What would you guys suggest? So I've got a simple news script that pulls the last 5 posts in a specific phpbb3 forum but I'm getting errors on the front page whenever they don't at least open the forums before. There errors: To narrow it down a little more for everyone, When they visit the home page( http://im.deathwillow.com ) before visiting the forums they receive the following errors. Once they have at least visited, not requiring a log in, the forums ( http://im.deathwillow.com/forums ) the errors disappear. Any ideas? Code: [Select] [phpBB Debug] PHP Notice: in file /includes/session.php on line 1024: Cannot modify header information - headers already sent by (output started at /hermes/web03/b36/pow.deathwillow21/IM/index.php:8) [phpBB Debug] PHP Notice: in file /includes/session.php on line 1024: Cannot modify header information - headers already sent by (output started at /hermes/web03/b36/pow.deathwillow21/IM/index.php:8) [phpBB Debug] PHP Notice: in file /includes/session.php on line 1024: Cannot modify header information - headers already sent by (output started at /hermes/web03/b36/pow.deathwillow21/IM/index.php:8) The script: Code: [Select] <?php define('FORUM_ID', 6); // Forum ID to get data from define('POST_LIMIT', 5); // How many to get define('PHPBB_ROOT_PATH', './forums/'); // Path to phpBB (including trailing /) define('PRINT_TO_SCREEN', true); // If set to true, it will print the posts out // If set to false it will create an array $news[] with all the following info // // 'topic_id' eg. 119 // // 'topic_time' eg. 06 June, 07 (uses board default) // 'topic_replies' eg. 26 // // 'username' eg. chAos // 'topic_title' eg. "News Post" // // 'post_text' eg. just the text (formatted w/ smilies, bbcode, etc) define('IN_PHPBB', true); $phpbb_root_path = PHPBB_ROOT_PATH; $phpEx = substr(strrchr(__FILE__, '.'), 1); include($phpbb_root_path . 'common.' . $phpEx); include($phpbb_root_path . 'includes/functions_display.' . $phpEx); include($phpbb_root_path . 'includes/bbcode.' . $phpEx); // Start session management $user->session_begin(false); $auth->acl($user->data); // Grab user preferences $user->setup(); $query = "SELECT u.user_id, u.username, t.topic_title, t.topic_poster, t.forum_id, t.topic_id, t.topic_time, t.topic_replies, t.topic_first_post_id, p.poster_id, p.topic_id, p.post_id, p.post_text, p.bbcode_bitfield, p.bbcode_uid FROM ".USERS_TABLE." u, ".TOPICS_TABLE." t, ".POSTS_TABLE." p WHERE u.user_id = t.topic_poster AND u.user_id = p.poster_id AND t.topic_id = p.topic_id AND p.post_id = t.topic_first_post_id AND t.forum_id = ".FORUM_ID." ORDER BY t.topic_time DESC"; $result = $db->sql_query_limit($query, POST_LIMIT); $posts = array(); $news = array(); $bbcode_bitfield = ''; $message = ''; $poster_id = 0; while ($r = $db->sql_fetchrow($result)) { $posts[] = array( 'topic_id' => $r['topic_id'], 'topic_time' => $r['topic_time'], 'username' => $r['username'], 'topic_title' => $r['topic_title'], 'post_text' => $r['post_text'], 'bbcode_uid' => $r['bbcode_uid'], 'bbcode_bitfield' => $r['bbcode_bitfield'], 'topic_replies' => $r['topic_replies'], ); $bbcode_bitfield = $bbcode_bitfield | base64_decode($r['bbcode_bitfield']); } // Instantiate BBCode if ($bbcode_bitfield !== '') { $bbcode = new bbcode(base64_encode($bbcode_bitfield)); } // Output the posts foreach($posts as $m) { $poster_id = $m['user_id']; $message = $m['post_text']; if($m['bbcode_bitfield']) { $bbcode->bbcode_second_pass($message, $m['bbcode_uid'], $m['bbcode_bitfield']); } $message = str_replace("\n", '<br />', $message); $message = smiley_text($message); $comment = ($m['topic_replies']==1) ? 'comment' : 'comments'; if( PRINT_TO_SCREEN ) { /* Output is in the following format * * <h3>Thread Title</h3> ^ <h4 class="postinfo">date // 5 comments // poster</h4> * <p>First post test</p> * */ echo "<div class=\"newsPost\"> <h1><span class=\"topic\"><a href=\"".PHPBB_ROOT_PATH."viewtopic.php?f=".FORUM_ID."&t={$m['topic_id']}\">{$m['topic_title']}</a></span></h1> <p>{$message}</p> <div class=\"newsPost_footer\"> <span class=\"newsPost_comments\">Comments: <a href=\"".PHPBB_ROOT_PATH."viewtopic.php?f=".FORUM_ID."&t={$m['topic_id']}\">{$m['topic_replies']}</a></span><span class=\"newsPost_author\">Posted by <i><font color=\"#CCCCCC\">{$m['username']} </font>on " . $user->format_date($m['topic_time']) . "</i></span> </div> </div>"; } else { $news[] = array( 'topic_id' => $m['topic_id'], // eg: 119 'topic_time' => $user->format_date($m['topic_time']), // eg: 06 June, 07 (uses board default) 'topic_replies' => $m['topic_replies'], // eg: 26 'username' => $m['username'], // eg: chAos 'topic_title' => $m['topic_title'], // eg: "News Post" 'post_text' => $message, // just the text ); } unset($message,$poster_id); } ?> Hello everyone, I have a script that shows the news posted on my website in a bigger format with comments ect... but it gives me the error Code: [Select] Parse error: syntax error, unexpected '}' in /home/stormgc/public_html/sources/news_view.php on line 50 I reviewed the code, I know what the error fix would be, but I cannot find the proper place to put it. If someone could please review the script and help that would be awesome! --> Code: [Select] <? $id = $_GET['id']; $news = mysql_query("SELECT * FROM `news` WHERE id='$id'"); if(mysql_num_rows($news) > 0){ $newz = mysql_fetch_array($news); loadHeader($newz['title']); } if($_GET['update'] == 1){ confirm('You have successfully updated this news.'); } ?> <br /> <div class="title"><? echo $newz['title']; ?><span class="options"><a href="index.php">Home</a> / <? echo $newz['title']; ?></span></div> <div class="content"> <? $username = $newz['username']; ?> <div class="category"><a href="index.php?action=news_view&id=<? echo $newz['id']; ?>"><? echo $newz['title']; ?></a> posted on <? displayTime($newz['time'], 'F jS, Y \a\t g:i a'); ?> <span class="options">By <? $accounts = mysql_query("SELECT * FROM accounts JOIN profiles ON accounts.username=profiles.username WHERE accounts.username='$username'"); if(mysql_num_rows($accounts) > 0){ $account = mysql_fetch_array($accounts); ?> <a href="index.php?action=profile&user=<? echo $account['username']; ?>">{<? } echo $account['display_name']; ?></a> <? } else { echo $username; } ?> </span></div> <div class="cell1"> <? echo parseText($newz['message']); ?> <br /><br /> <a href="index.php?action=forums">Discuss this in the forums...</a> <? if($cur_account['staff'] == "on" || $cur_admin == 1){ ?> <br /> <br /> <a href="index.php?action=news_modify&id=<? echo $newz['id']; ?>">Modify</a> | <a href="" onClick="if(confirm('Are you sure you want to delete this news?')){ location.href='index.php?action=news_delete&id=<? echo $newz['id']; ?>'; } return false;">Delete</a> <? } ?> </div> <? loadFooter(); } else { fatalError('The news article you are trying to view does not exist.'); } ?> Thanks, NW This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=318895.0 Is there a way or function that stops the execution of a required script but continues to execute the parent script, for example: if this is a.php <?php echo "<br>Good morning"; // function to stop execution of only this script to appear here echo "<br>Good Afternoon"; ?> and then this is b.php <?php require("a.php'); echo "<br>Good Evening"; ?> So if the file b.php is called it is supposed to display: Good morning Good evening So it has to skip "Good afternoon" because of the anonymous function which I need Hello, Im trying to create a simple voting script for my site, i been trying different things but cannot get it too function properly. The idea is you click the 'thumbs up' image to add 1 to the 'likes' value and thumbs down to add '1' to the dislikes. Sound simple but its giving me headaches. Would really appreciate it if someone could take a quick look at my script. The table is called 'youtube_rating' (because thats the look i was going for) and in the table is 4 columns, id (aut0_increment), liked (counts liked votes), disliked (counts dislikes) and item_num which is the id for teh product the rating is for. Code: [Select] <? if ( $row['rating'] == 'YES' ) { require ("../rating/voting/dbcon.php"); $result1 = mysql_query("select * from youtube_rating WHERE item_num='".$page_id."'"); $row = mysql_fetch_array($result1); $dislike = $row['dislike']; $like = $row['liked']; if (isset($_POST['submitted'])) { require_once ("../database/functions.php"); $userip = $_SERVER['REMOTE_ADDR']; $id = safe($_POST['id']); $vote = '1'; // check if user already voted $result = mysql_query("SELECT * FROM youtube_ip WHERE userip='$userip' AND item_num ='".$id."'"); $num = mysql_num_rows($result); // if already voted show error if (isset($_POST['submitted']) && ($num > 0)) { echo '<div class="alreadyvoted">You have already voted!</div>'; } // add like if (isset($_POST['submitted']) && ($_POST['submitted'] == 'like') && ($num == 0)) { // add 1 to value $liked_value = mysql_query("SELECT liked FROM youtube_ip WHERE item_num ='".$id."'"); $liked_total = $liked_value + $vote; $query = "update youtube_rating set liked = '".$liked_total."' where item_num ='".$id."'"; echo '<div class="ilikethis">You like this!</div>'; } // add dislike if (isset($_POST['submitted']) && ($_POST['submitted'] == 'dislike') && ($num == 0)) { // add 1 to value $dislike_value = mysql_query("SELECT dislike FROM youtube_ip WHERE item_num ='".$id."'"); $dislike_total = $dislike_value + $vote; $query = "update youtube_rating set dislike = '".$dislike_total."' where item_num ='".$id."'"; echo '<div class="idislikethis">You Dislike this!</div>'; } // log ip // if (isset($_POST['submitted']) && ($num == 0)) // { // mysql_query ("insert into youtube_ip (userip, item_num) values ('".$userip."', '".$id."')"); // } } ?> <table width="50%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="48%" align="center"> <form action="" method="post"> <input name="id" type="hidden" value="<? echo $page_id ?>" /> <input name="submitted" type="hidden" value="like" /> <button type="submit" class="like_button" name="like" id="like" > <img src="../rating/voting/pixel-vfl73.gif" alt=""> <span><?php echo $like?></span> </button> </form> </td> <td width="52%"> <form action="" method="post"> <input name="id" type="hidden" value="<? echo $page_id ?>" /> <input name="submitted" type="hidden" value="dislike" /> <button type="submit" class="dislike_button" name="dislike" id="dislike" > <img src="../rating/voting/pixel-vfl73.gif" alt=""> <span><? echo $dislike?></span> </button> </form> </td> </tr> </table> <? } ?> The problem is the vote does not add up or update the database, also it doesn't seem to be checking if the user has voted or not, it just attempts (but fails) to add a vote no matter what Thanks for any help. Hey Friends,
I am new to this forum, and does not know anything about programming. And I require very small help from the experts of forum. I have downloaded free image hosting script from web & it is not working fine, it gets stuck at basic.php (one of the file in script). I am sharing the script here also sharing the website. My website : bsm1313.5gbfree.com
Note : I have uploaded a rar file. Kindly change extension to .rar from .php. as it was not allowing me to upload the rar file.
Any kind of help is highly highly appreciated. Thanks a ton in advance.
Attached Files
easyimagehoster_1.32.php 35.46KB
5 downloads Hello everyone. I recently coded a Minecraft Voting for Diamonds script. Basically, you enter your username, you vote on the sites, then click "Get Reward". The reward then goes through a RCON script, and rewards the user with their diamonds in-game. the full script works fine, and I am happy with it, but there is one small problem; and that is users being able to abuse the system. If they wanted to, they could just refresh the page, and click Get Rewarded again, and again. I want to make something like this: It has a countdown on the link, which is started upon click, and then the link re-activates when the timer is done. My script already has "disabled=..." tags, so you have to click all links, this way would make sure a user cannot click the link until the timer is done. I'm pretty new to PHP, and please forgive me if it is not 100% PHP, but this place seemed extremely helpful. I am also pretty new to PHP, so make it for dummies xD Thanks everyone! After spending 3 days on internet and struggling with so many different forums , i have found this forum where i believe i will get the solution for my problem. Friends, I am zero in PHP, but still i have managed to do something to fulfill my requirement. I am stuck with one thing now..So i need help on.... I am using one html+php form to submit database into mysql. I created a display of that table through php script on a webpage. Now i want a datepicker option on that displayed page by which i should able to select the date range and display the data of that date range from my mysql table. And then take a export of data displayed of selected date range in excel. This displayed page is login protected, so i want after login the next thing comes in should show a sate selection option which should be fromdate to to date , and then records should displayed from the database and i can take export of those displayed results in excel file. The code i am using on this page is below which do not have any thing included for excel export and datepicker script, I am pasting the code here and request you to please include the required code in it as required. Thanks In advance <?php //database connections $db_host = 'localhost'; $db_user = '***********'; $db_pwd = '*************'; $database = 'qserves1_uksurvey'; $table = 'forms'; $file = 'export'; if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); // sending query $result = mysql_query("SELECT * FROM {$table} ORDER BY date desc"); if (!$result) { die("Query to show fields from table failed"); } $num_rows = mysql_num_rows($result); $fields_num = mysql_num_fields($result); echo "$num_rows"; echo "<h1></h1>"; echo "<table border='1'><tr>"; // printing table headers for($i=0; $i<$fields_num; $i++) { $field = mysql_fetch_field($result); echo "<td>{$field->name}</td>"; } echo "</tr>\n"; // printing table rows while($row = mysql_fetch_row($result)) { echo "<tr>"; // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row as $cell) echo "<td>$cell</td>"; echo "</tr>\n"; } mysql_free_result($result); ?> </body></html> This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=346951.0 Before I posted in here about a content management system for posting news. I was wondering how I could make so that when you fill out a form and send all the data to the database, it creates a new page from a template and includes that data within it? I know I asked this before, and some mentioned the _get method, but im using _post to process the form data and have no idea where to integrate the _get method. Here's the form in question: Code: [Select] <form action="http://www.djsmiley.net/cms/news/process.php" method="post" id="news"> <h1>Post New Article</h1> <p>Please fill out all of the following fields:</p> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td height="55" class="cmsNewsformText">Type*:</td> <td><font size="1"> <input name="type" type="text" class="Form1" size="50" /> </font></td> </tr> <tr> <td height="55" class="cmsNewsformText">News Topic/Title*: </td> <td><font size="1"> <input name="title" type="text" class="Form1" size="50" /> </font></td> </tr> <tr> <td height="55" class="cmsNewsformText">Username*:</td> <td><font size="1"> <input name="user" type="text" class="Form1" value="DJ Smiley" size="50" /> </font></td> </tr> <tr> <td height="55" class="cmsNewsformText">Url*:</td> <td><font size="1"> <input name="url" type="text" class="Form1" size="50" /> </font></td> </tr> <tr> <td height="55" class="cmsNewsformText">Message*:</td> <td><font size="1"> <textarea name="message" cols="43" rows="10" class="TextField1"></textarea> </font></td> </tr> <tr> <td height="55" class="cmsNewsformText"> </td> <td><font size="1"> <input name="Submit" type="submit" class="Button1" value="Submit" /> <input name="Submit2" type="reset" class="Button1" value="Reset" /> </font></td> </tr> </table> </form> and here's the code that sends the data from the forms to the database: Code: [Select] <?php $user=$_POST['user']; $title=$_POST['title']; $message=$_POST['message']; $type=$_POST['type']; $url=$_POST['url']; mysql_connect("hostname", "username", "password") or die(mysql_error()); mysql_select_db("database") or die(mysql_error()); $sql = sprintf("INSERT INTO mynews (user, title, message, type, url) VALUES ('%s', '%s', '%s', '%s', '%s')", mysql_real_escape_string($user), mysql_real_escape_string($title), mysql_real_escape_string($message), mysql_real_escape_string($type), mysql_real_escape_string($url)); $result = mysql_query($sql); Print "The article has successfully been posted"; ?> can someone help or at least point me in the right direction? Hi all, i have a form for add-/edit- news. my fields are :id postdate title newstxt formember preimg img1 img2 img3 authr. i store (modified by concat date)names of news images in table and upload theme in folder /dir/newsimg. i want my images in jpg/gif format and for preimage (103*103 pixel & <5KB) and for img1,2,3 (width:650 pixel & <50KB ). Here is my (multipart)form: <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" enctype="multipart/form-data"> <div><input id="post_title" type="text" size="30" tabindex="1" value="news title" /></div> <textarea cols="80" rows="10"></textarea> <div > <h3>Just For Members:</h3> <ul> <li> <label><input type="checkbox" name="chbox" />yes</label></li> </ul><BR/> <ul> <h4>news pics</h4> <li><p>preimg pic must be 103*103 pixel and maxsize <5kb. </p></li> <li><p> for image1,image2,image3 weightsize must ebe 650pixel and maxsize mustbe <50 kb. </p></li> <li> <INPUT TYPE=file NAME="preimg" size=20 accept="image/jpeg,image/gif"> </li> <li><INPUT TYPE=file NAME="image1" size=20 accept="image/jpeg,image/gif"> </li> <li><INPUT TYPE=file NAME="image2" size=20 accept="image/jpeg,image/gif"> </li> <li><INPUT TYPE=file NAME="image3" size=20 accept="image/jpeg,image/gif"> </li> </ul> <p> <input type="submit" value="preview" /> <input type="submit" value="save" /> </p> </div> </form> in INSERT and for TEST MY IMAGES what should i add? my php code is : include_once '../../config.inc.php'; if (!include '../autorization.php') { echo 'Access denied!'; exit (); } if ($_POST['submit']) { $SQL = 'INSERT INTO news VALUES(?:for images); if (!(mysql_query ($SQL))) { exit ('Can\'t PUBLISH news!'); ; } if ($_FILES['logo']['name']) { if (copy ($_FILES['preimg']['tmp_name'], $documentroot . ('' . ' /dir/newsimg/' . NOW() . '.') . substr ($_FILES['preimg']['type'], 6))) { unlink ($_FILES['logo']['tmp_name']); } } if ($_FILES['image1']['name']) { if (copy ($_FILES['image1']['tmp_name'], $documentroot . ('' . ' /dir/newsimg/' . NOW() . '.') . substr ($_FILES['image1']['type'], 6))) { unlink ($_FILES['image1']['tmp_name']); } } if ($_FILES['image2']['name']) { if (copy ($_FILES['image2']['tmp_name'], $documentroot . ('' . ' /dir/newsimg/' . NOW() . '.') . substr ($_FILES['image2']['type'], 6))) { unlink ($_FILES['image2']['tmp_name']); } } if ($_FILES['image3']['name']) { if (copy ($_FILES['image3']['tmp_name'], $documentroot . ('' . ' /dir/newsimg/' . NOW(). '.') . substr ($_FILES['image3']['type'], 6))) { unlink ($_FILES['image3']['tmp_name']); } } } TNX. I have this code.. <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { mysql_query("INSERT INTO blog (date, name, desc) VALUES ('" . date("Y-m-d") . "', '". realEscape($_POST['name']) ."', '". realEscape($_POST['desc']) ."') ") or die(mysql_error()); echo "News Added."; } ?> <center><h1>Adding News</h1> <form action="news.php" method="POST"> Your News Name:<br> <input id="name" type="text" name="name" autocomplete="off" maxlength="25"><br>Your News Description: <br> <textarea name="desc" id="desc" rows="3" cols="60" maxlength="250"> </textarea><br> <input type="submit" name="submit" value="Add News"> </form> And the error is Code: [Select] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc) VALUES ('2010-09-02', 'vcv', ' xcvxc')' at line 1 Note: vcv and xcvxc are the inputs we(I) used for a test so we(I) could get the error. Hi guys i have been racking my brains been on about 5 different forums now with no joy either.. so here goes I am looking for a PHP news script thing, so I can have a column on the right hand side of my home page updating students results in passing or failing. I have looked and looked for php news scripts and none work they all are defect i am using a windows server, using wampserver to test my files locally.. any ideas or help.. would be oh so much appreciated Hello everyone, I'm making a site with PHP script and PHPmyadmin database, i need some help with how to add news and then edit them or delete them on the site, not in the Database(if that is even possible to do it there), so far i can only delete the news, but when i try to add new stuff i just get the error message of my code, which is not very nice of it but hey, i'm a noob at this PHP so i must be doing something wrong. this is the code i have for the current situation. Code: [Select] <?php include_once( 'database_functions.php' ); $connectID = connectToDatabase( 'login' ); mysql_set_charset( 'utf8', $connectID ); $categories = mysql_query('SELECT * FROM ref_categories', $connectID); if( @$_POST && @$_POST['submitted'] && ( !@$_GET[ 'id' ] ) ) { $title = ( $_POST[ 'topic_name' ] ); $topic = ( $_POST[ 'topic_desc' ] ); //write to database mysql_query ( "INSERT into news (title, topic) VALUES ('$title', '$topic')", $connectID ) or die ("Unable to insert record into database"); print "Record successfully added"; } elseif( !$_POST && $_GET && $_GET['id'] ) { $id = $_GET['id']; $thisRecord = mysql_query("SELECT * FROM ref_categories WHERE id = $id", $connectID ) or die( "Can't Read this record." ); $recordData = mysql_fetch_array( $thisRecord, MYSQL_ASSOC ); } elseif( $_POST && $_POST['submitted'] && ( $_GET['id'] ) ) { $title = ( $_POST[ 'title' ] ); $topic = ( $_POST[ 'topic_desc' ] ); $id = $_GET['id']; $success = mysql_query( "SELECT * FROM news", $connectID ) or die( "Can't Update this record" ); if( $success ) { header( 'Location: links_admin.php?updated=1' ); } } else { } ?> I have a news code that posts news on the home page like a CMS would. How would i make it so when I post news using the code, I can use HTML within the post to change around what it looks like? Instead of just having it display the HTML like "<font color="blue">Example</font>" Regards, NW Got this script he http://www.codewalkers.com/c/a/Database-Articles/PHPMySQL-News-with-Comments/6/ Everything works, and I mean EVERYTHING. The problem is, when the form gets submitted, the database isn't being queried/updated/whatever. It worked at first, but after I started customizing/modifying it, it quit working. Here's my modified script: Code: [Select] <?php //**********************************// //**********************************// /*******user config variables********/ /* max number of news items to show */ //**********************************// //**********************************// $max_items = 5; //***********************// //***********************// //***********************// //make database connection// //***********************// //***********************// //***********************// $db = mysql_connect ('my hostname','my username','my password'); mysql_select_db ('my database name',$db); //If not all of the news articles are being displayed... function displayNews($all = 0) { /* bring in two variables * $db is our database connection * $max_items is the maximum number * of news items we want to display */ global $db, $max_items; /* query for news items */ if ($all == 0) { /* this query is for up to $max_items; only five news articles will be displayed */ $query = "SELECT id,title,body," . "DATE_FORMAT(date, '%m-%d-%Y') as date " . "FROM news ORDER BY id DESC LIMIT $max_items"; } else { /* this query will get all news; $max_items will be false */ $query = "SELECT id,title,body," . "DATE_FORMAT(date, '%Y-%m-%d') as date " . "FROM news ORDER BY id DESC"; } $result = mysql_query ($query); while ($row = mysql_fetch_assoc ($result)) { /* place table row data in * easier to use variables. * Here we also make sure no * HTML tags, other than the * ones we want are displayed */ $date = $row['date']; $title = htmlentities ($row['title']); $news = nl2br (strip_tags ($row['body'], '<a><b><i><u>')); $url = $row['id']; /* display the data (news) */ echo "<table border=\"0\" width=\"100%\"><tr><td><strong><h2><a href=\"{$_SERVER['PHP_SELF']}" . "?action=show&id={$row['id']}\">$title</a></h2></strong> <em>posted on $date</em> | by <strong>DJ Smiley</strong></td></tr>\n"; echo "<tr><td>"; echo stripslashes(substr($news, 0, 500)); echo "...<a href=\"{$_SERVER['PHP_SELF']}" . "?action=show&id={$row['id']}\">read more</a></td></tr>\n"; /* get number of comments from database */ $comment_query = "SELECT count(*) FROM comments " . "WHERE news_id={$row['id']}"; $comment_result = mysql_query ($comment_query); $comment_row = mysql_fetch_row($comment_result); /* display number of comments with link; add twitter, facebook, digg, and share widgets; and add email sharing widget */ echo "</table>\n<table width=\"100%\" border=\"0\"> <tr> <td width=\"6%\"><a href=\"{$_SERVER['PHP_SELF']}" . "?action=show&id={$row['id']}\"><img src=\"images/Icons/Comment/2.png\" width=\"20\" height=\"20\" class=\"fltlft2\"/></a>$comment_row[0]</td> <td width=\"13%\"><!-- FreeTellaFriend BEGIN --> <a href=\"http://www.freetellafriend.com/tell/\" onclick=\"window.open('http://www.freetellafriend.com/tell/?option=email&heading=Tell+A+Friend&bg=14&url=http%3A%2F%2Fhttp://www.djsmiley.net/index.php?action=show&id={$row['id']}', 'freetellafriend', 'scrollbars=1,menubar=0,width=435,height=500,resizable=1,toolbar=0,location=0,status=0,left='+(screen.width-435)/2+',top='+(screen.height-500)/3);return false;\"><img alt=\"Tell a Friend\" src=\"http://serv1.freetellafriend.com/s14.png\" border=\"0\" /></a> <!-- FreeTellaFriend END --></td> <td width=\"81%\"><span class=\"st_twitter_hcount\" st_url=\"http://www.djsmiley.net/index.php?action=show&id={$row['id']}\" displayText=\"Tweet\" st_title=\"{$row['title']}\"></span><span class=\"st_facebook_hcount\" st_url=\"http://www.djsmiley.net/index.php?action=show&id={$row['id']}\" displayText=\"Share\" st_title=\"{$row['title']}\"></span><span class=\"st_email_hcount\" st_url=\"http://www.djsmiley.net/index.php?action=show&id={$row['id']}\" displayText=\"Email\"></span><span class=\"st_sharethis_hcount\" st_url=\"http://www.djsmiley.net/index.php?action=show&id={$row['id']}\" displayText=\"Share\"></span></td> </tr> </table><br>"; } /* if we aren't displaying all news, * then give a link to do so */ if ($all == 0) { echo "<br><div style=\"border-radius: 10px; border: solid 2px #E5E5E5; padding: 10px; margin: 5px; background: #F6F6F6;\"></p><a href=\"{$_SERVER['PHP_SELF']}" . "?action=all\">View All Articles</a></p></div>"; } } //function for displaying only one item function displayOneItem($id) { global $db; /* query for item */ $query = "SELECT * FROM news WHERE id=$id"; $result = mysql_query ($query); $row = mysql_fetch_assoc($result); /* easier to read variables and * striping out tags */ $title = htmlentities ($row['title']); $news = nl2br (strip_tags ($row['body'], '<a><b><i><u>')); /* if we get no results back, error out */ if (mysql_num_rows ($result) == 0) { echo "This news article does not exist!\n"; return; } echo "<TABLE border=\"0\" width=\"100%\">\n"; /* displays individual article user visits */ echo "<tr><td><strong><h2><a href=\"{$_SERVER['PHP_SELF']}" . "?action=show&id={$row['id']}\">$title</a></h2></strong> <em>posted on $date</em> | by <strong>DJ Smiley</strong></td></tr>\n"; echo "<tr><td>"; echo stripslashes($news); echo "</td></tr>\n"; echo "</table>\n"; echo "<br>\n"; echo ("</table>\n<table width=\"100%\" border=\"0\"> <tr> <td width=\"6%\"><a href=\"{$_SERVER['PHP_SELF']}" . "?action=show&id={$row['id']}\"><img src=\"images/Icons/Comment/2.png\" width=\"20\" height=\"20\" class=\"fltlft2\"/></a>$comment_row[0]</td> <td width=\"13%\"><!-- FreeTellaFriend BEGIN --> <a href=\"http://www.freetellafriend.com/tell/\" onclick=\"window.open('http://www.freetellafriend.com/tell/?option=email&heading=Tell+A+Friend&bg=14&url=http%3A%2F%2Fhttp://www.djsmiley.net/index.php?action=show&id={$row['id']}', 'freetellafriend', 'scrollbars=1,menubar=0,width=435,height=500,resizable=1,toolbar=0,location=0,status=0,left='+(screen.width-435)/2+',top='+(screen.height-500)/3);return false;\"><img alt=\"Tell a Friend\" src=\"http://serv1.freetellafriend.com/s14.png\" border=\"0\" /></a> <!-- FreeTellaFriend END --></td> <td width=\"81%\"><span class=\"st_twitter_hcount\" st_url=\"http://www.djsmiley.net/index.php?action=show&id={$row['id']}\" displayText=\"Tweet\"></span><span class=\"st_facebook_hcount\" st_url=\"http://www.djsmiley.net/index.php?action=show&id={$row['id']}\" displayText=\"Share\"></span><span class=\"st_email_hcount\" st_url=\"http://www.djsmiley.net/index.php?action=show&id={$row['id']}\" displayText=\"Email\"></span><span class=\"st_sharethis_hcount\" st_url=\"http://www.djsmiley.net/index.php?action=show&id={$row['id']}\" displayText=\"Share\"></span></td> </tr> </table>"); /* now show the comments */ displayComments($id); } function displayComments($id) { /* bring db connection variable into scope */ global $db; /* query for comments */ $query = "SELECT * FROM comments WHERE news_id=$id"; $result = mysql_query ($query); echo "<h2>Comments</h2>"; /* display the all the comments */ while ($row = mysql_fetch_assoc ($result)) { //sets variables $comment = strip_tags ($row['comment'], '<a><b&><i><u>'); $comment = nl2br ($comment); $name = htmlentities ($row['name']); $time = ($row['time']); echo "<div style=\"border-radius: 10px; border: solid 2px #E5E5E5; padding: 10px; margin: 5px; background: #F6F6F6;\"><p><table border=\"0\" width=\"100%\"><tr><td><strong>$name</strong> says:</td></tr></table> <table><tr><td><img src=\"images/Icons/People/Anonymous 2.png\" alt=\"\" width=\"50\" height=\"50\"/></td><td>$comment</td></tr></table><table><tr><td>added on $time</td></tr></table></p></div>"; } /* add a form where users can enter new comments */ echo "<form action=\"{$_SERVER['PHP_SELF']}" . "?action=addcomment&id=$id\" method=post> <h2>Comment</h2><table width=\"37%\" border=\"0\"> <tr> <td width=\12%\">Name:</td> <td width=\"88%\"><label> <input type=\"text\" name=\"name\" id=\"name\" class=\"commentBoxforms\"> </label></td> </tr> <tr> <td>Comment:</td> <td><label> <textarea name=\"comment\" id=\"comment\" cols=\"45\" rows=\"5\" class=\"commentField1\"></textarea> </label></td> </tr> <tr> <td> </td> <td><label> <input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Comment\" class=\"Button1\"> </label></td> </tr> </table> </form>\n"; } function addComment($id) { global $db; /* insert the comment */ $query = "INSERT INTO comments " . "VALUES('',$id,'{$_POST['name']}'," . "'{$_POST['comment']}')"; mysql_query($query); echo "Your comment has been posted!<br>\n"; echo "<a href=\"{$_SERVER['PHP_SELF']}" . "?action=show&id=$id\">Return To Previous Page</a>\n"; } /* this is where the script decides what do do */ switch($_GET['action']) { case 'show': displayOneItem($_GET['id']); break; case 'all': displayNews(1); break; case 'addcomment': addComment($_GET['id']); break; default: displayNews(); } ?> Can anyone tell me where this script is going wrong? I've literally tried EVERYTHING. I even went back to the original script and compared every single character to mine, but NO luck. PLEASE HELP! I need to set when new news is posted from 7 days to now, to put echo that it is new.. Code: [Select] while ($var = mysql_fetch_array($result)) { $name = $var['name']; $date = $var['date']; echo " - {$s_name} [new]<br />"; }Now i need to put "[new]" when news is written in past 7 days(1 week), can someone help me? I have manage to create my own script that add news article, however, I would like to add a comment form below the news article. How can I relate the news and the comments? also, when I delete the articles, it should also delete the comments in mysql. Your help is highly appreciated! hi i want to make a script like http://www.greatdane.ru/eng/site/news/ and i dont have problem too add dogs but i want a auto news update after specific change like the link example : after add new dog or update dog or add image to a dog the link tell exactly what i want but also it has a feature that group added dogs and send a news any one have idea for make it? it is also so similar to facebook profile that after user do something page will auto update like : user change his cover |