Foreach loop problem
Posted: Mon Mar 13, 2006 8:55 am
feyd | Please use
The result returns the first 4 results for the first ID, and then loops through again on the same ID not moving to the next one... so eventually i get the same 4 results x 3 times.
I'm baffeled as the ID's come out of the DB correctly and go into the array correctly too, so there is something wrong with the loop...
any ideas?
Cheers
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Hello, I am having difficulties with a loop...
I am opening a Databse and taking out all records with an ID... there are 3 in this case...Code: Select all
// connecting to a database and getting every record of "ID"
$dblink = mysql_connect("localhost", "user", "pass");
mysql_select_db("db", $dblink);
$query = mysql_db_query ("db", "SELECT ID
FROM table") or die ("Unable to get ID");
// putting each one into an array
$array = array();
while ($row = mysql_fetch_row($query)) {
// moving each one into a seperate location
$array[] = array_shift($row);
}
mysql_close();
foreach($array as $value)
{
if(some conditions) {
// loops through some pattern matching and should return 4 results for each ID
.
.
.
}
}
?>I'm baffeled as the ID's come out of the DB correctly and go into the array correctly too, so there is something wrong with the loop...
any ideas?
Cheers
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]