brown2005 Posted January 4, 2013 Share Posted January 4, 2013 $domain = $_GET['domain'] ? $_GET['domain'] : ""; if($domain == ""){ $domains_sql = mysql_query("SELECT * FROM domains ORDER BY RAND() LIMIT 1"); }else{ $domains_sql = mysql_query("SELECT * FROM domains WHERE domains_id='$domain' LIMIT 1"); } I was wondering how I get the above code to work? Quote Link to comment https://forums.phpfreaks.com/topic/272700-ifdomain-else/ Share on other sites More sharing options...
Jessica Posted January 4, 2013 Share Posted January 4, 2013 Add an isset() to the first part of that ternary, then tell us what you think it will do if it "works". Quote Link to comment https://forums.phpfreaks.com/topic/272700-ifdomain-else/#findComment-1403240 Share on other sites More sharing options...
brown2005 Posted January 4, 2013 Author Share Posted January 4, 2013 if(isset($domain)) I have tried this? But still does not work? Quote Link to comment https://forums.phpfreaks.com/topic/272700-ifdomain-else/#findComment-1403241 Share on other sites More sharing options...
Jessica Posted January 4, 2013 Share Posted January 4, 2013 Do you know what a ternary operation is? Quote Link to comment https://forums.phpfreaks.com/topic/272700-ifdomain-else/#findComment-1403243 Share on other sites More sharing options...
brown2005 Posted January 4, 2013 Author Share Posted January 4, 2013 $domain = (isset($_POST['domain'])) ? $_POST['domain'] : ""; that what you wanted me to do? Quote Link to comment https://forums.phpfreaks.com/topic/272700-ifdomain-else/#findComment-1403248 Share on other sites More sharing options...
Jessica Posted January 4, 2013 Share Posted January 4, 2013 Well that looks better but why did you go from GET to POST? Is it working the way you expect? I would also use NULL instead of "" but that's more a style factor. Quote Link to comment https://forums.phpfreaks.com/topic/272700-ifdomain-else/#findComment-1403252 Share on other sites More sharing options...
brown2005 Posted January 4, 2013 Author Share Posted January 4, 2013 sorry, did not mean to change that. Changed it back to GET and no it does not do what I want it to do? Quote Link to comment https://forums.phpfreaks.com/topic/272700-ifdomain-else/#findComment-1403255 Share on other sites More sharing options...
Jessica Posted January 4, 2013 Share Posted January 4, 2013 then tell us what you think it will do if it "works". Quote Link to comment https://forums.phpfreaks.com/topic/272700-ifdomain-else/#findComment-1403257 Share on other sites More sharing options...
brown2005 Posted January 4, 2013 Author Share Posted January 4, 2013 sorry it has worked. I had the wrong $here in another part of the script. Quote Link to comment https://forums.phpfreaks.com/topic/272700-ifdomain-else/#findComment-1403260 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.