mysql - php sql syntax, fetching random row w/ includes row with id variable -
apologies not wording title properly. i'm looking pull random mysql id has genre value set electro select * rtsubmissions order rand() `$genretypefix` desc limit 0, 1 fred solved first part, order after where.. still cannot variable work though edit: $sorttype = $_get['sort']; $genretype = $_get['gn']; $genretypefix = "genre='" . $genretype . "'"; if ($sorttype == 'new') { $sql = " select * rtsubmissions order id desc limit 0, 1 "; } elseif ($sorttype == 'genre') { $sql = " select * rtsubmissions `$genretypefix` order rand() desc limit 0, 1 "; } else { $sql = " select * rtsubmissions order played desc limit 0, 1 "; } edit2: removed ` per comment , works, thank-you try this: "select * rtsubmissions $genretypefix order rand() desc limit 0, 1"