doucie Posted December 18, 2006 Share Posted December 18, 2006 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>";?> Link to comment https://forums.phpfreaks.com/topic/31142-loop-data-into-tables-and-linksnewbie-alert/ Share on other sites More sharing options...
Solarpitch Posted December 18, 2006 Share Posted December 18, 2006 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! Link to comment https://forums.phpfreaks.com/topic/31142-loop-data-into-tables-and-linksnewbie-alert/#findComment-143848 Share on other sites More sharing options...
doucie Posted December 18, 2006 Author Share Posted December 18, 2006 It didn't like line 34(Fatal error: Call to a member function fetch_assoc() on a non-object in C:\wamp\www\Query System\index.php on line 34)Line 34 is while($row = $result->fetch_assoc()) { Link to comment https://forums.phpfreaks.com/topic/31142-loop-data-into-tables-and-linksnewbie-alert/#findComment-143852 Share on other sites More sharing options...
Solarpitch Posted December 18, 2006 Share Posted December 18, 2006 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] Link to comment https://forums.phpfreaks.com/topic/31142-loop-data-into-tables-and-linksnewbie-alert/#findComment-143872 Share on other sites More sharing options...
doucie Posted December 18, 2006 Author Share Posted December 18, 2006 Stumbles at while($row = $result->fetch_assoc()){every time. What does -> mean or do?? I did say newbie!! Link to comment https://forums.phpfreaks.com/topic/31142-loop-data-into-tables-and-linksnewbie-alert/#findComment-143901 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.