Skip to content Skip to sidebar Skip to footer

How To Use A $result Variable With Table Object In Sql Query Using Mysqli

I am trying to make this code work, but it only works until the second echo statement echo 'Finished 2';. 0){ $sql = 'SELECT * FROM winery WHERE wine

Solution 1:

I think from your winery table you are fetching other table name???

If so you need to fetch row from the $result and then get appropriate column from winery table (i.e. column with other table name).

BTW best option would be joining two tables.

One more point where I think you are making mistake is

$sql = "SELECT * FROM".$result."WHERE wine_type='".$_GET['wine_type']."'";

should be

$sql = "SELECT * FROM ".$result." WHERE wine_type='".$_GET['wine_type']."'";

space between FROM & double quote and between double quote and WHERE

To get winery_id from winary_name you can write your HTML form like

<select name="winary_id">
    <option value="Winary ID HERE">Winary Name Here</option> // you can generate your dynamic options like this which will return id instead of name
</select>

Post a Comment for "How To Use A $result Variable With Table Object In Sql Query Using Mysqli"