How to make display links from mysql database???

This is a discussion on How to make display links from mysql database??? within the PHP Language forums, part of the PHP Programming Forums category; Hi i have the following problem and i am breaking my mind on it: I have a mysql database with (...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-26-2003
Kostas
 
Posts: n/a
Default How to make display links from mysql database???

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
karbanit@ee.duth.gr


Reply With Quote
  #2 (permalink)  
Old 11-26-2003
Pedro Graca
 
Posts: n/a
Default Re: How to make display links from mysql database???

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
> karbanit@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 =--
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:07 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0