Welcome to Our Community

Wanting to join the rest of our members? Feel free to sign up today.

Sign Up

mysqli php select

Discussion in 'Web Design Forum' started by Neil-C, Jan 6, 2011.

  1. Neil-C

    Neil-C New Member

    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

    id, company_title, company_type, company_website, company_email, company_telephone

    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.



    $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) > ) {
        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>";

    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. )

    Thank you.

Share This Page