Skip to main content
Participant
November 22, 2009
Question

PHP repeat region not repeating

  • November 22, 2009
  • 1 reply
  • 336 views

Hello,


Not sure if this or PHP application is te right forum so I posted it in both. So I am trying to get Dreamweaver to show all the returned records from my sql query but it only shows the first record even though $totalrows_rs_WineNotes shows up as more.

Here is what the code looks like:

<?php require_once('../Connections/PF_WINE.php'); ?>


<?php

$Wine = $_POST['Wine'];
$Vintage = $_POST['Vintage'];
$Vineyard = $_POST['Vineyard'];
$Varietal = $_POST['Varietal'];
$Appellation = $_POST['Appellation'];
$Producer = $_POST['Producer'];
?>

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;   
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}


$Vintage_rs_WineNotes = "0";
if (isset($Vintage)) {
  $Vintage_rs_WineNotes = $Vintage;
}
mysql_select_db($database_PF_WINE, $PF_WINE);
$query_rs_WineNotes = sprintf("SELECT * FROM WINE WHERE WINE.WINE_VINTAGE = %s", GetSQLValueString($Vintage_rs_WineNotes, "int"));
$rs_WineNotes = mysql_query($query_rs_WineNotes, $PF_WINE) or die(mysql_error());
$row_rs_WineNotes = mysql_fetch_assoc($rs_WineNotes);
$totalRows_rs_WineNotes = mysql_num_rows($rs_WineNotes);


mysql_free_result($rs_WineNotes);
?>

<?php echo $totalRows_rs_WineNotes ?>
<p></p>

<?php do { ?>
  <hr />
  <p><?php echo $row_rs_WineNotes['WINE_VINTAGE']; ?></p>
  <p><?php echo $row_rs_WineNotes['WINE_PRICE_RANGE']; ?></p>
  <p><?php echo $row_rs_WineNotes['WINE_ID']; ?></p>
<p><?php echo $row_rs_WineNotes['VARIETAL_TYPE_ID']; ?></p>
  <?php } while ($row_rs_WineNotes = mysql_fetch_assoc($rs_WineNotes)); ?>

This topic has been closed for replies.

1 reply

David_Powers
Inspiring
November 23, 2009

JoeSmoe_03 wrote:

mysql_free_result($rs_WineNotes);
?>

<?php echo $totalRows_rs_WineNotes ?>
<p></p>

<?php do { ?>
  <hr />
  <p><?php echo $row_rs_WineNotes['WINE_VINTAGE']; ?></p>
  <p><?php echo $row_rs_WineNotes['WINE_PRICE_RANGE']; ?></p>
  <p><?php echo $row_rs_WineNotes['WINE_ID']; ?></p>
<p><?php echo $row_rs_WineNotes['VARIETAL_TYPE_ID']; ?></p>
  <?php } while ($row_rs_WineNotes = mysql_fetch_assoc($rs_WineNotes)); ?>

You're using mysql_free_result(), which deletes the database result from memory, before trying to loop through it.

mysql_free_result($rs_WineNotes); should go right at the end of the script.

BTW, I see you posted a question about this in the Dreamweaver Help pages. Please do not post in two places at the same time. This forum (http://forums.adobe.com/community/dreamweaver/dreamweaver_development) is the appropriate place for such questions.