Jump to content

database query


billabong0202

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/92143-database-query/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.