Alright, here's what I tried. I have some code below that retrieves all data from my table. Now, in the textbox, let's say that I input "bar". I want it to send a query to mysql to display all rows (in an xml format) which TYPE = bar. Here's some code below.
Code: Select all
<html>
<body>
<?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();
?>
<form action="get_xml2.php" method="post">
Name: <input type="text" name="Name"><br>
Address: <input type="text" name="Address"><br>
Type: <input type="text" name="Type"><br>
<input type="Submit">
</form>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Name</font></th>
<th><font face="Arial, Helvetica, sans-serif">Address</font></th>
<th><font face="Arial, Helvetica, sans-serif">Type</font></th>
</tr>
<?php
$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"Name");
$f2=mysql_result($result,$i,"Address");
$f3=mysql_result($result,$i,"Type");
?>
<tr>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td>
</tr>
<?php
$i++;
}
?>
And here is get_xml2.php
Code: Select all
<?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 = 'Value1' AND Address = 'Value2' AND Type = 'Value3'";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
// Start XML file, echo parent node
echo '<markers>';
// 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 '</markers>';
?>
Here is a working example
http://tinyurl.com/6a76aek
As you can see, entering anything will return an empty xml file.