I am currently building an application with the use of MobiOne studio in order to use their publication features. I however have run across a unique problem. The app, at it's most basic, queries the user for data to be entered into a hosted MYSQL database. Then via search box, thy can recall certain records from the same MYSQL database. The insertion part works perfectly. However, I can not get the results to display. I CAN make this work in any old browser with a simple PHP snippet to display the records in a loop for as many results as there are.
However, PHP does not run smoothly in a client run situation as this. MobiOne preferes the use of Javascript/JSON/JQuery to display data. Is there anyway to display the contents of the loop created by the PHP script serverside via Javascript to a HTML block or DOM?
The below is the PHP code I use to find the content from a GET form with the id "query" on a seperate index.php file. Like I said, this works great. But I need to be able to take the data this spits out and display it with some JS.
Please check this link out as an example of what the code actually does, if you are not sure. Just enter "cracker" as a test search query.
http://tjrcomputersolutions.com/apps/edibles/v1.0/index.php
<?php
//capture search term and remove spaces at its both ends if the is any
$searchTerm = trim($_GET['query']);
//check whether the name parsed is empty
if($searchTerm == "")
{
echo "Enter name you are searching for.";
exit();
}
//database connection info
$host = "localhost"; //server
$db = "*****"; //database name
$user = "*****"; //database user name
$pwd = "*****"; //password
//connecting to server and creating link to database
$link = mysqli_connect($host, $user, $pwd, $db);
//MYSQL search statement
$query = "SELECT * FROM items WHERE item LIKE '%$searchTerm%'";
$results = mysqli_query($link, $query);
/* check whether there were matching records in the table
by counting the number of results returned */
if(mysqli_num_rows($results) >= 1)
{
$output = "";
while($row = mysqli_fetch_array($results))
{
$output .= "Item: " . $row['item'] . "<br />";
$output .= "Store: " . $row['store'] . "<br />";
$output .= "Size: " . $row['size'] . "<br />";
$output .= "Price: " . $row['price'] . "<br /><br />";
}
echo $output;
}
else
echo "There was no matching record for the name " . $searchTerm;
?>