hiya im trying to make a section of my website (home page) have 1 section were it will automaticlly update the script each time somebody posts a new post. what i want is it to be just the name updated and then ul be able to click on it to go to the post but i have no clue how to do this. if somebody could help me out ASAP that would be great
UPDATING RECENT POSTS ON HOME PAGE....
Started by dani190, Aug 26 2005 09:24 PM
4 replies to this topic
#1
Posted 26 August 2005 - 09:24 PM
#2
Posted 26 August 2005 - 09:46 PM
Im expecting you know some php so here's a link that will help you out:
http://www.dark-hope...ead.php?t=12139
http://www.dark-hope...ead.php?t=12139
#3
Posted 26 August 2005 - 09:51 PM
ummm yea i kinda know some php but not enough to understand this can you please exsplain
#4
Posted 26 August 2005 - 09:57 PM
Ok....
Open up phpmyadmin if you have it and go to your database and hit SQL, and put this in it:
Now set this for your database things, user,password,host,database. Simple enough, so now save this as config.php
save this as news.php
save this as admin.php
Well your all down, copy this into your ftp server and go to http://www.yourdomain.com/admin.php
and add some news!
note: you may want to rename the admin.php to something harder or password protect it.
Open up phpmyadmin if you have it and go to your database and hit SQL, and put this in it:
CREATE TABLE `news` ( `id` int(11) NOT NULL auto_increment, `title` text NOT NULL, `poster` text NOT NULL, `news` text NOT NULL, `date` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=1;
Now set this for your database things, user,password,host,database. Simple enough, so now save this as config.php
<?php
// Set Database Info
$username="user";
$password="pass";
$host="localhost";
$database = "databasename";
// Connect to Database
mysql_connect($host,$username,$password) or die("Error connecting to Database!" . mysql_error());
mysql_select_db($database) or die("Cannot select database!" . mysql_error());
// Other Variables
$limit_news = 10; // Amount of News articles to display
?>
save this as news.php
<?
include 'config.php'; // Include Config File
$result = mysql_query("SELECT * FROM news ORDER BY id DESC LIMIT $limit_news");
while($row=mysql_fetch_array($result)){
// Echo the Data
echo "<table width='100%' style='border: 1px SOLID #CCCCCC;' border='0' cellspacing='0'>
<tr>
<td bgcolor='#F9F9F9'><div align='center' style='border-bottom: 1px SOLID #CCCCCC;'>$row[title] by $row[poster]</div></td>
</tr>
<tr>
<td>".nl2br($row['news'])."</td>
</tr>
<tr>
<td bgcolor='#F9F9F9'><div align='center' style='border-top: 1px SOLID #CCCCCC;'>Posted on $row[date] </div></td>
</tr>
</table>
<br>";
}
// .nl2br? this is used to create a <br> everytime there is a new line in the mysql code.
?>
save this as admin.php
<?php
include 'config.php'; // Include Config File
$table = 'news'; // Set news table name
$action = $_REQUEST['action'];
if($action == 'add') // admin.php?action=add
{
$date = date("j F Y");
$title = $_POST['title'];
$poster = $_POST['poster'];
$news = $_POST['news'];
$sql = mysql_query("INSERT INTO $table VALUES ('NULL','$title','$poster','$news','$date')");
echo "News has been added.";
}
elseif($action == 'addedit') // admin.php?action=addedit
{
$title = $_POST['title'];
$poster = $_POST['poster'];
$news = $_POST['news'];
$sql = mysql_query("UPDATE $table SET poster='$poster', title='$title', news='$news' WHERE id='$_POST[id]'");
echo "News has been updated.";
}
elseif($action == 'delete') // admin.php?action=delete
{
$sql = mysql_query("DELETE FROM $table WHERE id= '{$_GET['item']}'");
echo "News has been deleted.";
}
else if ($action == 'edit') // admin.php?action=edit
{
$getinfo = mysql_query("select * from $table where id = '{$_GET['item']}' ");
$row = mysql_fetch_array($getinfo);
?>
<div align='center'><form name='form1' method='post' action='?action=addedit'>
Poster:
<input name="poster" type="text" class="textarea" id="poster" value="<? echo $row["poster"]; ?>">
<br>
<br>
Title:
<input name="title" type="text" class="textarea" id="title" value="<? echo $row["title"]; ?>">
<br>
<br>
<input type='hidden' name='id' value='<? echo $row["id"]; ?>'>
<textarea name='news' cols='50' rows='10' wrap='VIRTUAL' class='textarea' id='news'><? echo $row["news"]; ?> </textarea>
<br>
<input class='textarea' type='reset' name='Reset' value='Reset'>
<input class='textarea' type='submit' name='Submit' value='Submit'>
</form></div>
<?
}
else {
?>
<div align='center'><form name='form1' method='post' action='?action=add'>
<br>
Poster:
<input name="poster" type="text" class="textarea" id="poster">
<br>
<br>
Title:
<input name="title" type="text" class="textarea" id="title">
<br>
<br>
<input type="hidden" name="id">
<textarea name='news' cols='50' rows='10' wrap='VIRTUAL' class='textarea' id="news"></textarea>
<br>
<input class="textarea" type="reset" name="Reset" value="Reset">
<input class="textarea" type="submit" name="Submit" value="Submit">
</form></div><br>
<table width="95%" border="0" cellspacing="2">
<tr>
<td bgcolor="#e2e2e2">Title</td>
<td bgcolor="#e2e2e2">Delete</td>
<td bgcolor="#e2e2e2">Edit</td>
</tr>
<tr>
<?php
// Lets show existing news
$sql = mysql_query("select * from $table ORDER BY id DESC");
while($row = mysql_fetch_array($sql)){
echo "<tr><td>$row[title]</td>
<td><a href='?action=delete&item=$row[id]'><strong>Delete</strong></a></td>
<td><a href='?action=edit&item=$row[id]'><strong>Edit</strong></a></td></tr>";
}
}
?>
</table>
Well your all down, copy this into your ftp server and go to http://www.yourdomain.com/admin.php
and add some news!
note: you may want to rename the admin.php to something harder or password protect it.
#5
Posted 26 August 2005 - 10:11 PM
what you mean add news i want it to automaticlly update when somebody creates a new post?
i want the script to automaticlly update when somebody makes a new post on my forum
posts merged
do not double post. Stu
--------
hello can anyone help me with this?
posts merged again
i want the script to automaticlly update when somebody makes a new post on my forum
posts merged
do not double post. Stu
--------
hello can anyone help me with this?
posts merged again
Edited by Donna, 27 August 2005 - 02:30 PM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
