PHP Query Filter with multiple options - MySQL

Hi everyone,
I’m trying to create a filter that requests data from a table and outputs it into xml.

I’ve been introduced to the $query = “SELECT something FROM table WHERE some value”
however I’m confused as to how I can do that when the request from the cient side is
something like: BAR, in DOWNTON for date JULY 11, where entrance is LESS THAN 10.

I have a simple code that I’m trying to get to work with an html page with no luck. I’ve
searched google for two days straight but found nothing concretely for a begginer like me.
If you have the time and/or some examples that you can point me to, I’d be thankful.

Here’s what I have:

[php]$query = “SELECT * FROM events WHERE Location=‘downtown’”;
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ’ . mysql_error());
}[/php]

Thanks a lot!

where is the form that you are using? please show me that and also show me the fields in the events table of the database.
we are going to create a (“select * from events where location like ‘%downtown%’”) query but I want to see what info is being passed just to be sure the query is correct and I can set you up with the $_POST into strip tags and escaped string variables to help protect your site a little bit. I am also curious if you have an id or date field because you can order everything off of those so shoot me the info and lets see what we can do for you

Hi, thank you for your effort :)))
Here is what I have as of now: (The table below is there as a help reference to show exactly what is in the mysql database.)
http://tinyurl.com/6a76aek

The HTML is structured like this:

[php]

<?php $username="****"; $password="*****"; $database="****";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( “Unable to select database”);
$query=“SELECT * FROM markers”;
$result=mysql_query($query);

$num=mysql_num_rows($result);

mysql_close();
?>

Name:
Address:
Type:
<?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"Name"); $f2=mysql_result($result,$i,"Address"); $f3=mysql_result($result,$i,"Type"); ?> <?php $i++; } ?>[/php]

And get_xml2.php that the information is sent to looks like this:

[php]<?php
require(“db_access.php”);

function parseToXML($htmlStr)
{
$xmlStr=str_replace(’<’,’<’,$htmlStr);
$xmlStr=str_replace(’>’,’>’,$xmlStr);
$xmlStr=str_replace(’"’,’"’,$xmlStr);
$xmlStr=str_replace("’",’’’,$xmlStr);
$xmlStr=str_replace("&",’&’,$xmlStr);
return $xmlStr;
}

$Name=$_POST[‘Value1’];
$Address=$_POST[‘Value2’];
$Type=$_POST[‘Value3’];

// Opens a connection to a MySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
die('Not connected : ’ . mysql_error());
}

// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can’t use db : ’ . mysql_error());
}

// Select all the rows in the markers table
$query = "SELECT Name, Address, Type FROM markers WHERE Name = ’ .$Name. ’ AND Address = ’ .$Address. ’ AND type = ’ .$Type. ’ ";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ’ . mysql_error());
}

header(“Content-type: text/xml”);

// Start XML file, echo parent node
echo ‘’;

// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
echo '<marker ';
echo ‘name="’ . parseToXML($row[‘name’]) . '" ';
echo ‘address="’ . parseToXML($row[‘address’]) . '" ';
echo ‘lat="’ . $row[‘lat’] . '" ';
echo ‘lng="’ . $row[‘lng’] . '" ';
echo ‘type="’ . $row[‘type’] . '" ';
echo ‘/>’;
}

// End XML file
echo ‘’;

?>[/php]

I want, when I insert for example “restaurant” in the type field, to return all rows with the type=restaurant. When I do that, the xml file returned is empty.

Name Address Type
<?php echo $f1; ?> <?php echo $f2; ?> <?php echo $f3; ?>

Edit: I have fixed the following (though I still get an empty xml).

$Name=$_POST[‘Name’];
$Address=$_POST[‘Address’];
$Type=$_POST[‘Type’];

FIXED :smiley:

[QUOTE]$result = mysql_query($result);

Should be

$result = mysql_query($query);[/QUOTE]

Thanks for your time anyway :))))

Sponsor our Newsletter | Privacy Policy | Terms of Service