0

On an inded page on my webite a list of genera each directs to a page /species.php?id=x where x = the id of the genus (genid).
On the species page I want to list the species which are all associated with that genus e.g. if the page is /species.php?id=4 I want to show all the species in my database that have a genid=4.

My current code returns all the species in the database and not just those where the genid=url:

$url = $_GET['genid'];
if ($genid == $url)
{
$query = mysqli_query($connect, " SELECT * FROM desmids ORDER BY species ASC");
$row= mysqli_fetch_assoc($query);
$totalRows_query = mysqli_num_rows($query);
}

I know this is because my query is missing the conditional statement that sets the genid equal to the url id.
So how do I format the WHERE genid='url id'?

I have been stuck on this for ages and I'd really appreciate some help

Thank you

  • 1
    Does this answer your question? [How to include a PHP variable inside a MySQL statement](https://stackoverflow.com/questions/7537377/how-to-include-a-php-variable-inside-a-mysql-statement) – El_Vanja Dec 15 '20 at 15:28
  • `"SELECT * FROM desmids WHERE yourTableField = '".$variable."' ORDER BY species ASC";` // here yourTableField is field that use in you table and $variable is php variable that is you want to fetch from table – Akshay Nayka Dec 15 '20 at 16:29

0 Answers0