jlommori Posted August 6, 2006 Share Posted August 6, 2006 I'm new to using PHP to display mySQL results... I'm trying to display specific items from the DB into a table. The user will fill out a form on the previous page, then the results are sent to the current page via the "POST" method. The problem is, PHP is only display 1 result from the DB, not all the records that it should... here is the code:Within the <head> tag:<?php require_once('../Connections/Products.php'); ?><?phpmysql_select_db($database_Products, $Products);$query_Recordset1 = "SELECT * FROM PRODUCT_PAGES WHERE keyword_color = '$_GET[color]' ";$Recordset1 = mysql_query($query_Recordset1, $Products) or die(mysql_error());$row_Recordset1 = mysql_fetch_assoc($Recordset1);$totalRows_Recordset1 = mysql_num_rows($Recordset1);?>Within the <body> tag:<?php echo "<table border='1'><tr><th>name</th><th>desc</th><th>price</th><th>related1</th><th>related2</th><th>related3</th></tr>";$name = $row_Recordset1['PDCT_NAME'];$desc = $row_Recordset1['PDCT_DES'];$price = $row_Recordset1['PDCT_PRICE'];$related1 = $row_Recordset1['RELATED1'];$related2 = $row_Recordset1['RELATED2'];$related3 = $row_Recordset1['RELATED3'];echo "<tr> <td>$name</td> <td>$desc</td> <td>$price</td> <td>$related1</td> <td>$related2</td> <td>$related3</td> </tr>"; ?>Any suggestions are greatly appreciated!!!! Quote Link to comment https://forums.phpfreaks.com/topic/16743-mysql-results-problems/ Share on other sites More sharing options...
king arthur Posted August 6, 2006 Share Posted August 6, 2006 This isn't really a MySQL problem, it's down to your grasp of PHP programming. You need a while loop to loop through the results returned by the database query.First you don't need this line at all from what I can see:[code]$totalRows_Recordset1 = mysql_num_rows($Recordset1);[/code]Then you need to remove this line[code]$row_Recordset1 = mysql_fetch_assoc($Recordset1);[/code]and rework your code so it looks like this:[code]?>Within the <body> tag:<?php echo "<table border='1'><tr><th>name</th><th>desc</th><th>price</th><th>related1</th><th>related2</th><th>related3</th></tr>";while($row_Recordset1 = mysql_fetch_assoc($Recordset1));{$name = $row_Recordset1['PDCT_NAME'];$desc = $row_Recordset1['PDCT_DES'];$price = $row_Recordset1['PDCT_PRICE'];$related1 = $row_Recordset1['RELATED1'];$related2 = $row_Recordset1['RELATED2'];$related3 = $row_Recordset1['RELATED3'];echo "<tr> <td>$name</td> <td>$desc</td> <td>$price</td> <td>$related1</td> <td>$related2</td> <td>$related3</td> </tr>";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16743-mysql-results-problems/#findComment-70410 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.