server query problem
Posted: Wed Feb 20, 2008 11:39 am
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
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