Jump to content

Recommended Posts

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

[code]
<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>
[/code]

Huggie
  • Replies 71
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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

[code]<?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 />';
}
}
?>[/code]

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

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

To:

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

Regards
Huggie
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

[code]<?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);
?>[/code]

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
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
ok, try replacing all of your code that gets the countries and regions with this:

[code]
<?php
// Your select to get all the data, I've tried to remember your column/table data
$sql="SELECT c.countryName, r.regionName, r.regionID FROM tblCountry c, tblRegion r WHERE c.countryID = r.countryID";
$result = mysql_query($sql);
$country = "null";
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
  $cheader = $row['countryName'];
  if (is_null($country) || strcmp($country,$cheader) !=0){
      $country = $row['countryName'];
      echo <<<HTML
        <br>
        <h2>$country</h2>
HTML;
  }
echo <<<HTML
  <a href="hotels.php?regionid=$row[regionID]">$row[regionName]</a><br>
HTML;
}
?>
[/code]

See example here: http://www.dizzie.co.uk/php/pages2.php

Regards
Huggie
ok, add error checking then...

[code]<?php
// Your select to get all the data, I've tried to remember your column/table data
$sql="SELECT c.countryName, r.regionName, r.regionID FROM tblCountry c, tblRegion r WHERE c.countryID = r.countryID";
$result = mysql_query($sql);
if (!$result) {
  die('Invalid query: ' . mysql_error());
}
$country = "null";
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
  $cheader = $row['countryName'];
  if (is_null($country) || strcmp($country,$cheader) !=0){
      $country = $row['countryName'];
      echo <<<HTML
        <br>
        <h2>$country</h2>
HTML;
  }
echo <<<HTML
  <a href="hotels.php?regionid=$row[regionID]">$row[regionName]</a><br>
HTML;
}
?>[/code]

Regards
Huggie
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.