Forum Moderators: coopster
Database name = files
table name = applications
In the table I have the following
ID
appname
descr
I want the people to beable to put an app name in and have the vaules show up in a table.
Or if someone could show me a link to a site that shows you how to do this that would be cool too. Thanks
<?php
mysql_connect("aHost", "aUser", "aPassword");
mysql_select_db("files");
// Assume we are running under a web server
// and appName is in the URL as a parm
$appName = $_GET['appname'];
$dataSet = mysql_query("select descr from applications where appname like '%$appName%'");
$row = mysql_fetch_row($dataSet);
while ($row) {
print $row[0] . '<br>' . chr(10);
$row = mysql_fetch_row($dataSet);
}
?>
Appname Description
Adobe 7.0 A program that lets you view pdf
If I were to type adobe in the seach box and I searched for it, it would bring this up. If you guys and gals need more details let me know.
With regards to the text box/button biz, you then want to get the input variable from the POST php var, not the get ie.,
in the html:
<input type="text" name="appname" size="32">
<input type="submit" value="Perform Search">
... then in the PHP ...
$appName = $_POST['appname']
... or am I just missing you here?
This is just the query
$sql = "(SELECT appname, descr FROM applications WHERE appname LIKE '$appName%' ORDER BY appname) UNION (SELECT appname, descr FROM applications WHERE appname LIKE '%$appName%' ORDER BY appname)";
If you search $appName = "Eagle";
you will first get all apps starting with eagle:
Eagle 4.15...
then with word eagle inside
Network Eagle Monitor...
However this query will also find apps containing that search pattern:
Eaglemania
Weagles
etc
Hope this helps
Michal Cibor
I use FullText a lot and it works really nicely.
<html>
<head>
<title>Application Database</title>
<br>
<form>
<input type="text" name="appname" size="32">
<input type="submit" value="Perform Search">
</form>
<?
require("../test-php/util.php");
$sql = new MySQL_class;
$sql->Create("files");
echo("<h3>Selecting multiple rows</h3>\n");
echo("<p><ul><table border=1 cellpadding=4>\n");
echo("<tr><th>App Name</th><th>OS</th></tr>\n");
$sql->Query("Select appname, descr from applications order by appname");
for ($i = 0; $i < $sql->rows; $i++) {
$sql->Fetch($i);
$appname = $sql->data[0];
$descr = $sql->data[1];
echo("<tr><td>$appname</td><td>$descr</td></tr>\n");
}
echo("</table></ul>\n");
$sql = "(SELECT appname, descr FROM applications WHERE appname LIKE '$appName%' ORDER BY appname) UNION (SELECT appname, descr FROM applications WHERE appname LIKE '%$appName%' ORDER BY appname)";
?>
Now where do the results get displayed? Thanks
my particular style would be this:
<!-- html tags, header et al -->
<!-- php/MySQL code that performs a search into an array IF the form method is a post -->
<!-- html + php block that displays the form - and if the array has elements (ie., it was filled up in the prior PHP block) then put display the elements here -->
<!-- closing html, footers etc -->
Hope this helps - I'll check in mid-July when I return to see if you are still stuck.
-EP
one file form.html:
<html>
<head></head>
<body>
<title>Application Database</title>
<br>
<form action="process.php" method="POST">
<input type="text" name="appname" size="32">
<input type="submit" value="Perform Search">
</form></body></html>
Form requires attribute action - pointing where to send data. Method is GET or POST. get you see in url, post you don't - therefore post is much better, more user friendly
in second file process.php (the file that form is sent to)
<?
require("../test-php/util.php");
$sql = new MySQL_class;
$sql->Create("files");echo("<h3>Selecting multiple rows</h3>\n");
echo("<p><ul><table border=1 cellpadding=4>\n");
echo("<tr><th>App Name</th><th>OS</th></tr>\n");$sqlquery = "(SELECT appname, descr FROM applications WHERE appname LIKE '$appName%' ORDER BY appname) UNION (SELECT appname, descr FROM applications WHERE appname LIKE '%$appName%' ORDER BY appname)";
$sql->Query($sqlquery);for ($i = 0; $i < $sql->rows; $i++) {
$sql->Fetch($i);
$appname = $sql->data[0];
$descr = $sql->data[1];
echo("<tr><td>$appname</td><td>$descr</td></tr>\n");
}
echo("</table></ul>\n");
?>
And that's it.
Hope this helps you
Michal Cibor