Hello people,
I'm still quite new to php & mysqli and i am hoping somebody will guide me in the right direction with the situation i'm in at the moment.
I have 2 tables
companies
id, company_title, company_type, company_website, company_email, company_telephone
company_address
id, company_id, street_address, town_city, post_code
What i am wanting to do is use php, to display certain information on a page. e.g, I want to display all pubs in rotherham. But also want to display, the company_title.
I can issue the following query in phpMyAdmin and get the result i desire.
SELECT * FROM companies LEFT JOIN company_address ON companies.id = company_address.company_id
WHERE (companies.company_type = 'pub') AND (company_address.town_city = 'sheffield')
However when i try implementing this query into my php script i'm not getting anything displayed.
Here's my php.
<?php
include("connect.php");
doDB;
$get_sql = "SELECT * FROM companies LEFT JOIN company_address ON companies.id = company_address.company_id WHERE (companies.company_type = '".$_POST["choose_company_type"]."') AND (company_address.town_city = '".$_POST["choose_company_location"]."')";
$get_res = mysqli_query($mysqli, $get_sql) or die(mysqli_error($mysqli));
if (mysqli_num_rows($get_res) > 0 ) {
while ($info = mysqli_fetch_array($get_res)) {
$id = $info['company_id'];
$title = stripslashes($info['company_title']);
$type = stripslashes($info['company_type']);
$town = stripslashes($info['town_city']);
$display_block .= "<h1>".$title."</h1><p>".$type." in <strong>".$town."</strong></p>";
}
mysqli_free_result($get_res);
mysqli_close($mysqli);
}
?>
connect.php works fine with another script that I use to add info to the database so i dont think the problem lies within that.
(I do also have
<?php echo $display_block; ?>
in the body of the page. )
Greatly appreciate any help,
Thank you.