A self-updating sidebar

I have created a sidebar on my website. I want it to be displaying the titles of 6 of the latest stories from members much like a news update. When the member clicks a title, it loads the story allowing him to comment. At the bottom of the sidebar should be an “older stories” link. The stories and title are stored in a mysql database. Anyone who knows how I can achieve that with php and mysql? Sample codes would help. Thanks in advance.

well it is the same as any other mysql php updater

you have your database

which consist of usually an id,storyname,story,user,date right of your tablename called stories maybe ?
do you have your database

and you would want to connect to the database

here is a basic connection
[php]

<?php $db_host = "localhost"; $db_username = "dbuser"; $db_pass = "dbpass"; $db_name = "dbname"; // Run the connection here $con = mysql_connect("$db_host","$db_username","$db_pass")or die ("Couldn't connect to server."); if (!$con){ die('Could not connect: ' . mysql_error()); } mysql_select_db($db_name, $con); ?>

[/php]

then you would want to all the function that you need to get the data from the tables

[php]

<? $sql = "select * from stories order by date ASC limit 0,3";//limit will give you the 3 latest stories $result = mysql_query($sql1); while ($row = mysql_fetch_array($result)) { echo " {$row[storyname]}
" . " {$row[story]}
" . "User: {$row[user]}
" ; } ?>

[/php]

that will do it for a basic updater you will have to implement that into your sidebar

not tested so let me know

Thanks Cabalsdemon for the help. Here are other problems I would like to solve.

HELP! HELP!

I have created a mysql database which contains the following tables: “stories” and “comments.” The “stories” table has 5 columns among them the “title” and “story” columns. There is a page on my website that has a form whose data is inserted into “stories” table.

I want to achieve the following tasks:

  1. I want the sidebar to show the titles of 5 latest stories in hyperlink form. When a member clicks the hyperlink on the sidebar, a page loads showing the story and the author and date it was posted plus all its associated comments. At the bottom is a form which allows another comment to be inserted.

The problems I am having are:

  1. Establishing a relationship between the “stories” and “comments” tables such that each story is linked to its comments.
  2. Creating a sidebar showing the titles of five latest stories in hyperlink form.
  3. Loading a story and its associated comments.
  4. Allowing a member to insert comment.

ANY HELP WILL BE HIGHLY APPRECIATED. THANKS IN ADVANCE.

[php]

<? $sql = "select * from stories order by date ASC limit 0,5"; //limit will give you the 5 latest stories $result = mysql_query($sql1); while ($row = mysql_fetch_array($result)) { echo " {$row[title]}
" ; } ?>

[/php]

try that for your sidebar

then make a file called stories.php

i have to get to work but i will help you with that page when i get home it is too much for this morning that i can get done

Thanks Cabalsdemon. I look forward to your help. Again thanks.

I did it. Thanks Cabalsdemon for your willingness to help.

your welcome

I know this is an older post, but I was hoping I could crash it because I am looking for something similar, except the side bar aspect doesn’t really matter, I am just trying to have the latest updated documents linked to on the search screen for quicker access. Thanks for the help in advance!

P.S. here is my code
[php]




table { border-collapse: collapse; border: solid 1px black; } td { padding: 2px 6px; border: solid 1px black; } ' method='post'>

Account Code or Company name:

Advanced Search

<?php if(isset($_POST['search'])) { $connx = mysql_connect('localhost', '*****', '*****') or die("connx"); $db = mysql_select_db('*****_*****') or die(mysql_error()); # convert to upper case, trim it, and replace spaces with "|": $search = (ini_get('magic_quotes_gpc')) ? stripslashes($_POST['search']) : $_POST['search']; $search = mysql_real_escape_string($search); $search = strtoupper(preg_replace('/[^a-zA-Z0-9-&\s]/', ' ', trim($_POST['search']))); # create a MySQL REGEXP for the search: $regexp = "REGEXP '[[:<:]]($search)[[:alpha:]]*[[:>:]]'"; $query = "SELECT document_name, description FROM `documents` WHERE UPPER(`document_name`) $regexp OR ". "`document_name` $regexp"; $result = mysql_query($query) or die($query . " - " . mysql_error()); echo "\n"; while($row = mysql_fetch_assoc($result)) { echo ""; echo ''; echo "\n"; } } ?> [/php]

the view-document.php is below:
[php]


table { border-collapse: collapse; border: solid 1px black; } td { padding: 2px 6px; border: solid 1px black; } ' method='post'>

Search for:

Back to Account Code Search

<?php if(isset($_POST['search'])) { $connx = mysql_connect('localhost', '*****', '*****') or die("connx"); $db = mysql_select_db('*****_*****') or die(mysql_error()); # convert to upper case, trim it, and replace spaces with "|": $search = (ini_get('magic_quotes_gpc')) ? stripslashes($_POST['search']) : $_POST['search']; $search = mysql_real_escape_string($search); $search = strtoupper(preg_replace('/[^a-zA-Z0-9-&\s]/', ' ', trim($_POST['search']))); # create a MySQL REGEXP for the search: $regexp = "REGEXP '[[:<:]]($search)[[:alpha:]]*[[:>:]]'"; $query = "SELECT document_name, description FROM `documents` WHERE UPPER(`description`) $regexp OR ". "`document_name` $regexp"; $result = mysql_query($query) or die($query . " - " . mysql_error());
 echo "<table>\n"; 

while($row = mysql_fetch_assoc($result))
{
echo “

”;
echo ‘’;
echo “\n”;
}
}
?> <? $hostname = "localhost"; // $username = "*****"; // $password = "*****"; // $usertable = "*****"; // $dbName = "*****_*****"; // MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable"); @mysql_select_db( "$dbName") or die( "Unable to select database"); ?> <?php if(isset($_GET['docname'])) { // Connect to MySQL // Check docname $docname = mysql_real_escape_string($_GET['docname']); $query = mysql_query("SELECT document_name, description FROM `documents` WHERE `document_name`='" . $docname . "'"); if(mysql_num_rows($query) == 1) { $doc = mysql_fetch_array($query); echo nl2br ($doc['description']); } else { echo 'Document not found!'; } } ?>[/php]
', $row['document_name'], '
’, $row[‘document_name’], ‘
Sponsor our Newsletter | Privacy Policy | Terms of Service