Jump to content


Photo

New Switch Statement problem


  • Please log in to reply
13 replies to this topic

#1 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 20 October 2006 - 12:55 PM

Ok so as i said in another thread a thought the probelm was with this:

<?php
switch($row_rsHotel['hotelType'])
{
	case 'Hotel':
		if($row_rsPages['Id']== "15")
		include "pages/country.php";
		break;

	case 'Villa':
		if($row_rsPages['Id']== "3")
		include "pages/country_villa.php";
		break;		
		
		case 'Golf':
		if($row_rsPages['Id']== "2")
		include "pages/country_golf.php";
		break;		
		
		
	default:
		
		break;
		
}
?>

so whats happening is there are 3 hotel types, Hotel, Villa, and Golf, and when one of these is selected it will go to a new page.

whats happening is that, whenever i change the hotel type in the first id field in the SQL, it changes all of the hotels to this, so they all follow the first Id, which i do not what to happen, any suggestions as to why this is happening.....

#2 obsidian

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

Posted 20 October 2006 - 01:00 PM

huh? where does SQL come into play here? your code is simply a switch statement (apparently based off a SQL query by your question). it sounds like your update query may not be properly filtering your records, and you're updating all records instead of just the one you're after.

why don't you share with us your method of updating your record, and let's figure out why they're all changing.
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 20 October 2006 - 01:05 PM

its updates in the backend with the admin panel, this is the update:

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE tabHotel SET hotelName=%s, hotelDescription=%s, hotelRating=%s, regionId=%s, hotelType=%s WHERE Id=%s",
                       GetSQLValueString($_POST['txtName'], "text"),
                       GetSQLValueString($_POST['txtDescription'], "text"),
                       GetSQLValueString($_POST['selectRating'], "text"),
                       GetSQLValueString($_POST['selectCountry'], "int"),
                       GetSQLValueString($_POST['selectType'], "text"),
                       GetSQLValueString($_POST['hidId'], "int"));


#4 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 20 October 2006 - 02:01 PM

any ideas at all as to why this is happening.................

#5 obsidian

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

Posted 20 October 2006 - 02:04 PM

well, it appears that your update statement is constructed properly. have you checked the data in your records after an update? is the data itself updated in every row, or is it the code displaying it that is causing the problem?
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 20 October 2006 - 02:11 PM

everything is updating fine, it just seems to be taking everything with the first Id, but not actually changing the other ones, to get it on everypage i could do this

<? if(@$_GET['Id']=="15") include 'country.php';
 else if(@$_GET['Id']=="2") include 'country_villa.php';
 else if(@$_GET['Id']=="3") include 'country_golf.php';?>
<?php
switch($row_rsHotel['hotelType'])
{
	case 'Hotel':
		if(@$_GET['Id']== "15")
		break;

	case 'Villa':
		
		if(@$_GET['Id']== "2");
		break;		
		
		case 'Golf':
		
		 if(@$_GET['Id']== "3");
		break;		
		
		
	default:
		
	break;
		}
?>


but it still wouldnt solve the problem, but it would get it on the right pages

#7 obsidian

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

Posted 20 October 2006 - 02:22 PM

ok, maybe i should back up a step: how is your $row_rsHotel array being populated? that's what you're running your switch on. can you explain what it is your switch is supposed to do? are you displaying details for each hotel with it? you are checking for two variables to be true in your switch statement as it stands in your first post: the only way "pages/country.php" is going to be included is if 1) $row_rsHotel['hotelType'] == 'Hotel' AND 2) $_GET['Id'] == 15.

i'm afraid you're going to have to really try to explain what you're doing with those variables and how they're being populated, because, as it is, if your update is working right, we've got to know more than just it's not working.
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 20 October 2006 - 02:45 PM

ok so this is what is happening

everthing you have said si correct

there are 3 hotel types, Golf, hotel, and Villa

each has a different Id page e.g

Golf Id = 3
Hotel Id = 15
Villa Id= 2

when they go on a page, e.g the hotels page, a list of coutrys will come up ( these countrys are added in the Admin side of the website )

and within the country, a list of regions show that are with the country, so it wil appaer like this for example:

SPAIN :

Murica, Madrid 

the code used to do this is

<?php 
$sql="SELECT tabCountry.countryName, tabCountry.countryImage, tabRegion.regionName, tabRegion.Id FROM tabCountry , tabRegion  WHERE tabCountry.Id = tabRegion.countryId";
$result = mysql_query($sql);
if (!$result) {
   die('Invalid query: ' . mysql_error());
}
$country = "null";
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
   $name = $row['countryName'];
   if (strcmp($country,$name) !=0){
      $country = $row['countryName'];
	 
      echo <<<HTML
       
	    <br>
		<div class="homebar2"><h1>$name</h1></div>
 <div class="country">  <img src="../thumb/phpThumb.php?src=../images/country_{$row['countryImage']}&amp;w=100&amp;h=100&amp;zc=1"  alt="Latest Deals">   </div>  
         
HTML;
   }
echo <<<HTML

 <div class="countrycontent"><a href="index.php?Id=16&id={$row['Id']}">{$row['regionName']}</a><br></div>
HTML;
} 
?>

this code is on the country.php page, and is the same on country_villa and country_hotel apart from the link at the bottom where i have changed the Id to o  to the right place.

When i region is clicked on, it goes to a new page, with the list of hotels within that region

done with this 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";
}

// List the hotels
echo "<div class=\"homebar2\"><h1>".$name."</h1></div><div class=\"hotel\">".$image."</div><div class=\"hotelcontent\">".$description."</div><h3><img src=\"".$star."\" hspace=\"2\"></h3>
\n";
}

mysql_free_result($rsHotels);
?>



so what happens at the moment is that the villa, golf and hotel, hotels appear on each page, but what i am tryin to do is get it that on the hotel page, it just hsows the hotel, hotels

on the villa page the villa ones, and the golf page, the golf ones.....

#9 obsidian

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

Posted 20 October 2006 - 02:58 PM

ah, ok. so, you're wanting to have sort of a filter to show all of one type of hotel? it sounds like you just need to add another filter to your query based on what was selected to filter by. i would recommend doing this with a single filter page instead of separate pages for each. this way, you avoid a ton of repetative code. something like this should work (you'll probably have to adjust it to suit your database):
<?php
// default your filter page to show hotels
$filter = isset($_GET['filter']) ? $_GET['filter'] : "Hotel";
switch($filter) {
  case "Villa": 
    $where = "hotelType = 'Villa'";
    break;

  case "Golf":
    $where = "hotelType = 'Golf'";
    break;

  default:
    $where = "hotelType = 'Hotel'";
}

$sql = mysql_query("SELECT * FROM hotels WHERE $where");
// now display your results reflecting the filter
?>

and to set up your filter, all you have to do is set up some links:
<a href="?filter=Hotel">Show only Hotels</a>
<a href="?filter=Villa">Show only Villas</a>
<a href="?filter=Golf">Show only Golf</a>

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

#10 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 20 October 2006 - 03:05 PM

the reason i have different pages though, is because the client asked for a hotel page, a villas page, and a golf page

#11 obsidian

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

Posted 20 October 2006 - 03:12 PM

ok, well, just use the same logic as i showed above, but then set your SQL statement at the top of each page, and then make your links point to the separate pages directly.

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

#12 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 20 October 2006 - 03:36 PM

so now i need to add something to this code i guess because its now showing each hotel on each section

<?php 
$sql="SELECT tabCountry.countryName, tabCountry.countryImage, tabRegion.regionName, tabRegion.Id FROM tabCountry , tabRegion  WHERE tabCountry.Id = tabRegion.countryId";
$result = mysql_query($sql);
if (!$result) {
   die('Invalid query: ' . mysql_error());
}
$country = "null";
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
   $name = $row['countryName'];
   if (strcmp($country,$name) !=0){
      $country = $row['countryName'];
	 
      echo <<<HTML
       
	    <br>
		<div class="homebar2"><h1>$name</h1></div>
 <div class="country">  <img src="../thumb/phpThumb.php?src=../images/country_{$row['countryImage']}&amp;w=100&amp;h=100&amp;zc=1"  alt="Latest Deals">   </div>  
         
HTML;
   }
echo <<<HTML

 <div class="countrycontent"><a href="index.php?Id=16&id={$row['Id']}">{$row['regionName']}</a><br></div>
HTML;
} 
?>


#13 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 25 October 2006 - 10:38 AM

right i tried the filter thing but couldnt get it to work, so i am trying this


switch($row_rsAccomodation['hotelType'])
{
 case 'Hotel':
  if($row_rsPages['Id']== "15")
  include "pages/country.php";
  break;
 
 case 'Villa':
  if($row_rsPages['Id']== "3")
  include "pages/country_villa.php";
  break;  
  
  case 'Golf':
  if($row_rsPages['Id']== "2")
  include "pages/country_golf.php";
  break;  
  
  
 default:
  
  break;
  
}
?>

but it just follows the first Id still

#14 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 25 October 2006 - 12:57 PM

<?php
mysql_select_db($database_conTotal, $conTotal);
$query_rsHotellist = "SELECT * FROM tabHotel WHERE hotelType = 'Hotel'";
$rsHotellist = mysql_query($query_rsHotellist, $conTotal) or die(mysql_error());
$row_rsHotellist = mysql_fetch_assoc($rsHotellist);
$totalRows_rsHotellist = mysql_num_rows($rsHotellist);
 
$sql="SELECT tabCountry.countryName, tabCountry.countryImage, tabRegion.regionName, tabRegion.Id FROM tabCountry , tabRegion  WHERE tabCountry.Id = tabRegion.countryId";
$result = mysql_query($sql);
if (!$result) {
   die('Invalid query: ' . mysql_error());
}
$country = "null";
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
   $name = $row['countryName'];
   if (strcmp($country,$name) !=0){
      $country = $row['countryName'];
	 
      echo <<<HTML
       
	    <br>
		<div class="homebar2"><h1>$name</h1></div>
 <div class="country">  <img src="../thumb/phpThumb.php?src=../images/country_{$row['countryImage']}&amp;w=100&amp;h=100&amp;zc=1"  alt="Latest Deals">   </div>  
         
HTML;
   }
echo <<<HTML

 <div class="countrycontent"><a href="index.php?Id=16&id={$row['Id']}&hotelType='Hotel'">{$row['regionName']}&</a><br></div>
HTML;
} 

mysql_free_result($rsHotellist);
?>,

do i put the case code on this page, I also have one for Gold and hotel with the same code, but the type at the top changes and the link at the bottom




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users