ltoto Posted October 23, 2006 Share Posted October 23, 2006 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]<?phpmysql_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=1any suggestions as to what i can do or change? Quote Link to comment Share on other sites More sharing options...
obsidian Posted October 23, 2006 Share Posted October 23, 2006 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 loophope this helps Quote Link to comment Share on other sites More sharing options...
ltoto Posted October 23, 2006 Author Share Posted October 23, 2006 my problem though is, i can find out what the probel is, but i cant write it properly in code.... Quote Link to comment Share on other sites More sharing options...
ltoto Posted October 23, 2006 Author Share Posted October 23, 2006 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 Quote Link to comment Share on other sites More sharing options...
obsidian Posted October 23, 2006 Share Posted October 23, 2006 [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]<?phpwhile ($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? Quote Link to comment Share on other sites More sharing options...
ltoto Posted October 23, 2006 Author Share Posted October 23, 2006 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 wasarse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING inafter this is done, will have a read through all of this, understand it even more, just that people are making me rush it... Quote Link to comment Share on other sites More sharing options...
obsidian Posted October 23, 2006 Share Posted October 23, 2006 [code]<?php// this lineecho "<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 beecho "<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] Quote Link to comment Share on other sites More sharing options...
ltoto Posted October 23, 2006 Author Share Posted October 23, 2006 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.