0

0 down vote favorite

I have a table in database like this:

ID, features, Values : ID will be 1, 2, 3.... features will be color, size, material.... values will be red, 13inch, silicon...

I stored it like this:

ID

1
1
1

Features
color
size
material

values
red
13in
silicon

and it continues for product 2... . I am trying to display it in tabular form which i am not getting.

Actually it has to go to next row when id -2 comes... but it keeps on displaying in the same row....

can somebody tell me how to do it?

I tried like this

if(isset($_POST['submit']))

{
$id = $_POST['id'];

$test = "SELECT id, features, values FROM mytable WHERE features IN ('color', 'size', 'material') AND id IN (" . implode(',',$id) .")";
$result = mysql_query($test) or die (mysql_error());
echo "<table width='100%'>";
echo "<tr><th>color</th>
<th>size</th>
<th>material</th></tr>";
echo "<tr>";
while ($row = mysql_fetch_assoc($result)) {

    echo "<td>".$row['values']."</td>";


} 
echo "</tr>";
echo "</table>";
}

and it continues for product 2... . I am trying to display it in tabular form which i am not getting.

Actually it has to go to next row when id -2 comes... but it keeps on displaying in the same row....

can somebody tell me how to do it?

2
Contributors
2
Replies
24
Views
3 Years
Discussion Span
Last Post by my3h
0

are you planning to store id, features and values, as an array (exploded to string or not)?
This is a bad idea.
better is to have 2 tables:

product:
id,
name,
...

product_features:
id, -> primery key (autoincrement)
product_id, -> forenkey -> the id from the product table
feature, -> the name of the feature
value -> the value of the feature

your exampel gives:
product:
 1,   redball
and 3 rows of product_features:
 1,   1,  color,   red     
 2,   1,   size,    13inch
 3,   1,  material,  silicon
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.