I don't even know anymore.

thanks anyway

Member Avatar


OK, from what I can get my head around, you could do something like this:


require 'db_connection.php';

$whereString = ' WHERE c.cat_type != 1';
$sql = 'SELECT * FROM deals AS d INNER JOIN categories AS c INNER JOIN x AS cities ON d.cat_id = c.cat_id';

//Check Login
if(isset($_SESSION['user_id'])) $whereString = '';

//Check Category ID passed
    $cat_id = intval($_GET['cat_id']);
    $catIdCondition = ' d.cat_id = ' . $cat_id;
    $whereString .= ($whereString) ? ' AND' : ' WHERE';
    $whereString .= $catIdCondition; 

//Check City ID passed
    $city_id = intval($_GET['city_id']);
    $cityIdCondition = ' d.city_id = ' . $city_id;
    $whereString .= ($whereString) ? ' AND' : ' WHERE';
    $whereString .= $cityIdCondition;  

$sql .= $whereString;

echo $sql;

$result = mysql_query($sql); 
    $content = '<h3>Sorry, no deals at present</h3>'; 
    $content = '<table><thead><tr><th>Value</th><th>Discount</th><th>Deal Amount</th><th>You Save</th></tr></thead><tbody>';
    while($data = mysql_fetch_array($result))
        $content .= "<tr><td>{$data['deal_actual_amount']}</td><td>{$data['deal_percentage']} %</td><td>{$data['deal_deal_amount']}</td><td>{$data['deal_saving_amount']}</td></tr>";
    $content .= '</tbody></table>';

<!doctype html>
<div id="content">
    <?php echo $content;?>

I realise that I'm not using your user-defined functions like deal_fetch etc, but I've used what I think are the mysql_* equivalents.
I've included three tables in the SQL statement:

categories, deals and cities

I'm assuming that they're all linked by the usual Primary Key/Foreign Key.
That should give the output required in the table you showed in the last code block.

Well Sir I have been living in Mr.and Mrs. PHP and SQL 's home the last two days. Reading and trying different angles to the code above with no success.

First off, no insult to you. That bit above taught me about joins and conditional statements and much more. And I'm still looking at it.

In any case, it doesn't appear to have primary / foreign keys.

SELECT * FROM ig_deals AS d INNER JOIN ig_categories AS c INNER JOIN x AS ig_city ON ig_deals.shop_id = ig_deal_shops.shop_city_idWHERE ig_category.cat_type != 1 AND ig_deals.deal_category = 4
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in all_deals.php on line 42

$sql = 'SELECT * FROM ig_deals AS d INNER JOIN ig_categories AS c INNER JOIN x AS ig_city ON ig_deals.shop_id = ig_deal_shops.shop_city_id';

41.  $result = mysql_query($sql);
42.  if(!mysql_num_rows($result))
Member Avatar


No sorry there aren't any - I wasn't sure what they were called, so I left them out intially and forgot to include some dummy fields on posting :(