Jump to content

Recommended Posts

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'); ?>
<?php
mysql_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!!!!
Link to comment
https://forums.phpfreaks.com/topic/16743-mysql-results-problems/
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/16743-mysql-results-problems/#findComment-70410
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.