Jump to content
xisto Community
Corey

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

Recommended Posts

dtygl: Yes it is possible to do this you just must have more than one WHERE clause.

 

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

146585[/snapback]

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. :rolleyes:

Share this post


Link to post
Share on other sites

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 toThey can be very useful in all sorts of eventualities. I can't remember what they are collectively called (hopefully someone will help out :rolleyes: )They can be used with dates, numbers, variables, times, all sorts of things.

Share this post


Link to post
Share on other sites

I got this error when all was done and done:

Warning: mysql_query(): Access denied for user 'webtodes'@'localhost' (using password: NO) in /home/webtodes/public_html/news/index.php on line 50Warning: mysql_query(): A link to the server could not be established in /home/webtodes/public_html/news/index.php on line 50Warning: 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 :)

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

Share this post


Link to post
Share on other sites

What does it mean if I get this error on news.Php?

___________________________________________

Warning: mysql_query() [function.Mysql-query]: Access denied for user 'levi'@'lotus.X10hosting.Com' (using password: NO) in /home/levi/public_html/news.Php on line 7Warning: mysql_query() [function.Mysql-query]: A link to the server could not be established in /home/levi/public_html/news.Php on line 7Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/levi/public_html/news.Php on line 9

____________________________________________

Where it says levi. That is my username on the server.

Share this post


Link to post
Share on other sites

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)

 

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"

 

<?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"

 

<?phpinclude "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.

 

<?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://forums.xisto.com/no_longer_exists/

 

 

 

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

 

More Free PHP News script you can check out at PHPKode.com

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.