Jump to content


Photo

repeating the same record over again, help need please


  • Please log in to reply
7 replies to this topic

#1 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 23 October 2006 - 02:20 PM

well, the code i have below is repeating the same record over and over again, instead of changin the records:

this is the code

<?php
mysql_select_db($database_conTotal, $conTotal);
$query_rsHotels = "SELECT * FROM tabHotel";
$rsHotels = mysql_query($query_rsHotels, $conTotal) or die(mysql_error());
$row_rsHotels = mysql_fetch_assoc($rsHotels);
$totalRows_rsHotels = mysql_num_rows($rsHotels);

$sql="SELECT * FROM tabHotel WHERE regionId = $id";
$result = mysql_query($sql);
if (!$result) {
   die('Invalid query: ' . mysql_error());
}
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
   $name = $row['hotelName'];
   $description = $row['hotelDescription'];
   $rating = $row['hotelRating'];
      $image = "<img src=\"../thumb/phpThumb.php?src=../images/hotel_{$row['hotelImage']}&w=100&h=100&zc=1\"  alt=\"Hotel\">";  

if ($row['hotelRating'] == 3){
$star = "../images/star3.jpg";
}
else if ($row['hotelRating'] == 4){
$star = "../images/star4.jpg";
}
else if ($row['hotelRating'] == 5){
$star = "../images/star5.jpg";
}

?>


<?php

?>
<?php do { ?>
<div class="homebar2"><h1><?php echo $name; ?></h1>
</div>
<div class="hotel"><?php echo $image; ?></div>
<div class="hotelcontent"><?php echo substr($description, 0, 300); ?>...</div>
<h3>Hotel Star: <img src="<?php echo $star; ?>" hspace="2"></h3>
<div class="moreinfo"> <a href="index.php?Id=22&id=<?php echo $row_rsHotels['Id']; ?>"><img src="../images/moreinfo.jpg" alt="moreinfo" width="75" height="18" border="0"></a></a></div>
<?php } while ($row_rsHotels = mysql_fetch_assoc($rsHotels)); ?>
<?php
}
?>
<? 

mysql_free_result($rsHotels);
?>

and here the link to the page it is doing it on:

http://development4.....php?Id=20&id=1

any suggestions as to what i can do or change?

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 23 October 2006 - 02:25 PM

Well, you're running one loop that runs through the entire record set and assigns your variables appropriately, but you're waiting until you are completely done with that loop before you start printing your results out. You need to do one of two things:

1) Echo out your data while you're within your initial loop ... or...

2) Assign your records to an array during your first loop, and echo them out of the array in your second loop

hope this helps
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 23 October 2006 - 02:27 PM

my problem though is, i can find out what the probel is, but i cant write it properly in code....

#4 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 23 October 2006 - 02:47 PM

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
    $name = $row['hotelName'];
    $description = $row['hotelDescription'];
    $rating = $row['hotelRating'];
      $image = "<img src=\"../thumb/phpThumb.php?src=../images/hotel_{$row['hotelImage']}&w=100&h=100&zc=1\"  alt=\"Hotel\">"; 

how would i go about echoing this out then...

sorry im a bit of newb, i kind of understnad when i see it, normally i would look it up, buy ive been put in a rush by the client

#5 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 23 October 2006 - 04:03 PM

sorry im a bit of newb, i kind of understnad when i see it, normally i would look it up, buy ive been put in a rush by the client


We've all got to lean somewhere. try something like this out (I'm simply combining your two loops):
<?php
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
  $name = $row['hotelName'];
  $description = $row['hotelDescription'];
  $rating = $row['hotelRating'];
  $image = "<img src=\"../thumb/phpThumb.php?src=../images/hotel_{$row['hotelImage']}&w=100&h=100&zc=1\"  alt=\"Hotel\">";  

  if ($row['hotelRating'] == 3) {
    $star = "../images/star3.jpg";
  } else if ($row['hotelRating'] == 4) {
    $star = "../images/star4.jpg";
  } else if ($row['hotelRating'] == 5) {
    $star = "../images/star5.jpg";
  }

  // now that you've assigned your variables, echo the record while you're still in the loop
  echo "<div class=\"homebar2\"><h1>$name</h1></div>\n";
  echo "<div class=\"hotel\">$image</div>\n";
  echo "<div class=\"hotelcontent\">" . substr($description, 0, 300) . "...</div>\n";
  echo "<h3>Hotel Star: <img src=\"$star\" hspace=\"2\"></h3>\n";
  echo "<div class=\"moreinfo\"><a href=\"index.php\?Id=22&id=$row['Id']\"><img src="../images/moreinfo.jpg" alt=\"moreinfo\" width=\"75\" height=\"18\" border=\"0\"></a></div>\n";
}
?>

does that make sense?
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#6 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 23 October 2006 - 06:38 PM

i understanding more now, but i got an error from this part of the code

  echo "<div class=\"moreinfo\"><a href=\"index.php\?Id=22&id=$row['Id']\"><img src="../images/moreinfo.jpg" alt=\"moreinfo\" width=\"75\" height=\"18\" border=\"0\"></a></div>\n";

which was

arse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in

after this is done, will have a read through all of this, understand it even more, just that people are making me rush it...

#7 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 23 October 2006 - 06:44 PM

<?php
// this line
echo "<div class=\"moreinfo\"><a href=\"index.php\?Id=22&id=$row['Id']\"><img src="../images/moreinfo.jpg" alt=\"moreinfo\" width=\"75\" height=\"18\" border=\"0\"></a></div>\n";

// should be
echo "<div class=\"moreinfo\"><a href=\"index.php\?Id=22&id=$row[Id]\"><img src=\"../images/moreinfo.jpg\" alt=\"moreinfo\" width=\"75\" height=\"18\" border=\"0\"></a></div>\n";
?>

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#8 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 23 October 2006 - 06:47 PM

do the \ lines make it work in the php quote then i guess, btw, thanks a lot that works fine, i just need to change the link at the bottom now




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users