Jump to content

repeating the same record over again, help need please


ltoto

Recommended Posts

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

this is the code

[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);
?>[/code]

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

http://development4.jbswebdesign.co.uk/index.php?Id=20&id=1

any suggestions as to what i can do or change?
Link to comment
Share on other sites

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 [b]while[/b] 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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

[quote author=ltoto link=topic=112437.msg456340#msg456340 date=1161614827]
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
[/quote]

We've all got to lean somewhere. try something like this out (I'm simply combining your two loops):
[code]
<?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";
}
?>
[/code]

does that make sense?
Link to comment
Share on other sites

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...
Link to comment
Share on other sites

[code]
<?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";
?>
[/code]
Link to comment
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.