dink87522 Posted November 28, 2010 Share Posted November 28, 2010 $query = "SELECT * FROM Companies WHERE owner = '$userName'"; $result = mysql_query($query) or die("Error: " . mysql_error()); $count = mysql_num_rows($result); echo("Count: $count<p>"); $result = mysql_query("SELECT name FROM Companies WHERE owner = '$userName'") or die("Error: " . mysql_error()); $result = mysql_fetch_row($result); for ($i=0; $i<=$count; $i++){ // $i<=$count means do while $i is less than or equal to $count /$companyName[$i] = $result[$i]; echo("$i: $companyName[$i]<br />"); echo("$i: $a<br />"); } I am trying to check the number of entries of company names the user has in the table Companies. I am then trying to use a for loop to loop through and store each of those names into an array. It doesn't work and I don't know why, can anyone see my problem? Link to comment https://forums.phpfreaks.com/topic/220037-using-loops-and-dynamic-arrays/ Share on other sites More sharing options...
dink87522 Posted November 28, 2010 Author Share Posted November 28, 2010 ? Link to comment https://forums.phpfreaks.com/topic/220037-using-loops-and-dynamic-arrays/#findComment-1140519 Share on other sites More sharing options...
harristweed Posted November 28, 2010 Share Posted November 28, 2010 Yes, I can see a few error.. why not: $query = "SELECT * FROM Companies WHERE owner = '$userName'"; $result = mysql_query($query) or die("Error: " . mysql_error()); $count = mysql_num_rows($result); echo"<p>Count: $count</p>"; $i=1; while($data=mysql_fetch_array($result)){ echo $i.":".$data['name']."<br />\n"; $i++; } Link to comment https://forums.phpfreaks.com/topic/220037-using-loops-and-dynamic-arrays/#findComment-1140522 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.