Jump to content

mysql data as links


aznjay

Recommended Posts

There is not that much to to it really. Example

if(isset($_GET['id']) && is_numeric($_GET['id']))
{
    $id = $_GET['id'];

    $sql  = "SELECT * FROM table WHERE id='$id'";
    $result = mysql_query($sql);

    if(mysql_num_rows($result) == 1)
    {
        $row = mysql_fetch_assoc($result);

        echo '<pre>' . print_r($row, true) . '</pre>';
    }
}
else
{
    $sql  = 'SELECT id, title FROM table';
    $result = mysql_query($sql);

   while($row = mysql_fetch_assoc($result))
   {
        echo '<a href="?id='.$row['id'].'">'.$row['title'].'</a><br />';
   }
}

As I don't know what you're table structure is, you will need to modify the queries and the $row variables.

Link to comment
Share on other sites

I have the website alltraxx.uni.cc is under construction

 

On the context box of this page I have the code:

<?php
$file = $_GET['page'].'.php';
if (file_exists($file)) {

include $file;


} elseif ($_GET['page'] == '') {


include ("newsinc.php");


} else {

echo ' ERROR';
}
?>

 

Whenever I click on the  http://alltraxx.uni.cc/index.php?id=5  ......   it redirects me back to the news page...it does not load up the data from mysql.

Link to comment
Share on other sites

it's  suppose to show the  data from click the link on my website click on my website and click the link PHP this will show the page phptuts.php and then phptuts.php?id="1" and then it'll  show specific data from that row...but when ever i click that it show the news... coz' i have the if and then script...that's the main problem...

Link to comment
Share on other sites

Here you go:

 

phptuts.php file:

 


<div id="tutorial2">
<?
include 'database.php';

if(isset($_GET['id']) && is_numeric($_GET['id']))
{
    $id = $_GET['id'];

    $sql  = "SELECT * FROM phptut WHERE id='$id'";
    $result = mysql_query($sql);

    if(mysql_num_rows($result) == 1)
    {
        $row = mysql_fetch_assoc($result);

        echo '<pre>' . print_r($row, true) . '</pre>';
    }
}
else
{
    $sql  = 'SELECT * FROM phptut';
    $result = mysql_query($sql);

   while($row = mysql_fetch_assoc($result))
   {
        echo '<a href="?id='.$row['id'].'">'.$row['title'].'</a><br />';
   }
}

?>
</div>
</div>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.