By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

How to make display links from mysql database???

P: n/a
Hi i have the following problem and i am breaking my mind on it:
I have a mysql database with (id,title,topic,body) in the database i have
stored some documents.
How can i display a link with only the title of the document stored?(easy
one) but...
I want to view the whole document in the same page!
Let me explain in code:

<?php
$ip = "localhost";
$user = "kostas";
$password = "kostas";
$basename = "test";
$table ="docs";
$db = mysql_connect($ip, $user, $password);
mysql_select_db($basename,$db);
$result1= mysql_query("SELECT * FROM $table ORDER BY id DESC LIMIT 5 ");
$myrow = mysql_fetch_array($result1);
$title = $myrow["title"];
$intro = $myrow["intro"];
$body = $myrow["body"];
?>

So i want the five latest entries to be as links in a blank page and each
time a link is pressed i want to show the whole corresponding document
(title,intro,body) in the same page.
Thanks a lot
ka******@ee.duth.gr
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Kostas wrote:
Hi i have the following problem and i am breaking my mind on it:
I have a mysql database with (id,title,topic,body) in the database i have
stored some documents.
How can i display a link with only the title of the document stored?(easy
one) but...
I want to view the whole document in the same page!
Let me explain in code:

<?php
$ip = "localhost";
$user = "kostas";
$password = "kostas";
$basename = "test";
$table ="docs";
$db = mysql_connect($ip, $user, $password);
mysql_select_db($basename,$db);
$result1= mysql_query("SELECT * FROM $table ORDER BY id DESC LIMIT 5 ");
// if you don't need * choose your fields more judiciously
$myrow = mysql_fetch_array($result1);
// comment line above :-)
while ($myrow = mysql_fetch_array($result1)) {
$title = $myrow["title"];
$intro = $myrow["intro"];
$body = $myrow["body"];
echo '<a href="' . $_SERVER['PHP_SELF'] . '?id=' . $myrow['id'] . '">' . $title . '</a>';
// at this time I'm only using id and title from the DB
} // end while
?>

So i want the five latest entries to be as links in a blank page and each
time a link is pressed i want to show the whole corresponding document
(title,intro,body) in the same page.
Thanks a lot
ka******@ee.duth.gr


and wherever you want the body displayed add:

<?php
if (isset($_GET['id']) && is_valid($_GET['id'])) {
// the is_valid() function I leave up to you
// select body from $table where id=$id
echo $body;
}
?>
--
--= my mail address only accepts =--
--= Content-Type: text/plain =--
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.