Jump to content


Photo

2 links in 1, HELP PLEASE!!


  • Please log in to reply
8 replies to this topic

#1 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 23 October 2006 - 01:09 PM

Heres the code to the page:

<?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);
?>

what do I do to this link

index.php?Id=22

so 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..

#2 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 23 October 2006 - 03:27 PM

the link at the top of the page that I am putting this link on is this

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

i have and include on the pages page which is this:

<?php
if(@$_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?

#3 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 23 October 2006 - 03:53 PM

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

#4 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 23 October 2006 - 04:15 PM

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:

$sql="SELECT * FROM tabHotel WHERE regionId = $id";


There should be something like this in order to set the value:

$id = $_GET['id'];


Then let's take a look at the URL you want to output from your results. You have this:

<a href="index.php?Id=22">


In your 'while' loop for displaying your contents you can include that link plus the other html and make the link like this:

<?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>
?>

Since you're already retrieving all the data in your query:

$sql="SELECT * FROM tabHotel WHERE regionId = $id";

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:

<?php
echo "<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>";
?>

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.


#5 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 23 October 2006 - 06:33 PM

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

#6 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 23 October 2006 - 06:58 PM

right, i have fixed one part of the code on this page now, so the code now look slike this:

<?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";
  }

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);?>

now i still need to fix the link problem from this

ndex.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???

#7 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 23 October 2006 - 07:34 PM

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.co...hp?categoryid=4

Now, 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.co...yid=$categoryid

This 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?Id=16&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 = $id";

That needs to know what the value is in order to match it with your regionID in the WHERE clause.



#8 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 23 October 2006 - 09:56 PM

thanks for that, i will sleep on now and look into tomoz, thanks again

#9 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 24 October 2006 - 08:09 AM

right so I have changed the top bit so it has the get id in there now which is this:

$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);

and this is the link

index.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....




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users