billabong0202 Posted February 20, 2008 Share Posted February 20, 2008 I am new to using php and mysql. For some reason or another query keeps failing. Could somone help me out with my logic. The query is as follows: Separate connect file <?php # mysql_connect.php DEFINE('DB_USER', '*******'); DEFINE('DB_PASSWORD', '********'); DEFINE('DB_HOST', '**********'); DEFINE('DB_NAME', '********'); $dbc=@mysql_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die('Could not connect to MYSQL: ' . mysqli_connect_error()); ?> Code within the webpage <?php require_once('mysql_connect.php'); $qry= "SELECT DISTINCT (restaurant_info.food_type) FROM restaurant_info INNER JOIN restaurants ON restaurants.rest_id= restaurant_info.rest_id WHERE restaurants.delivery = 'yes' ORDER BY food_type ASC"; $result = mysql_query($qry); if (!$result) {die("Query Failed."); }else{ while($row = mysql_fetch_array($result)) { echo '<p>' . $row['food_type'] . '</p>'; } } ?> I don't get an error however it says "Query Failed" every time so i am assuming $results isnt pulling information. However when i run the ( SELECT DISTINCT (restaurant_info.food_type) FROM restaurant_info INNER JOIN restaurants ON restaurants.rest_id= restaurant_info.rest_id WHERE restaurants.delivery = 'yes' ORDER BY food_type ASC; ) query in mysql it pulls the info I need. Thanks for your help i am using mysql 5 Quote Link to comment https://forums.phpfreaks.com/topic/92143-database-query/ Share on other sites More sharing options...
fenway Posted February 20, 2008 Share Posted February 20, 2008 Perhaps because DISTINCT isn't a function? Quote Link to comment https://forums.phpfreaks.com/topic/92143-database-query/#findComment-471982 Share on other sites More sharing options...
billabong0202 Posted February 20, 2008 Author Share Posted February 20, 2008 is it not? the query works in mysql and pulls the info that I need, just not through the website. Quote Link to comment https://forums.phpfreaks.com/topic/92143-database-query/#findComment-472018 Share on other sites More sharing options...
fenway Posted February 20, 2008 Share Posted February 20, 2008 You get query failed? What does mysql_error() say? Quote Link to comment https://forums.phpfreaks.com/topic/92143-database-query/#findComment-472028 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.