Here I’m making two queries with PHP. Is there something more simple? One query instead of two?
$id = mysql_real_escape_string($_GET["id"]);
$result = mysql_query("SELECT * FROM questionstable WHERE id=$id");
$row = mysql_fetch_assoc($result);
$category = $row['category'];
$main = mysql_query("SELECT name FROM categorytable WHERE id=$category");
As an aside, assuming your
questionstable.idis numeric, you could use$id = (int)$_GET["id"]and save some writing. (It’s also probably a safer bet. Just because it’s escaped doesn’t mean it’s completely safe–especially when it’s not within quotes [gives you a LOT of options for SQL injection]. ;-))