dflow Posted February 8, 2009 Share Posted February 8, 2009 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/144371-query-and-putput/ Share on other sites More sharing options...
dflow Posted February 9, 2009 Author Share Posted February 9, 2009 bump Quote Link to comment https://forums.phpfreaks.com/topic/144371-query-and-putput/#findComment-758091 Share on other sites More sharing options...
sasa Posted February 9, 2009 Share Posted February 9, 2009 look JOIN commands in mysql Quote Link to comment https://forums.phpfreaks.com/topic/144371-query-and-putput/#findComment-758110 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.