Jump to content

Loop data into tables and links(newbie alert!)


doucie

Recommended Posts

OK, I need to get all the results from the database and enter into a table, which the code below does quite nicely, however, I need one of the fileds to be a link in each row.  How do I change the loop??



$query="SELECT query_number, query_type, query_status, client, client_ref, debt_ref, query_date, user
FROM query
ORDER BY query_number";

$results=mysql_query($query)
or die(mysql_error());

echo "<table width=\"100%\" border=\"3\" align=\"center\" bordercolor=\"#000099\" cellspacing=\"0\" cellpadding=\"5\"
<tr><td>Query Number</td>
<td>Query Type</td>
<td>Status</td>
<td>Client</td>
<td>Client Ref</td>
<td>DebtRef</td>
<td>Date/Time Entered</td>
<td>User</td>
</tr> ";

while ($row=mysql_fetch_assoc($results)){
echo "<tr>";
foreach($row as $value){
echo "<td>";
echo $value;
echo "</td>";
}
echo "<tr>";
}
echo "</table>";
?>

Try Something like...

[code]
while($row = $result->fetch_assoc())
  {
 
 
  echo "<tr  >";
 

echo "<td></td>";

  echo "<td>" . $row['Column_name_1'] . "</td>";
  echo "<td>" . $row['Column_name_1'] . "</td>";
  echo "<td>" . $row['Column_name_1'] . "</td>";
  echo "<td>" . '€' . $row['Column_name_1'] . "</td>";

  echo "<td'><a href=\"newpage.php?member=". $row['database_id'] ."\">Next Page</a></td>";

  echo "</tr >";
 
  }
[/code]

This code might be missing a bracket or two so I wouldnt recommend a copy and paste job!

Heres some code the way I implement it. This code works for me.

[code]

$mysql_connect = new mysqli("localhost", "root", "password");
$mysql_connect->select_db('myDatabaser');

$result = mysqli_query($mysql_connect, "SELECT * FROM Table ");

while($row = $result->fetch_assoc())
{

  echo "<tr>";
  echo "<td>" . $row['header'] . "</td>";
  echo "<td>" . $row['offwant'] . "</td>";
  echo "<td>" . $row['price'] . "</td>";
  echo "<td>" . $row['class'] . "</td>";

  echo "<td><a href=\"newpage.php?member=". $row['member_id'] ."\">View New Page>></a></td>";

  echo "</tr >";

  }

echo "</table >";
}

[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.