Jump to content

SELECT WHERE 'variable'


SamohtVII

Recommended Posts

I am trying to get an ID from one table and use it to search another table.So I have one query traversing a table:

$sql = "SELECT * FROM `posts` ORDER BY `date` DESC";

How can i set the ID of the posts table to a variable and then say:

$sql2 = "SELECT * FROM `comments` WHERE ID = IDVARIABLE";

Thanks

Link to comment
Share on other sites

We can select id like this

if (isset($_GET['idvar'])){		$idvar = $_GET['idvar'];}else{	 echo"ID NOT DETECTION";}//QUERY DATA$q = "SELECT * FROM comments Where id = '$idvar'";

<a href = exam.php?idvar=<?=$listid?> >Per ID  </a>   <!-- GET IDVAR FROM HERE -->

Edited by fikiwan
Link to comment
Share on other sites

you need to use join for thathttp://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0CDIQFjAA&url=http%3A%2F%2Fdev.mysql.com%2Fdoc%2Frefman%2F5.0%2Fen%2Fjoin.html&ei=sFlZUYzUJYLqrQfGyIDIDA&usg=AFQjCNGXZQycUZ9UHnvO4i2-l6UslF5wRA&bvm=bv.44442042,d.bmk

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...