ltoto Posted October 23, 2006 Share Posted October 23, 2006 Heres the code to the page: [code]<?php$colname_rsHotels = "1";if (isset($_GET['Id'])) { $colname_rsHotels = (get_magic_quotes_gpc()) ? $_GET['Id'] : addslashes($_GET['Id']);}mysql_select_db($database_conTotal, $conTotal);$query_rsHotels = sprintf("SELECT * FROM tabHotel WHERE Id = %s", $colname_rsHotels);$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?><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"><img src="../images/moreinfo.jpg" alt="moreinfo" width="75" height="18" border="0"></a></a></div><?php}?><? mysql_free_result($rsHotels);?>[/code]what do I do to this linkindex.php?Id=22so that it also picks up the hotel Id aswell if that makes sense??? becausewhat I am trying to do is make it so it clicks on the hotel id, and all the info from tht page shows up.thanks alot.. Quote Link to comment Share on other sites More sharing options...
ltoto Posted October 23, 2006 Author Share Posted October 23, 2006 the link at the top of the page that I am putting this link on is thishttp://development4.jbswebdesign.co.uk/index.php?Id=20&id=1:i have and include on the pages page which is this: <?phpif(@$_GET['Id']== "22") { include('pages/accom.php'); } ?>on this page from the code in the post above i wrote the link as this:<a href="index.php?Id=22&id=<? echo $row_rsHotels['Id']; ?>"but obviously this would be the same as the one at the top of the post.i have found that it is picking the right id number up, but seems to be going to the wrong table in the sql when clicking on it? Quote Link to comment Share on other sites More sharing options...
ltoto Posted October 23, 2006 Author Share Posted October 23, 2006 sorry for triple post, just that i have until half past 5 to do it and i am a bit miffed, andysugesstions or do i need o tadd somthing else Quote Link to comment Share on other sites More sharing options...
simcoweb Posted October 23, 2006 Share Posted October 23, 2006 I'm not a pro but I see a couple of things and perhaps a different way to write your output.First, I don't see where you're setting the value for the variable $id that's in your query:[quote]$sql="SELECT * FROM tabHotel WHERE regionId = $id";[/quote]There should be something like this in order to set the value:[quote]$id = $_GET['id'];[/quote]Then let's take a look at the URL you want to output from your results. You have this:[quote]<a href="index.php?Id=22">[/quote]In your 'while' loop for displaying your contents you can include that link plus the other html and make the link like this:[code]<?php<a href='index.php?Id=" . $row['Id'] . "&id=" . $row['id'] . "'><img src="../images/moreinfo.jpg" alt="moreinfo" width="75" height="18" border="0"></a>?>[/code]Since you're already retrieving all the data in your query:[code]$sql="SELECT * FROM tabHotel WHERE regionId = $id";[/code]You can display it in your 'while' loop and dress if up in a table for example and the link would appear as your image and point to the proper location. Make sense?So, displaying it like this for example:[code]<?phpecho "<table width='90%' border='0'>";while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {echo "<tr><td>" . $row['hotelName'] . "</td></tr> <tr><td>" . $row['hotelDescription'] . "</td></tr> <tr><td>" . $row['hotelRating'] . "</td></tr> <tr><td><img src='../thumb/phpThumb.php?src=../images/hotel_" . $row['hotelImage'] . "&w=100&h=100&zc=1' alt='Hotel'></td></tr>";}echo "</table>";?>[/code]This is just an idea, obviously. But would output your results in a table layout that you can then dress up with some background colors and styles. Quote Link to comment Share on other sites More sharing options...
ltoto Posted October 23, 2006 Author Share Posted October 23, 2006 i cant use tables ;D, tabless website..thanks for the advice, i tired it at home but it didnt seem to work, but i will have a play around Quote Link to comment Share on other sites More sharing options...
ltoto Posted October 23, 2006 Author Share Posted October 23, 2006 right, i have fixed one part of the code on this page now, so the code now look slike this:[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"; }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";}?><? mysql_free_result($rsHotels);?>[/code]now i still need to fix the link problem from thisndex.php?Id=22&id=$row[Id]with this id=$row[Id] bit, it picks up the id from something else, as i have already used a link like this on another include page, which is this:index.php?Id=16&id={$row['Id']}">{$row['regionName']}and suggestions how to get it to pick up thehotel Id??? Quote Link to comment Share on other sites More sharing options...
simcoweb Posted October 23, 2006 Share Posted October 23, 2006 Ok, let's see if we can make sense of this. Alright, so you're not using tables. That was just an example. I wanted you to see how I was calling the results using " . $row['hotelName'] . " and not so much the tables themselves. In regards to the link....first I need to understand how you get the ID into your link. I have a similar setup and my links are like this which are hard-coded with the category id number:http://www.mysite.com/category.php?categoryid=4Now, when they click on that it takes them to category.php and identifies the categoryid through a $_GET['categoryid'] which sets that as a variable like:$categoryid = $_GET['categoryid'];So, in the continuation links you'd use the variable like this:http://www.mysite.com/category.php?categoryid=$categoryidThis way no matter what link they click on over there <------------- it take them to the proper category over there -------->and displays the content/details pertaining to only that categoryid by using the WHERE categoryid = '$categoryid' clause. Make sense?So, in your case, i'm not 100% on how you have this set up but it's obvious you have an ID # in your links that they are clicking on. So, assuming that you have a list of hotels on a page that then link to this script you're creating whereas there's an ID number in that link (ie: index.php?[b]Id=16[/b]&id={$row['Id']}">{$row['regionName']}) then you'd want to snag that ID using the $_GET and use in your links and get the other 'id' from your query to fill out your link. Since your query returns an array of all the data pertaining to that particular hotel (ie: the SELECT * FROM ) then you can get the other 'id' variable displayed like I showed you and then daisy chain it into your link like this inside you WHILE loop:echo "<a href='index.php?Id=$Id&id=" . $row['id'] . "'>Click here to view this hotel!</a>";Again, these are just examples. Not 100% sure what you're trying to accomplish. But, one more thing. I still don't see where you are setting a value for this variable:$sql="SELECT * FROM tabHotel WHERE regionId = [b]$id[/b]";That needs to know what the value is in order to match it with your regionID in the WHERE clause. Quote Link to comment Share on other sites More sharing options...
ltoto Posted October 23, 2006 Author Share Posted October 23, 2006 thanks for that, i will sleep on now and look into tomoz, thanks again Quote Link to comment Share on other sites More sharing options...
ltoto Posted October 24, 2006 Author Share Posted October 24, 2006 right so I have changed the top bit so it has the get id in there now which is this:[code]$colname_rsHotels = "1";if (isset($_GET['Id'])) { $colname_rsHotels = (get_magic_quotes_gpc()) ? $_GET['Id'] : addslashes($_GET['Id']);}mysql_select_db($database_conTotal, $conTotal);$query_rsHotels = sprintf("SELECT * FROM tabHotel WHERE Id = %s", $colname_rsHotels);$rsHotels = mysql_query($query_rsHotels, $conTotal) or die(mysql_error());$row_rsHotels = mysql_fetch_assoc($rsHotels);$totalRows_rsHotels = mysql_num_rows($rsHotels);[/code]and this is the linkindex.php?Id=22&Id=$row[Id]now it is picking up the right id number, but itsn't going to the right place, because i already have a link with the id on so maybe i need to some how rename the second Id part in the link, how do i do this.... 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.