0

So here's what I want.. When user clicks on some link e.g. http://www.keevik.com/vicevi.php?id=24 that script prints out only that single id.

Here's my code

    /* Get data. */
$sql = "SELECT * FROM $tbl_name ORDER BY id DESC LIMIT $start, $limit";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
    {
    echo "<a href ='vicevi.php?id=".$row['id']."'>".$row['id']."</a>";
    echo "<br>";
    echo nl2br($row["VicText"]);
    echo "<hr>";
    }

So, when I click on some link it doesn't do what I actually want :S

3
  • 1
    Add a where clause WHERE id=$id and get it from $_GET['id']; Commented Apr 23, 2013 at 12:21
  • 2
    ... and escape it properly ;-) Commented Apr 23, 2013 at 12:23
  • this is the code of the page where you display the list. What's in the page where you display an item detail ? Commented Apr 23, 2013 at 12:24

1 Answer 1

4
$sql = "SELECT * FROM $tbl_name ORDER BY id DESC LIMIT $start, $limit";
if(isset($_GET['id']))
{
    $id=intval($_GET['id']);
    $sql = "SELECT * FROM $tbl_name WHERE id=$id";
}
$result = mysql_query($sql);
if(!$result)
{
    echo 'no data found!';
}
else
{
    // etc..
}
Sign up to request clarification or add additional context in comments.

1 Comment

lookup mysql_real_escape_string() but I suggest moving to mysqli

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.