Home     Articles & Projects     Products & Web Services     Forum

MySQL Database question

Hi David,

I have gone down the route of adding merchant details and voucher offers for merchants into the PT database. I have it working but wondered if I had done it in the simplist way or made it more compliacted than I needed to!

Fistly I added 2 tables

Voucher with the following fields
vouch_id
merch_id
name
description
deeplink
expires
submitted

merchants with the fields
merch_id
merchant
description
deeplink

to display a list of vouchers from a specific merchant, I first get the merchant info and then get the vouchers from that merchant

  $sql = "SELECT * FROM `".$config_databaseTablePrefix."merchants` WHERE merch_id = '".database_safe($_GET["merch_id"])."'";
  $result = database_querySelect($sql,$rows);
  $merchant = $rows[0];
 
  if ($result){
  print "<table>";     
  print "<tr>";   
  print "<td>".$merchant["merchant"]."</td>";
  print "<td>".$merchant["description"]."</td>";
  print "<td>".$merchant["deeplink"]."</td>";
  print "</tr>";
  print "</table>";
 
  $sql = "SELECT * FROM `".$config_databaseTablePrefix."vouchers` WHERE merch_id = '".database_safe($_GET["merch_id"])."'";
   
  print "<table>";  

  if (database_querySelect($sql,$rows))
  {
    foreach($rows as $vouchers)
    {
      print "<tr>";
      print "<td>".$vouchers["name"]."</td>";
      print "<td>".$vouchers["description"]."</td>";
      print "<td>".teaser($vouchers["deeplink"],50)."</td>";
      print "<td>".date("d M Y", $vouchers["expires"])."</td>";
      print "<td>".date("d M Y", $vouchers["submitted"])."</td>";
      print "</tr>";
    }
  }
 
  print "</table>";

Is there a simpler way to do this?

Thanks,
Simon

Hi Simon, Looks pretty good

Hi Simon,

Looks pretty good to me, they're not going to be big tables so not really worth just extending the existing feeds table (as that is effectively the merchants table) - and this way you don't have to worry about keeping the merchant data if you ever un-register / re-register their feeds...

Cheers,
David.

Thanks David! Compare

Thanks David!
Compare Electricals