remybink Posted July 31, 2011 Share Posted July 31, 2011 My products based on category share common features, then I have products where all features are different. right now I have the following code for the features -- in the table is (id, category, feature1, feature2, feature3, ...... feature15) <?php $records = "SELECT * FROM (features) WHERE category='$cat'"; $query_records = mysql_query($records); $num_records = mysql_num_rows($query_records); if ($num_records == 0) { return FALSE; } while($row = mysql_fetch_assoc($query_records)){ echo '<ul class="list">'; $feature = $row['feature1']; if ($feature){ echo '<li>'.$feature.'</li>';} $feature = $row['feature2']; if ($feature){ echo '<li>'.$feature.'</li>';} $feature = $row['feature3']; if ($feature){ echo '<li>'.$feature.'</li>';} $feature = $row['feature4']; if ($feature){ echo '<li>'.$feature.'</li>';} $feature = $row['feature5']; if ($feature){ echo '<li>'.$feature.'</li>';} $feature = $row['feature6']; if ($feature){ echo '<li>'.$feature.'</li>';} $feature = $row['feature7']; if ($feature){ echo '<li>'.$feature.'</li>';} $feature = $row['feature8']; if ($feature){ echo '<li>'.$feature.'</li>';} $feature = $row['feature9']; if ($feature){ echo '<li>'.$feature.'</li>';} $feature = $row['feature10']; if ($feature){ echo '<li>'.$feature.'</li>';} $feature = $row['feature11']; if ($feature){ echo '<li>'.$feature.'</li>';} $feature = $row['feature12']; if ($feature){ echo '<li>'.$feature.'</li>';} $feature = $row['feature13']; if ($feature){ echo '<li>'.$feature.'</li>';} $feature = $row['feature14']; if ($feature){ echo '<li>'.$feature.'</li>';} $feature = $row['feature15']; if ($feature){ echo '<li>'.$feature.'</li>';} echo '</ul>'; } ?> this format is just not suitable. how can i make this easier and versatile for some products i think i will add a "model" to the table and pull data based on "model" on some products. I don't want to have to rewrite the common features for each product, yet, i need to add additional special features. So, can I just add common features into 1 field labeled "common-features" and have additional fields for "additional-features" and then call the field and pass it through "explode" function? Will i be able to add "<li></li>" tags in the output? Quote Link to comment https://forums.phpfreaks.com/topic/243345-adding-content-with-the-use-of-the-explode-function/ Share on other sites More sharing options...
trq Posted July 31, 2011 Share Posted July 31, 2011 You need to look into database normalization techniques. You should have a separate table for features. Quote Link to comment https://forums.phpfreaks.com/topic/243345-adding-content-with-the-use-of-the-explode-function/#findComment-1249652 Share on other sites More sharing options...
remybink Posted July 31, 2011 Author Share Posted July 31, 2011 I do have a separate table for features. I understand normalization. This is a small db so i use unique terms for primary and foreign keys. my question is can the explode function be used to turn the content in table field into an array and then output the result with added <li> tags? Or is there a better method? Or am i stuck entering features field by field? Quote Link to comment https://forums.phpfreaks.com/topic/243345-adding-content-with-the-use-of-the-explode-function/#findComment-1249663 Share on other sites More sharing options...
trq Posted July 31, 2011 Share Posted July 31, 2011 can the explode function be used to turn the content in table field into an array Yes. I still think your database is a terrible design. Anytime your have fields named something1, something2, something3 and so on it screams poor design. Quote Link to comment https://forums.phpfreaks.com/topic/243345-adding-content-with-the-use-of-the-explode-function/#findComment-1249670 Share on other sites More sharing options...
remybink Posted July 31, 2011 Author Share Posted July 31, 2011 That was also part of my question. Because I wanted to grab each feature and apply tags for other purposes this was the only way i thought of doing it and not repeating the data. so i put one feature in each field and the entire column is applied with category to which these features belong this is one table is only for features and nothing else i wanted to use 1 field for common features, 1 field for extra features and apply relation to each category, but i was not sure how to use the explode feature to extract the data. i assume i would need some separator other than space to signal between the key words to which explode would reference as features are not typically one worded. If i knew what i was doing I would not be using this forum i have separate tables for login, items, category, features Quote Link to comment https://forums.phpfreaks.com/topic/243345-adding-content-with-the-use-of-the-explode-function/#findComment-1249678 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.