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 (...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 =-- |