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
https://forums.phpfreaks.com/topic/124039-mysql-data-as-links/#findComment-640418
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
https://forums.phpfreaks.com/topic/124039-mysql-data-as-links/#findComment-640572
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
https://forums.phpfreaks.com/topic/124039-mysql-data-as-links/#findComment-640964
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
https://forums.phpfreaks.com/topic/124039-mysql-data-as-links/#findComment-641221
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.