Author Topic: Loop issue-SOLVED  (Read 207 times)

meerkat746

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Loop issue-SOLVED
« on: August 21, 2010, 10:42:17 AM »
What it is suppose to do: Pull all the rows from the database and populate a dynamic table.
What it is doing: Pulling the same row out of the table and populating the dynamic table with the same information 9 times (same number of fields the query consist of)

Main query:
Code: [Select]
$query_Retrieve = "SELECT Mem_Firstname,Mem_LastName,Mem_MemberID,Mem_Contact_Num1,Mem_City,Mem_BusinessType, Mem_BusinessWeb,Mem_BusinessDescription, Mem_Img_Loc FROM cos_members";
  mysql_select_db($database_cosmo, $cosmo);
  $Table = mysql_query($query_Retrieve, $cosmo) or die(mysql_error());

Table headers:
Code: [Select]
if (($Table)||(mysql_errno==0))
  {
  echo "<table class='list'><tr>";
  if (mysql_num_rows($Table)>0)
 
  {
  echo "<th>Name</th>";
  echo "<th>Surame</th>";
  echo "<th>Member ID</th>";
  echo "<th>Phone</th>";
  echo "<th>Location</>";
  echo "<th>Business Type</th>";
  echo "<th>Web Url</th>";
  echo "<th>Business Description</th>";
  echo "<th>Logo</th>";
   
  echo "</tr>";

The loop
Code: [Select]
while ($rows=mysql_fetch_array($Table,MYSQL_ASSOC))

 //for ($i=mysql_num_rows($Table) {
 {
 echo"<tr>";
 foreach($rows as $data)
 {

//echo '<td>'.$data.'</td>';
echo "<td>".$rows['Mem_Firstname']."</td><td>".$rows['Mem_LastName']."</td><td>".$rows['Mem_MemberID']."</td><td>".$rows['Mem_Contact_Num1']."</td><td>".$rows['Mem_City']."</td><td>".$rows['Mem_BusinessType']."</td><td>".$rows['Mem_BusinessWeb']."</td><td>".$rows['Mem_BusinessDescription']."</td><td><img src='".$rows['Mem_Img_Loc']."'/></td></td></tr>";

 }
// }
 }
 }else{
 echo "<tr><td>No results found!</td></tr>";
 }
 echo "</table>";
 
 }else{
 echo "Error in running query:".mysql_error();
 }

When using
Code: [Select]
echo '<td>'.$data.'</td>'; the loops work properly, except that the image url is displayed instead of the image.

I know the problem is right in front of me, I just over looking it.

Any help would be greatly appreciated.

Solution

Code: [Select]
for($i = 0, $t = count($Table); $i < $t; $i++) {
 {

//echo '<td>'.$data.'</td>';
echo "<td>".$rows['Mem_Firstname']."</td><td>".$rows['Mem_LastName']."</td><td>".$rows['Mem_MemberID']."</td><td>".$rows['Mem_Contact_Num1']."</td><td>".$rows['Mem_City']."</td><td>".$rows['Mem_BusinessType']."</td><td>".$rows['Mem_BusinessWeb']."</td><td>".$rows['Mem_BusinessDescription']."</td><td><img src='".$rows['Mem_Img_Loc']."' width='200' height='80'/></td></td></tr>";

 }
 }
« Last Edit: August 21, 2010, 12:04:12 PM by meerkat746 »