You need to give everythign a Unique ID (Autoinremement field called aid or somethign)
//Maxrows being the number of adverts in the table
$rand = rand(0,$maxRows);
Then you can do
$query = "SELECT * FROM $tablename WHERE aid = '$rand'";
//get it
$query = "UPDATE $tablename set whatever=whatever WHERE aid='$rand'";
Probably a better way, but that'll work.