Jump to content

Query and putput


dflow

Recommended Posts

i have this script i want to

query a list of promotions from the promotions table i looop through the list and want to get for example a RegionName from the region_list table

filtering the region_list table by RegionID  from the promotions table

 

there aren't any  errors

 

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_international, $international);
$query_RsIndex = "SELECT * FROM ski_promotions ORDER BY Price ASC";
$RsIndex = mysql_query($query_RsIndex, $international) or die(mysql_error());
$row_RsIndex = mysql_fetch_assoc($RsIndex);
$totalRows_RsIndex = mysql_num_rows($RsIndex);

mysql_select_db($database_international, $international);
$query_RsCountry = "SELECT * FROM country_list WHERE CountryID = CountryID";
$RsCountry = mysql_query($query_RsCountry, $international) or die(mysql_error());
$row_RsCountry = mysql_fetch_assoc($RsCountry);
$totalRows_RsCountry = mysql_num_rows($RsCountry);

mysql_select_db($database_international, $international);
$query_RsRegion  = sprintf("SELECT * FROM region_list WHERE RegionID = %s", GetSQLValueString($row_RsPromotion['RegionID'], 'text'));
$RsRegion = mysql_query($query_RsRegion, $international) or die(mysql_error());
$row_RsRegion = mysql_fetch_assoc($RsRegion);
$totalRows_RsRegion = mysql_num_rows($RsRegion);

$maxRows_RsPromotion = 10;
$pageNum_RsPromotion = 0;
if (isset($_GET['pageNum_RsPromotion'])) {
  $pageNum_RsPromotion = $_GET['pageNum_RsPromotion'];
}
$startRow_RsPromotion = $pageNum_RsPromotion * $maxRows_RsPromotion;

$colname_RsPromotion = "-1";
if (isset($_GET['CountryID'])) {
  $colname_RsPromotion = $_GET['CountryID'];
}
mysql_select_db($database_international, $international);
$query_RsPromotion = sprintf("SELECT * FROM ski_promotions WHERE CountryID = %s", GetSQLValueString($colname_RsPromotion, "text"));
$query_limit_RsPromotion = sprintf("%s LIMIT %d, %d", $query_RsPromotion, $startRow_RsPromotion, $maxRows_RsPromotion);
$RsPromotion = mysql_query($query_limit_RsPromotion, $international) or die(mysql_error());
$row_RsPromotion = mysql_fetch_assoc($RsPromotion);

if (isset($_GET['totalRows_RsPromotion'])) {
  $totalRows_RsPromotion = $_GET['totalRows_RsPromotion'];
} else {
  $all_RsPromotion = mysql_query($query_RsPromotion);
  $totalRows_RsPromotion = mysql_num_rows($all_RsPromotion);
}
$totalPages_RsPromotion = ceil($totalRows_RsPromotion/$maxRows_RsPromotion)-1;
?>

 

Link to comment
Share on other sites

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.