Jump to content

adding content with the use of the explode function


remybink

Recommended Posts

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.