SamohtVII Posted April 1, 2013 Share Posted April 1, 2013 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 More sharing options...
fikiwan Posted April 1, 2013 Share Posted April 1, 2013 (edited) 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 April 1, 2013 by fikiwan Link to comment Share on other sites More sharing options...
birbal Posted April 1, 2013 Share Posted April 1, 2013 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 More sharing options...
SamohtVII Posted April 3, 2013 Author Share Posted April 3, 2013 Works fine now. Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now