[RESOLVED] Loop through rows in database?
I have seven records in my table(in one row) in a db and i need to join them together into one $var, so like, $a1.a2.a3.$4...$a7 this is ok. I must need to loop though the columns one by one and make this $var from each row,
I can do it for the first row ok, but it just works for one row at the moment.
Quote:
if ($result=mysql_query($sql)) {
if ($row=mysql_fetch_row($result)) {
$ggg = $row[0].$row[1].$row[2].$row[3].$row[4].$row[5].$row[6];
}
}
Something like 'do while cols are ot empty' sort of thing......
Any ideas?
Re: Loop through rows in database?
change
PHP Code:
if ($row=mysql_fetch_row($result)) {
$ggg = $row[0].$row[1].$row[2].$row[3].$row[4].$row[5].$row[6];
}
to
PHP Code:
while ($row=mysql_fetch_row($result)) {
$ggg = $row[0].$row[1].$row[2].$row[3].$row[4].$row[5].$row[6];
}
And that will go through all of the rows. You can save the values into an array or do whatever you need with them.
Re: Loop through rows in database?
easy, should have got it.