this should be so easy! foreach looping through an array
Posted: Mon Sep 05, 2005 11:41 pm
Hello,
I am simply trying to query a database then spit the results on the screen using foreach. I use PHP Version 5.0.4 on apache2 with winxp
My query brings back 18 lines (user_id) but in my foreach statement it only shows the first record 2x!!
--------------------------------------------------------------------------------------------
$select_distinct = mysql_query("select distinct submissions.user_id from submissions, talent where submissions.talent_id = talent.talent_id and submissions.status='1' order by submissions.user_id desc");
$results = mysql_fetch_array($select_distinct);
$found3 = mysql_num_rows($select_distinct);
print "<p>".$found3." records found</p>";
if (is_array($results)) {print "<p>this is definitely an array</p>";}
foreach ($results as $value)
{
echo "Value: " . $value . "<br />";
}
---------------------------------------------------------------------------------------------------
the screen shows;
----------------------------------------------------------
18 records found
this is definitely an array
Value: 1676
Value: 1676
Help would sure be appreciated. I would like to see al 18 user_id's
thanks!!
I am simply trying to query a database then spit the results on the screen using foreach. I use PHP Version 5.0.4 on apache2 with winxp
My query brings back 18 lines (user_id) but in my foreach statement it only shows the first record 2x!!
--------------------------------------------------------------------------------------------
$select_distinct = mysql_query("select distinct submissions.user_id from submissions, talent where submissions.talent_id = talent.talent_id and submissions.status='1' order by submissions.user_id desc");
$results = mysql_fetch_array($select_distinct);
$found3 = mysql_num_rows($select_distinct);
print "<p>".$found3." records found</p>";
if (is_array($results)) {print "<p>this is definitely an array</p>";}
foreach ($results as $value)
{
echo "Value: " . $value . "<br />";
}
---------------------------------------------------------------------------------------------------
the screen shows;
----------------------------------------------------------
18 records found
this is definitely an array
Value: 1676
Value: 1676
Help would sure be appreciated. I would like to see al 18 user_id's
thanks!!