lexington
12-30-2007, 11:31 AM
Hello, I hope this is easy to do since I cannot figure it out. Basically the mysql DB stores rows of data for example:
name - quantity
bob - 5
jake - 4
sarah - 3
tom - 6
How can I create a php code that selects this info from the DB but duplicates the name by the amount of the quantity? Since you see bob has 5, could it displays bob's name 5 times and then jake 4 times right under it:
bob
bob
bob
bob
bob
jake
jake
jake
jake
and so on. I was able to create something that kinda works but it doesn't continue for every listing only the first one:
$count = $row['quantity'];
$x = 0;
while($x < $count)
{
echo $row['name'] . ' <br>';
$x++;
}
I assume a simple while statement would fix that but I couldn't get it to work. Please help and thanks :)
name - quantity
bob - 5
jake - 4
sarah - 3
tom - 6
How can I create a php code that selects this info from the DB but duplicates the name by the amount of the quantity? Since you see bob has 5, could it displays bob's name 5 times and then jake 4 times right under it:
bob
bob
bob
bob
bob
jake
jake
jake
jake
and so on. I was able to create something that kinda works but it doesn't continue for every listing only the first one:
$count = $row['quantity'];
$x = 0;
while($x < $count)
{
echo $row['name'] . ' <br>';
$x++;
}
I assume a simple while statement would fix that but I couldn't get it to work. Please help and thanks :)
