Jul 26, 2008

Php News Script - how to make news script that uses MySQL writen in PHP

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming
Pages: 1, 2

free web hosting

Php News Script - how to make news script that uses MySQL writen in PHP

Corey
How to make a News script with PHP + MySQL



So..in this tutorial i will explain how to create PHP news script.

first we have to create the table in My SQL..

with the code below you will do this ( you have to enter it into SQL field ..in PHPmyADMIN)

CODE


CREATE TABLE news ( id int(10) unsigned NOT NULL auto_increment, postdate timestamp(14) NOT NULL, title varchar(50) NOT NULL default '', content text NOT NULL, PRIMARY KEY (id), KEY postdate (postdate), FULLTEXT KEY content (content) )





>>>> script files

1 file will show the news ,1 file will contain variables and with the third one we can add news.

we'll call the first file "news.php"

CODE


<?php


$query = "SELECT *," .
"DATE_FORMAT(postdate, '%Y-%m-%d') as date " .
"FROM news ORDER BY id DESC LIMIT $news_limit"; // 1.
$result = mysql_query($query);

while($r=mysql_fetch_array($result)) // 2.
{
echo "<br><table width='100%'><tr bgcolor='$title_cell_color'><td>
<img src='$bullet'><b>$title</b> posted on $date</td></tr>
<tr bgcolor='$news_cell_color'><td>$content</td></tr>
</table><br>";

}

?>



explaination:

1. inlcuding variables into the script

2. selecting the table in the db,formating date, limiting the number of news the script is going to show.

3. now the script is writing the data form db into tables.



now we have to make another file which can add new news into db.

we will call it "add.php"

CODE


<?php
include "var.php"; // 1.
if ($action==add) // 2.
{
$title=$_POST['title'];
$content=$_POST['content']; // 3.
mysql_query("insert into news (title,content) VALUES ('$title','$content')");
echo "<a href='index.php'>Home</a>"; // 4.
}
else // 4.
{
print "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td><form name=\"form1\" method=\"post\" action=\"add.php?action=add\">
<div align=\"center\">
<p>Title:
<input type=\"text\" name=\"textfield\">
</p>
<p>News content :
<textarea name=\"title\" cols=\"50\" rows=\"10\" id=\"title\"></textarea>
</p>
<p>
<input type=\"submit\" name=\"Submit\" value=\"Add\">
</p>
</div>
</form></td>
</tr>
</table>\n";
}


?>



explaination:

1. includeing variables into the script

2. if the $action id add..then the script is going to add data into the db,and if $action isn't selected,then the scipt is gonna show form for adding news.

3. the script is putting the data that we have entered into variables

4. if $action isn't set to "add" the script is showing a form for adding news



this is the third file....we are gonna define all important variables here..and we're gonna make a connection to db.

CODE


<?php
////////////////////////////////////////////////////////////////////////////////////////
$news_limit="xxxx"; // number of news that script shows
$user="xxxx"; // db username
$pass="xxxx"; // password
$db_name="xxxx"; // database name
$bullet="xxxx"; // path to the bullet image
$title_cell_color="xxxx"; // bg color for title cell in RGB...(black = #000000)
$news_cell_color="xxx"; // bg color for news cell in RGB...(black = #000000)
////////////////////////////////////////////////////////////////////////////////////////
$db = mysql_connect("localhost", "$user", "$pass");
mysql_select_db("$db_name", $db); //
?>



You have to change all the variables.



You can download all script files here.

http://tema.trap17.com/php/SNS-php.rar



..if you have some questions are if you have found a mistake in this script...please let me know. (post here)

 

 

 


Reply

hype
Can you put the download file in zip instead of rar? I dont wanna download winrar for that....

Reply

dtygel
Great script Corey!
Two questions:

1) Can I use some change of this script for a newsletter? I mean, is there a way to send the news genterated and stored in the database?

2) Is there a way to generate some reports (search reports) crossing more than one field, like "some words in the subject", and "sent before X day"?

Thanks a lot, I'm a newbie in php!

daniel (from Brasil)

Reply

Corey
QUOTE(hype @ May 18 2005, 02:22 AM)
Can you put the download file in zip instead of rar? I dont wanna download winrar for that....
*



no problem...
here..
http://tema.trap17.com/php/SNS-php.zip


QUOTE(dtygel @ May 18 2005, 03:12 AM)
Great script Corey!
  Two questions:

        1) Can I use some change of this script for a newsletter? I mean, is there a way to send the news genterated and stored in the database?

        2) Is there a way to generate some reports (search reports) crossing more than one field, like "some words in the subject", and "sent before X day"?

      Thanks a lot, I'm a newbie in php!

          daniel (from Brasil)
*



1) yes...but afkors..you have to make some changes ...u have to make a script that pulls the data from db and sends it to users via e-mail

2) ....maybe...don't know it yet..

 

 

 


Reply

karlo
http://www.karlo.ph.tc

On my website, I have a NEWS SCRIPT that I made, with pages support, bbcodes, and RSS feed support. smile.gif

Reply

Van2003ko
Wow very useful infomation will used this in the future..

Reply

rvalkass
On the subject of dtygel's suggestions:

1. Could this be done using the PHP mail() function?

2. A search could be done by asking the user for a search term in a text field and asking what to search in e.g Date, Title etc and also placing that in a variable. Then selecting the appropriate results from the SQL database.

The search could also help with the email, to ensure that only the current months news is mailed.

Just a thought smile.gif

Reply

dtygel
Hi all,

rvalkass and corey showed a way, but I'm a terrible programmer (sorry...), so I would prefer to find some solution. My problem is the following: I'd like to send "automagically" the latest news in my website (which is still under construction smile.gif ); and also, I would like to let the user make some searchs on the news sent in the past. I took a look at karlo's site, but didn't find the news script he mentioned.

Now, about using the mail() function: wouldn't I be limited to the hourly limit in the server of e-mails sent? Or is the mail() function out of this account? Would it be better to use, say, the phplist software?

Thanks folks: I'm understanding a little bit more about php since I came accross this topic wink.gif

Daniel

Reply

rvalkass
As the mail() function sends emails from an address you specify I belive you would be limited to the servers limits. I belive that PHPList also uses the mail function so would have the same problems. I think a mySQL query soemthing like the one below would allow for a search funtion:

CODE

mysql_query("SELECT title, content FROM news WHERE title='$search' ");


This would get all news entries where the title is equal to the search term. The variable $search would be a text box containing the search term. I may have got this code wrong, so please correct me. I am also unsure of whether the term has to exactly match that in the database, or just contain it. Everyone, please feel free to correct me or change this code. Thanks.

Reply

dtygel
Great, Valkass!
Thank you for the answers.

Well, how do I get rid of the servers limits? Can mailman do that? Or should I contract a mailing service? (some suggestion?)

About the script: that was a suggestion of a simple search. I would like to give the user the possibility to cross between fields (maybe the AND syntax...): a cross-fields search.

Daniel

Reply

Latest Entries

iGuest
The zip and rar files are no longer available to download. Any chance of putting them back up?

Reply

Spectre
Because you aren't specifying a password: '(using password: NO)'. Did you notice how old this thread was?

Reply

skter4938
I got this error when all was done and done:

CODE
Warning: mysql_query(): Access denied for user 'webtodes'@'localhost' (using password: NO) in /home/webtodes/public_html/news/index.php on line 50

Warning: mysql_query(): A link to the server could not be established in /home/webtodes/public_html/news/index.php on line 50

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/webtodes/public_html/news/index.php on line 52


and the username was webtodes_admin in the var.php file dry.gif

Why does it give me this error, even though I put in a different username?

Reply

rvalkass
The <= thing means less than or equal to. There are loads of them used in all programming languages. Some of the most common ones are listed below:

< less than
> greater than
<= less than or equal to
>= greater than or equal to
== exactly equal to
!= not equal to

They can be very useful in all sorts of eventualities. I can't remember what they are collectively called (hopefully someone will help out smile.gif )

They can be used with dates, numbers, variables, times, all sorts of things.

Reply

karlo
QUOTE(Shawn @ Jun 1 2005, 11:35 PM)
dtygl: Yes it is possible to do this you just must have more than one WHERE clause.

CODE

$query = "SELECT * FROM `news` WHERE `timestamp`<='$searchDate' AND `text` LIKE '$searchString'";

*


Hmmm.. that's a new function of MySQL for me. The <= thing in the query is new to me. Where did you learn to use it? Because all i know is the basic MySQL things, as in basic. sad.gif

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Pages: 1, 2
Recent Queries:-
  1. news script with images - 12.85 hr back. (1)
  2. news script uses mysql - 37.76 hr back. (1)
  3. php news script mysql - 37.98 hr back. (1)
  4. make a simple php news script - 50.50 hr back. (1)
  5. how to make a php news script - 54.03 hr back. (1)
  6. simple news script php mysql - 56.15 hr back. (1)
  7. php latest news script - 64.64 hr back. (1)
  8. php news script - 22.46 hr back. (2)
  9. simple php news script - 102.43 hr back. (1)
  10. php mysql news script - 105.35 hr back. (1)
  11. php without mysql news script - 133.64 hr back. (1)
  12. php mysql crossing table data - 133.67 hr back. (1)
  13. "php news script" - 134.46 hr back. (1)
  14. php news article making script - 145.58 hr back. (1)
Similar Topics

Keywords : php, news, script, make, news, script, mysql, writen, php

  1. Php Guest Online Script
    (2)
  2. How To Make A View New Post Script?
    (5)
    Ok so i'm still working on the forum software i posted about a while back, but I have no idea
    how to do this. I want to make a view new post script, as this is one of the main things that my
    forum software dose not have that all other forums have. so does any body have an idea on how i
    would do this? Thanks.....
  3. Guessing Php Script
    (0)
    I am looking for: freeware php quess the person in the photo game script....
  4. Create Table - Mysql Code - Help
    (1)
    I need your feedback about setting the database issues. Please, review them and correct some entries
    in the code if they got some mistakes. This is the code itself: SQL CREATE TABLE
    `news` ( `id` int(250) NOT NULL auto_increment, `title` varchar(255)
    NOT NULL default '', `text` text NOT NULL, `author` varchar(255) NOT
    NULL default '', `valid` varchar(255) NOT NULL default '',
    `date` varchar(255) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE = ....
  5. Mysql Error
    (3)
    ok i need some more help from the wonderful coders here at Trap. I'm almost done with my CMS
    script, but i'm having a problem with the installer.php file, when it trys to inseret the user
    data into the database i keep getting the following error: CODE mySQL Error: 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 ';INSERT INTO `members` (`id`, `name`,
    `username`, `password`, `email`, `title`) ' at lin....
  6. Sending E-mails After News Update?
    Coding needed?!? (8)
    I need the following code or the idea how to reach this concept. Let's say, I have a database
    entry which is called "news", where all of the news stories are stored. If this database entry got
    modified, like the new post was added to the web-site by an administrator, the registered users will
    get some kind of email notification automatically, I mean the mails are sent automatically without
    the interaction of someone else. ....
  7. Html Form!
    Using MySQL?! (4)
    Hey, I need your help again! I need some good working tutorial how I can update my SQL through
    HTML form. I did use some tutorials online found with the help of google; but they do not work
    properly; I mean there are still small mistakes. I need to have a good tutorial to follow. It
    should be based on security and more things. It has to be done in proper way.......
  8. Best Php And Mysql Editor For Noobs
    anyone any php or mysql editor that is good for noob (6)
    hi there guys, from my previous posting, i am a noob in php and mysql programming. I want to know
    if there are any php and mysql editors which are best for me as a noob. i appreciate your kindness
    ....
  9. Php And Mysql Programming
    anyone knows a code for mysql and php (2)
    hi everyone! I am making a program using php and mysql...I am a noob on this so i need your
    help guys...I want to make a simple program that will some values and then store them on a database
    and then retrieve them...uhmm let me give an example out put of what i need. This is the example
    say..: Enter First Name: Enter Last Name:
    Enter Age: Enter Address: ..those
    are the data needed for input values...my question now is how can I make a database....
  10. Need Help Installing Dolphin Community Script!
    (5)
    I'm not sure if this is the right place to post this but I really need help in installing the
    dolphin community script. I have absolutely no previous experience of scripts or programming. I
    would really appreciate if someone could walk me through it step-by-step, or even do it for me by
    logging into my cpanel. I have tried to install it my self but I'm a little confused. I'm
    sure it won't take very long at all for someone who has done this before.....
  11. How Do I Connect To Live Database With Php Script?
    while being hosted with ComputingHost (6)
    I am not new to programming. I want to create a form to add some values into my tables, the code
    are all working. But I am not sure what is the URL to connect to my site's database. All along,
    I have been testing through MAMP, which provides a local copy of mySQL. Can anyone lend me a hand?
    My site's URL is http://limetouch.com/ ....
  12. Best Sites For Learning Php-mysql
    (4)
    Hi I was reminded of this earlier by a post in a topic, meant to post it but forgot and the topic on
    php books reminded me. Well anyway there is tyhschools for learning php (unless someone else knows
    a better 1) but I wan't to know what is the best site for using php with mysql (using
    phpmyadmin) also whats the difference between postgresql and mysql? though I must admit the
    postgresql version of phpmyadmin whatever it's called looks better (visually)!....
  13. Tools Needed!
    PHP & MySQL (9)
    Hello, everyone! I need some tools for those two things to test PHP scripts coming together with
    database on my laptop, instead checking them on a web-server which takes time.....
  14. Download Script For Mp3 Files
    (0)
    Hello, I'm looking for a download script for sound files (e.g. mp3, avi, wma, and other ones).
    i have found a few download scripts but they would not work for sound files for some reason. also
    this will not be used for allowing downloading of illegal or riped music, what i will be using this
    script for is i'm making a site for my church and the pastor wants to be able to recored the
    services and then have me upload them to the site so that the church members can download them for
    what ever reason. If some one could tell me how to make one or could show me a plac....
  15. Php Rediret Script
    (12)
    Ok, what I am trying to do is this. Re-direct a domain name called: avalon.asn.au to
    preschool.stmarksavalon.org.au I have created a script that will re-direct within the a folder.
    However, the avalon.asn.au and stmarksavalon.org.au are PARKED Domains. Any ideas on how to create
    this PHP Redirect Script please?....
  16. Forum Script
    (3)
    Hello, i'm wanting to start making my own forum software but i dont know where to start or what
    i need to know in order to do this. I know i will need php and mysql but what else, and could some
    one point me to a good site were i could learn php and mysql. Thanks ....
  17. Library Script
    Where? (6)
    Hello, everyone. Anyone knows where I can get a library script that acts like CMS script software,
    you can add books or delete them. I want to build virtual online library which can be accessible to
    everyone. Or just give me some advices how to make it build. I'm a novice in programming.....
  18. Script Help Required: Undefined Variable
    A fault I cannot spot in PHP (3)
    Hi, when running a PHP script I keep getting the error: QUOTE Notice: Undefined variable: bret
    in c:\program files\easyphp1-8\home\poll.php on line 294 Notice: Undefined
    variable: bret in c:\program files\easyphp1-8\home\poll.php on line 294 (And,
    yes, I get it twice). The code related to the variable is as follows: CODE function
    LogString($string,$type)     {         $t_log = "\n";
            $t_log .=
    $this->globaldata->server_vars['REMOTE_ADDR']."....
  19. Mysql Won't Update
    (4)
    Ok, so I'm making some arcade administration software so I don't have to add games the hard
    way, well anyway, one of the features I have is that on the homepage is a featured author and as
    such I just have it so it updates one line in the mySQL. Well, the page with the form passes on the
    varibles fine and the updating page recieves them because I echoed everything, then I build the
    query and I even echo the query and it comes out exactly how I want it to, but for some reason, the
    database itself won't update even though all the varibles are there. Here's....
  20. Html Code Tester. Online Script
    (15)
    Yes, yes. I have another script that I have written and I am distributing. I am not entirely sure if
    this works. I have not tested it yet, but I will later and post back with a demo and fix it up.
    Current script: CODE <?php //Save this as something like htmltest.php function
    CheckForm() { $html_unsafe=$_POST['code']; //Gives us our user
    input $html_safe=str_replace("<?php"," ",$html_unsafe);
    //Starts security measures $html_safe=str_replace("?>","
    ",$html_sa....
  21. Creatting A Playlist Through Php
    script help needed (5)
    Hi I am trying to make a script so that i can insert songs into a playlist, but i need a script in
    which it opens the playlist file and removes the closing tag at the end, so before i can add more
    entrys. e.g CODE <atx> <entry>Location 5</entry> <entry>Location
    4</entry> <entry>Location 3</entry> <entry>Location
    2</entry> <entry>Location 1</entry> <atx> But to add more entrys
    i would have to get rid of the atx, then use the fputs to place the new entry into the file. ....
  22. What Kind Of Script Do You Need ?
    post here and get free script (15)
    Hi everybody sorry if i posting here , i know I want design free PHP script and i dont know
    webmasters what kind of scripts want i think its better to aks here becuase trap17 is very nice
    webmasters forum So , Plz post here what kind of script with details you need ! sorry may en
    is not very well for example you need "upload center" : write "upload center" with upload center
    options ( like Ajax , Fast , multi lan and ... ) with this post we can give script details and
    webmasters idea /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.....
  23. Wappy Buddy V1.10 - Tibia Gold Edition By Wappy & Jon Roig
    the official wap download script (3)
    By downloading this script you are agreeing to the license and terms outlined below /biggrin.gif"
    style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> QUOTE /** * *
    @package: wappyBUDDY - Tibia Gold Edition * @version: 1.10 2006/10/01 00:00:01 wappy * @copyright:
    ©2003, 2006 jon roig, wappy * @release notes: this is the first official release of my download
    script despite pirate and incomplete copies floating around that were stolen from one of my previous
    servers. The next release will follow very shortly * @terms: wappyBUDDY is free softw....
  24. Free Auction Script
    Any Suggestions? (6)
    Any free auction script suggested? I want it to be as many practical functions as possible, yet
    easy to manage. And more importantly, it is free! Appreciate your kind suggestions!....
  25. Watermark Your Image With Simple Php Script
    found it on the net (34)
    This script was found on the net http://tips-scripts.com/?tip=watermark#tip B&T's Tips &
    Scripts site. Just in case the site may not show, I will include the code here: List of things
    needed: 1. your image in any format 2. watermark image--in gif format with transparent background 3.
    script below with name (i.e. watermark.php) CODE <?php // this script creates a watermarked
    image from an image file - can be a .jpg .gif or .png file // where watermark.gif is a mostly
    transparent gif image with the watermark - goes in the same directory as this script // ....
  26. Creating Profiles In Php/mysql ?
    (7)
    i've started to learn php..im familiar to basics of php and mysql now.Now for example i want
    that some user can register to my website , and after that he can Login and log out , and he can see
    his profile.is there any tutorial about this ? or any helping url .. or any helping answer please
    /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />....
  27. Can You Add Images Into A Mysql Database?
    Using Php? (20)
    I'm learning php in class right now, but I'm still not that good at it, what I'm
    wondering is when I write the php so that it can connect with a database, can I at the same time
    have it that it is able to display back images that I choose. Like, I want a search feature, where
    you can search for a keyword, and it will bring back a list of all the possible entries with that
    keyword, but each of these entries will have a photo associated with it. Now, do I put these image
    files directly into the database, or do I write the code to link them from my files to th....
  28. Parse: Error Unexpected T_lnumber
    php parse error when running script (4)
    Hi. I've just created a php script. The main object of the script is to delete some old files
    and replace it with a new file with some new content, effectively moving the contents from one file
    to another. These are the first 50 lines of the file: /* Calculate For The "A" Group - The
    Latest Games ID */ $a_B = 002; while(file_exists("a_" . $a_B . ".dat")) {
    $a_B++; } $new_page_contents = " " . $_POST . " " . $_POST . "
    include \"/home/cmatcme/public_html/footer.php\"; ?> "; $a_stream = fopen(&....
  29. Increment A Mysql Column
    how to increment a MySQL column one unit (6)
    Hi, I have a column in a MySQL table which contains a counter of the views of the object described
    by this table. I would like to increment this value by one everytime the object is viewed. Obviously
    came into my mind the possibility of retrieving the value of this field, store it in a variable
    increment this value by one and perform an UPDATE query again with this new value. My question is if
    there is a MySQL option to update the field with its actual value plus an unit increment. I hope you
    understand the issue.....
  30. Script: Php Jukebox
    A one file script! (4)
    This scripts is so simple, you dont need to edit ANY of it! All you have to do is make a folder
    called 'songs' and put some audio files in it. Here is the whole page, I named it index.php
    and put it in a folder called 'music': CODE <!DOCTYPE HTML PUBLIC
    "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd"> <html> <head>
    <title>PHP jukebox</title> </head> <body> <!-- ©2005 Craig
    lloyd. All rights reserved. Visit cragllo.com for more sc....

    1. Looking for php, news, script, make, news, script, mysql, writen, php

Searching Video's for php, news, script, make, news, script, mysql, writen, php
advertisement



Php News Script - how to make news script that uses MySQL writen in PHP



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE