Return to Snippet

Revision: 48477
at July 2, 2011 06:45 by cphoover


Initial Code
<?php
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
/*
the first time it should run the external query get data and cache in local sqli then use that data until refreshed
*/



require('dbconnect.php');



function getWines($selectString, $distinct = FALSE, $id = NULL, $parentRegion = NULL, $childRegion = NULL, $year = NULL, $rating = NULL){
	
	$sql = 'SELECT ' . ($distinct ? DISTINCT : ''). ' ' . mysql_real_escape_string($selectString) .'
				FROM `wines` WHERE 1 ';
	$sql .=	( $parentRegion ? ' AND `parentRegion` == \'' 	. mysql_real_escape_string ($parentRegion)  . '\'' : ''	);
	$sql .=	( $id 			? ' AND `id` == \'' 			. mysql_real_escape_string ($id) 			. '\'' : ''	);
	$sql .= ( $childRegion  ? ' AND `childRegion`  == \'' 	. mysql_real_escape_string ($childRegion)	. '\'' : ''	);
	$sql .= ( $year			? ' AND `year`  == \'' 			. mysql_real_escape_string ($year)			. '\'' : ''	);
	$sql .= ( $rating		? ' AND `rating`  == \'' 		. mysql_real_escape_string ($rating)		. '\'' : ''	);
	$result = mysql_query($sql);
	return $result;
}




/* --
This function returns a json encoded string from the given object
**/
function parseJSON($data){
	
	$JSON = '';
	
	while ($row = mysql_fetch_assoc($data)) {
	    $JSON .= json_encode($row);
	}
	return $JSON;
}


echo parseJSON(getWines('*'));



?>

Initial URL


Initial Description


Initial Title
Pass MYSQL by reference

Initial Tags


Initial Language
PHP