Jump to content


Photo

mySQL Results problems....


  • Please log in to reply
1 reply to this topic

#1 jlommori

jlommori
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 06 August 2006 - 10:49 PM

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!!!!

#2 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 06 August 2006 - 11:05 PM

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:
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

Then you need to remove this line
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
and rework your code so it looks like this:
?>

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>";
}
?>


Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users