Jump to content


Photo

SOLVED 2 Repeat Regions


  • Please log in to reply
71 replies to this topic

#41 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 13 September 2006 - 03:53 PM

wahay, that is how i have done the backend, atleast i have done something right now  ;D

#42 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 14 September 2006 - 07:47 AM

Not country name, country ID.  Look at my previous structure....

tabCountry - countryID, countryName
tabRegion - regionID, countryID, regionName
tabHotel - hotelID, regionID, hotelName, hotelImage, hotelDescription, hotelRating


Rich


in country where you have put countryId, can that be left as Id or must I rename it as countryId

#43 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 14 September 2006 - 08:03 AM

It can be left as ID, so long as it's a unique field, preferably auto-incrementing.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#44 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 14 September 2006 - 08:11 AM

and just to check, i then use this code for the drop down list is the regionadd page

<select name="selectCountry" id="selectCountry">
                <?php
do {  
?>
                <option value="<?php echo $row_rsCountry['Id']?>"<?php if (!(strcmp($row_rsCountry['Id'], $row_rsRegionedit['countryId']))) {echo "SELECTED";} ?>><?php echo $row_rsCountry['Id']?></option>
                <?php
} while ($row_rsCountry = mysql_fetch_assoc($rsCountry));
  $rows = mysql_num_rows($rsCountry);
  if($rows > 0) {
      mysql_data_seek($rsCountry, 0);
	  $row_rsCountry = mysql_fetch_assoc($rsCountry);
  }
?>
              </select>

which will be the same on the hotel page

#45 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 14 September 2006 - 08:21 AM

Assuming that
$row_rsRegionedit['countryId']
came from a select on the tabRegion, then yes, it looks good to me.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#46 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 14 September 2006 - 09:11 AM

right so this is now done, so now how do I change it so intead of it showing the Id of the region in the dropdown menu, it shows the names

#47 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 14 September 2006 - 09:14 AM

What's the select statement you're using to get the code for the dropdown?

Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#48 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 14 September 2006 - 09:21 AM

it is only like this at the moment

  <select name="selectCountry" id="selectCountry" title="<?php echo $row_rsAccomedit['hotelCountry']; ?>">
			    <?php
do {  
?>
			    <option value="<?php echo $row_rsRegion['Id']?>"<?php if (!(strcmp($row_rsRegion['Id'], $row_rsAccomedit['regionId']))) {echo "SELECTED";} ?>><?php echo $row_rsRegion['Id']?></option>
			    <?php
} while ($row_rsRegion = mysql_fetch_assoc($rsRegion));
  $rows = mysql_num_rows($rsRegion);
  if($rows > 0) {
      mysql_data_seek($rsRegion, 0);
	  $row_rsRegion = mysql_fetch_assoc($rsRegion);
  }
?>
              
		      
              </select>

Edited

#49 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 14 September 2006 - 09:24 AM

Sorry, didn't explain myself there...

I mean what's your SQL select statement.. eg. SELECT countryId FROM... etc.

Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#50 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 14 September 2006 - 09:26 AM

oh i see what you mean i think

mysql_select_db($database_conTotal, $conTotal);
$query_rsRegion = "SELECT * FROM tabRegion";
$rsRegion = mysql_query($query_rsRegion, $conTotal) or die(mysql_error());
$row_rsRegion = mysql_fetch_assoc($rsRegion);
$totalRows_rsRegion = mysql_num_rows($rsRegion);

mysql_select_db($database_conTotal, $conTotal);
$query_rsCountry = "SELECT * FROM tabCountry";
$rsCountry = mysql_query($query_rsCountry, $conTotal) or die(mysql_error());
$row_rsCountry = mysql_fetch_assoc($rsCountry);
$totalRows_rsCountry = mysql_num_rows($rsCountry);
?>


#51 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 14 September 2006 - 09:32 AM

I'm aware of that, but you need to show me what the SQL code is that's getting the recordset for that drop down.

Based on what you've said in the past, I'd imagine it's something like...

<select name="selectCountry" id="selectCountry" title="<?php echo $row_rsAccomedit['hotelCountry']; ?>">

<?php
   do {
?>

<option value="<?php echo $row_rsRegion['Id']?>"<?php if (!(strcmp($row_rsRegion['Id'], $row_rsAccomedit['regionId']))) {echo "SELECTED";} ?>><?php echo $row_rsRegion['regionName']?></option>

<?php
   }
   while ($row_rsRegion = mysql_fetch_assoc($rsRegion));
      $rows = mysql_num_rows($rsRegion);
      if($rows > 0) {
         mysql_data_seek($rsRegion, 0);
         $row_rsRegion = mysql_fetch_assoc($rsRegion);
   }
?>

</select>

Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#52 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 14 September 2006 - 09:44 AM

right so moving on to the front end now, so the code is like this at the moment

<?php

if($row_rsPages['Id']== "15"  )
{
$row_rsCountry_Q = mysql_query("SELECT * FROM tabCountry  ORDER BY 'countryName' ") or die(mysql_error());
while($row_rsCountry = mysql_fetch_array($row_rsCountry_Q))

{
echo '<h2>'.  $row_rsCountry['countryName'].'</h2>';
}
$row_rsRegion_Q = mysql_query("SELECT * FROM tabRegion WHERE 'regionName' = '".$row_rsCountry['Id']."' ORDER BY 'regionName' ") or die(mysql_error());
while($row_rsRegion = mysql_fetch_array($row_rsRegion_Q))
{
echo '<br />' . $row_rsRegion['regionName'] . '<br />';
}
}
?>

what changes will need to be made to this in order for everything to work

#53 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 14 September 2006 - 09:50 AM

Change this row:

$row_rsRegion_Q = mysql_query("SELECT * FROM tabRegion WHERE 'regionName' = '".$row_rsCountry['Id']."' ORDER BY 'regionName' ") or die(mysql_error());

To:

$row_rsRegion_Q = mysql_query("SELECT * FROM tabRegion WHERE 'countryId' = '".$row_rsCountry['Id']."' ORDER BY 'regionName' ") or die(mysql_error());

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#54 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 14 September 2006 - 09:55 AM

ok i have done that, but it still doesnt seem to be showing the regions from the country, just the list of countrys still, Im guessing i have a mistake somewhere along the line, any ideas where icoul dof made it

#55 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 14 September 2006 - 09:58 AM

Are you able to post the entire code from that page, I'd like to take a look at it if possible?

Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#56 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 14 September 2006 - 10:01 AM

i think there are many errors on this page which i have to go through and correct, which i normally go through when the page is complete, so this is the last stage of the page

<?php
$currentPage = $_SERVER["PHP_SELF"];

$colname_rsPages = "1";
if (isset($_GET['Id'])) {
$colname_rsPages = (get_magic_quotes_gpc()) ? $_GET['Id'] : addslashes($_GET['Id']);
}
mysql_select_db($database_conTotal, $conTotal);
$query_rsPages = sprintf("SELECT * FROM tabPages WHERE Id = %s", $colname_rsPages);
$rsPages = mysql_query($query_rsPages, $conTotal) or die(mysql_error());
$row_rsPages = mysql_fetch_assoc($rsPages);
$totalRows_rsPages = mysql_num_rows($rsPages);

$maxRows_rsDeals = 4;
$pageNum_rsDeals = 0;
if (isset($_GET['pageNum_rsDeals'])) {
$pageNum_rsDeals = $_GET['pageNum_rsDeals'];
}
$startRow_rsDeals = $pageNum_rsDeals * $maxRows_rsDeals;

mysql_select_db($database_conTotal, $conTotal);
$query_rsDeals = "SELECT * FROM tabLatestDeals WHERE Id = Id ORDER BY Id DESC";
$query_limit_rsDeals = sprintf("%s LIMIT %d, %d", $query_rsDeals, $startRow_rsDeals, $maxRows_rsDeals);
$rsDeals = mysql_query($query_limit_rsDeals, $conTotal) or die(mysql_error());
$row_rsDeals = mysql_fetch_assoc($rsDeals);

if (isset($_GET['totalRows_rsDeals'])) {
$totalRows_rsDeals = $_GET['totalRows_rsDeals'];
} else {
$all_rsDeals = mysql_query($query_rsDeals);
$totalRows_rsDeals = mysql_num_rows($all_rsDeals);
}
$totalPages_rsDeals = ceil($totalRows_rsDeals/$maxRows_rsDeals)-1;

$colname_rsForm = "1";
if (isset($_GET['Id'])) {
$colname_rsForm = (get_magic_quotes_gpc()) ? $_GET['Id'] : addslashes($_GET['Id']);
}
mysql_select_db($database_conTotal, $conTotal);
$query_rsForm = sprintf("SELECT * FROM tabForm WHERE Id = %s", $colname_rsForm);
$rsForm = mysql_query($query_rsForm, $conTotal) or die(mysql_error());
$row_rsForm = mysql_fetch_assoc($rsForm);
$totalRows_rsForm = mysql_num_rows($rsForm);

mysql_select_db($database_conTotal, $conTotal);
$query_rsGolf = "SELECT * FROM tabPages WHERE Id = 2";
$rsGolf = mysql_query($query_rsGolf, $conTotal) or die(mysql_error());
$row_rsGolf = mysql_fetch_assoc($rsGolf);
$totalRows_rsGolf = mysql_num_rows($rsGolf);

mysql_select_db($database_conTotal, $conTotal);
$query_rsTour = "SELECT * FROM tabPages WHERE Id = 13";
$rsTour = mysql_query($query_rsTour, $conTotal) or die(mysql_error());
$row_rsTour = mysql_fetch_assoc($rsTour);
$totalRows_rsTour = mysql_num_rows($rsTour);

mysql_select_db($database_conTotal, $conTotal);
$query_rsCustom = "SELECT * FROM tabPages WHERE Id = 14";
$rsCustom = mysql_query($query_rsCustom, $conTotal) or die(mysql_error());
$row_rsCustom = mysql_fetch_assoc($rsCustom);
$totalRows_rsCustom = mysql_num_rows($rsCustom);

mysql_select_db($database_conTotal, $conTotal);
$query_rsVillas = "SELECT * FROM tabPages WHERE Id = 3";
$rsVillas = mysql_query($query_rsVillas, $conTotal) or die(mysql_error());
$row_rsVillas = mysql_fetch_assoc($rsVillas);
$totalRows_rsVillas = mysql_num_rows($rsVillas);

$maxRows_rsHotel = 10;
$pageNum_rsHotel = 0;
if (isset($_GET['pageNum_rsHotel'])) {
$pageNum_rsHotel = $_GET['pageNum_rsHotel'];
}
$startRow_rsHotel = $pageNum_rsHotel * $maxRows_rsHotel;

mysql_select_db($database_conTotal, $conTotal);
$query_rsHotel = "SELECT * FROM tabHotel";
$query_limit_rsHotel = sprintf("%s LIMIT %d, %d", $query_rsHotel, $startRow_rsHotel, $maxRows_rsHotel);
$rsHotel = mysql_query($query_limit_rsHotel, $conTotal) or die(mysql_error());
$row_rsHotel = mysql_fetch_assoc($rsHotel);

if (isset($_GET['totalRows_rsHotel'])) {
$totalRows_rsHotel = $_GET['totalRows_rsHotel'];
} else {
$all_rsHotel = mysql_query($query_rsHotel);
$totalRows_rsHotel = mysql_num_rows($all_rsHotel);
}
$totalPages_rsHotel = ceil($totalRows_rsHotel/$maxRows_rsHotel)-1;

$maxRows_rsCountry = 10;
$pageNum_rsCountry = 0;
if (isset($_GET['pageNum_rsCountry'])) {
  $pageNum_rsCountry = $_GET['pageNum_rsCountry'];
}
$startRow_rsCountry = $pageNum_rsCountry * $maxRows_rsCountry;

$colname_rsCountry = "1";
if (isset($_GET['countryName'])) {
  $colname_rsCountry = (get_magic_quotes_gpc()) ? $_GET['countryName'] : addslashes($_GET['countryName']);
}
mysql_select_db($database_conTotal, $conTotal);
$query_rsCountry = sprintf("SELECT * FROM tabCountry WHERE countryName = '%s'", $colname_rsCountry);
$query_limit_rsCountry = sprintf("%s LIMIT %d, %d", $query_rsCountry, $startRow_rsCountry, $maxRows_rsCountry);
$rsCountry = mysql_query($query_limit_rsCountry, $conTotal) or die(mysql_error());
$row_rsCountry = mysql_fetch_assoc($rsCountry);

if (isset($_GET['totalRows_rsCountry'])) {
  $totalRows_rsCountry = $_GET['totalRows_rsCountry'];
} else {
  $all_rsCountry = mysql_query($query_rsCountry);
  $totalRows_rsCountry = mysql_num_rows($all_rsCountry);
}
$totalPages_rsCountry = ceil($totalRows_rsCountry/$maxRows_rsCountry)-1;

mysql_select_db($database_conTotal, $conTotal);
$query_rsRegion = "SELECT * FROM tabRegion";
$rsRegion = mysql_query($query_rsRegion, $conTotal) or die(mysql_error());
$row_rsRegion = mysql_fetch_assoc($rsRegion);
$totalRows_rsRegion = mysql_num_rows($rsRegion);

mysql_select_db($database_conTotal, $conTotal);
$query_rsRegion = "SELECT * FROM tabRegion";
$rsRegion = mysql_query($query_rsRegion, $conTotal) or die(mysql_error());

$row_rsRegion = mysql_fetch_assoc($rsRegion);
$totalRows_rsRegion = mysql_num_rows($rsRegion);
?>





<?
if($row_rsPages['Id'] == "1" )
{
echo ?> <div id="homebg">
  <? } ?>
  <h2><?php echo $row_rsPages['pagesTitle']; ?></h2>
<?php echo $row_rsPages['pagesContent']; ?>

<?
if($row_rsPages['Id'] == "1" )
{
echo ?> </div>
<? } ?>







<?php
if(@$_GET['Id']== "12") { ?>
<?php do { ?>
<div class="Dealsbar2">

<h1><?php echo $row_rsDeals['dealsTitle']; ?></h1>

</div>

<div class="Deals2"><img src="/images/deals_<?php echo $row_rsDeals['dealsImage']; ?>" alt="Latest Deals"><br>

<div class="contentbox"> <?php echo $row_rsDeals['dealsContent']; ?><br>
<br></div>

</div>

<div class="Deals2">
<div class="dealsbox"> <div class="Deals2date"> Date: <?php echo $row_rsDeals['dealsDate']; ?>

</div></div>

<div class="Deals2price"> Price:&pound;<?php echo $row_rsDeals['dealsPrice']; ?></div>

</div>
<?php } while ($row_rsDeals = mysql_fetch_assoc($rsDeals)); ?>
<?php } ?>

<?php

if($row_rsPages['Id']== "15"  )
{
$row_rsCountry_Q = mysql_query("SELECT * FROM tabCountry  ORDER BY 'countryName' ") or die(mysql_error());
while($row_rsCountry = mysql_fetch_array($row_rsCountry_Q))

{
echo '<h2>'.  $row_rsCountry['countryName'].'</h2>';
}
$row_rsRegion_Q = mysql_query("SELECT * FROM tabRegion WHERE 'countryId' = '".$row_rsCountry['Id']."' ORDER BY 'regionName' ") or die(mysql_error());
while($row_rsRegion = mysql_fetch_array($row_rsRegion_Q))
{
echo '<br />' . $row_rsRegion['regionName'] . '<br />';
}
}
?>


<?php
if($row_rsPages['Id']== "1") { ?>


<div class="homebar2">
<h1>Golf Holidays </h1>
</div>





<p><?php
function cutit ($var, $max)
{
return (strlen( $var ) > $max) ? substr($var, 0, $max).'...' : $var;
}


echo cutit ($row_rsGolf['pagesContent'], 250);


?>
</p>
<div class="moreinfo"> <a href="index.php?Id=2"><img src="../images/moreinfo.jpg" alt="moreinfo" width="75" height="18" border="0"></a></div>



<div class="homebar2">
<h1>Tour Packages </h1> </div>
<p><?php echo strip_tags(cutit($row_rsTour['pagesContent'], 250));?></p>
<div class="moreinfo"> <a href="index.php?Id=13"><img src="../images/moreinfo.jpg" alt="moreinfo" width="75" height="18" border="0"></a></div
>




<div class="homebar2">
<h1>Custom Holidays</h1></div>
<p><?php echo strip_tags(cutit($row_rsCustom['pagesContent'], 250));?></p>
<div class="moreinfo"> <a href="index.php?Id=14"><img src="../images/moreinfo.jpg" alt="moreinfo" width="75" height="18" border="0"></a></div
>



<div class="homebar2">
<h1>Villa Property </h1></div>
<p><?php echo strip_tags(cutit($row_rsVillas['pagesContent'], 250));?> </p>
<div class="moreinfo"> <a href="index.php?Id=3"><img src="../images/moreinfo.jpg" alt="moreinfo" width="75" height="18" border="0"></a></div
>

<?php } ?>



<?php
mysql_free_result($rsPages);

mysql_free_result($rsDeals);

mysql_free_result($rsForm);

mysql_free_result($rsGolf);

mysql_free_result($rsTour);

mysql_free_result($rsCustom);

mysql_free_result($rsVillas);

mysql_free_result($rsHotel);

mysql_free_result($rsCountry);

mysql_free_result($rsRegion);
?>

the next words i am guessing you will say is, the code is a mess :(, but i think most of the mess is just the stuff dreamweaver does

#57 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 14 September 2006 - 10:09 AM

It is quite messy, but if you're new it's understandable, no doubt when I write my first proper php script it will be the same.  However, having said that, it looks as though the code itself is fine.

I'm assuming this is a front page, or something similar?

Do you have a URL where this is live, or are you testing locally?  If a live URL, can you provide it?

Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#58 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 14 September 2006 - 10:14 AM

this is the page where the pages are, if that makes sense.

It is being tested on my companies local server at the mo, but maybe i could upload it to my site

#59 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 14 September 2006 - 10:20 AM

this is what it is on at the moment

http://www.ryanbenbo...index.php?Id=15


there will be errors with pictures cos i just put it on here

#60 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 14 September 2006 - 11:53 AM

OK, there's no drop downs on that page at all...

Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users