So I decided a good way to really test my one day old MYSQL skills would be to write a random fact generator that uses a mysql database that stores two columns one is the id of the fact and the other is the fact. I use the php rand() function to generate a random id (between 1 and the highest id). My generated number is working fine and I store it in the variable $rand but the problem comes when trying to get the row with the id of $rand. I use the following query to get the row with the id PHP: $query=mysql_query("SELECT * FROM facts WHERE id='2'") or die(mysql_error()); then a few more lines to get the fact. This works perfectly for a hard coded number but when I try to use the value of $rand it just doesn't work. How do I use a php int in a mysql query? I want something like this PHP: $query=mysql_query("SELECT * FROM facts WHERE id='$rand'") or die(mysql_error()); I'm sure this is easy to do but I just don't know off the top of my head. I tried casting it with int($rand) just got the sake of it but also no luck. Anyone have the solution for using the value of $rand for my id?