Jump to content

[SOLVED] Get data by id


demonforce

Recommended Posts

Hi, i am working for a school project atm.

 

It is that i need to keep up with a log each day, so i decited to make it in php.

 

the index is simple, it shows the id from the action, name, date, and a short description.

 

now i want that when i clock the name, i go to a page where you can see more information about it.

 

how can i make it like show.php?=ect....

 

i searchet the internet, but i dont understand it. if someone could help me with it, i bould be verry thanksfull :)

 

 

greetz demonforce

Link to comment
Share on other sites

i guess u want a profile type thing?

 

make ur url like show.php?ID=#

 

in your code, use the $_GET function, to retrieve that number, and your mysql queries should be like, SELECT * From `tablename` WHERE id=ID

the code :

$result = @mysql_query("SELECT * FROM users WHERE id= ID");

$temp = @mysql_fetch_object($result);

$user = $temp;

 

now, you look at your columns in ur mysql,

each value can be called up to the screen by doing this:

 

echo"$user->ID"; would echo their ID, $user->name is their name, etc

Link to comment
Share on other sites

To expand what uwannadonkey said, im giving a simple example:

 

index.php

<?php
$query = @mysql_query("SELECT * FROM logs") or die(mysql_error());
$counter = 0;
while($values = mysql_fetch_array($query)){
     echo $counter . " <a href=\"logs.php?id={$values['id']}\">{$values['name']}<br />";
     $counter++;
}
?>

 

logs.php

<?php
if(isset($_GET['id'])){
     if(!is_numeric($_GET['id'])){
           die('The page doesnt exists');
     }
     $id = mysql_real_escape_string($_GET['id']);
     $query = @mysql_query("SELECT * FROM logs WHERE id='$id'") or die(mysql_error());
     $values = mysql_fetch_array($query);
     echo $values['name'] . "<br />";
     echo $values['action'] . "<br />";
     echo $values['date'] . "<br />";
     echo $values['desciption'] . "<br />";
}
?>

 

Its a simple example which shows what u want to achieve. In index.php i showed all the records of the table where each record is a html anchor that links to logs.php and passed its id in a url variable. In logs.php i used GET to retrieve that variable, sanitized it and made a query filtered with only that id. Guess its a lot more clear now...

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.