Phaelon Posted May 11, 2014 Share Posted May 11, 2014 Hey all, I'm creating a search page and on it people can search by brand. They can do this by toggling a SELECT OPTION <SELECT> <OPTION>BRAND A</OPTION> <OPTION>BRAND B</OPTION> <OPTION>BRAND C</OPTION> </SELECT> What I am wanting to do is make these OPTIONS dynamic and only include brands that I will actually be carrying. Is there a way to do a lookup on a MySQL table of products and for each different type of data, to generate a <OPTION></OPTION> option for it? Like.. a foreach different type of data. The thing I am having a problem with is that there are several different types of products of the same category, such as 'product 1' and 'product 4' both being T-Shirt's, I don't want to have two options as <OPTION>T-Shirt</OPTION><OPTION>T-Shirt</OPTION>. Can what I want to do even be done?? Link to comment https://forums.phpfreaks.com/topic/288403-creating-a-single-variable-for-multiple-mysql-returns-of-the-same-data/ Share on other sites More sharing options...
Phaelon Posted May 11, 2014 Author Share Posted May 11, 2014 Never mind, I am going to drop this feature. Thanks anyway. Link to comment https://forums.phpfreaks.com/topic/288403-creating-a-single-variable-for-multiple-mysql-returns-of-the-same-data/#findComment-1479059 Share on other sites More sharing options...
Phaelon Posted May 11, 2014 Author Share Posted May 11, 2014 Actually, I would like to get this feature working after all. If anyone could help it would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/288403-creating-a-single-variable-for-multiple-mysql-returns-of-the-same-data/#findComment-1479063 Share on other sites More sharing options...
Ch0cu3r Posted May 11, 2014 Share Posted May 11, 2014 What is you table structure like? If you are storing the product type in a separate column then you can do select distinct, example $result = $mysqli->query('SELECT DISTINCT product_type FROM products'); if($result) { echo '<select name="type">'; while(list($type) = $mysqli->fetch_row()) { echo "<option>$type</option>"; } echo '</select>'; } Link to comment https://forums.phpfreaks.com/topic/288403-creating-a-single-variable-for-multiple-mysql-returns-of-the-same-data/#findComment-1479066 Share on other sites More sharing options...
Phaelon Posted May 12, 2014 Author Share Posted May 12, 2014 Oh, its ok.. I came up with a way: while ($row = mysql_fetch_row($result)) { if (empty($option'.$row['type'].')) { echo '<OPTION>'.$row['type'].'</OPTION>'; $option'.$row['type'].' = 1; } } Link to comment https://forums.phpfreaks.com/topic/288403-creating-a-single-variable-for-multiple-mysql-returns-of-the-same-data/#findComment-1479146 Share on other sites More sharing options...
Ch0cu3r Posted May 12, 2014 Share Posted May 12, 2014 What.. that makes no sense when it is full of syntax errors. Link to comment https://forums.phpfreaks.com/topic/288403-creating-a-single-variable-for-multiple-mysql-returns-of-the-same-data/#findComment-1479218 Share on other sites More sharing options...
Jacques1 Posted May 12, 2014 Share Posted May 12, 2014 There is no sense in this. Phaelon simply has fallen in love with variable variables. // I see you've already found it. Link to comment https://forums.phpfreaks.com/topic/288403-creating-a-single-variable-for-multiple-mysql-returns-of-the-same-data/#findComment-1479221 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.