Jump to content

speckytwat

Members
  • Posts

    49
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

speckytwat's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. Ok, think I fixed it, by doing the following: SELECT DISTINCT LEFT (order_discount_code,3) AS vouchercode.... Then pulling $row['vouchercode'] to the variable to put into the option tags. So your DISTINCT LEFT did the trick. Thanks
  2. Thanks, I tried changing the query to exactly as suggested but unfortunately that just makes the SELECT have blank entries in the dropdown: Correct, the order_discount_code can be ABC123, ABC456, ABC789 and so on, it's the ABC that I'm interested in outputting into the dropdown. I thought the blank entries might be because I was using $agencycode in the option tags, but I tried $vouchercode and that did the same...
  3. Hi, anyone know how I can restrict the values displayed in a Select, taken from a MySQL query, which have been edited before output? The original values are all unique so doing a COUNT or DISTINCT in MySQL won't work. This is the PHP I'm using to pull and edit the values: $getusers = $mysqli->query("SELECT order_discount_code FROM orders ORDER BY order_discount_code ASC"); while ($row = $getusers->fetch_assoc()) { $vouchercode = $row['order_discount_code']; //These values are all unique but share common characters e.g the first three characters of the string $agencycode = mb_substr($vouchercode, 0, 3); //I'm doing this as I want to have just the first three characters show in the form Select that contains this query echo '<option>'.$agencycode.'</option>'; } Basically I just want to output unique instances of $agencycode, so if the first three characters might be ABC, DEF or GHI for all the various records, I want ABC to only show once in the Select, DEF to show once, GHI to show once etc. At the moment my code shows a whole long list of every instance. Anyone know how I can do this? Thanks!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.