Forum Moderators: coopster

Message Too Old, No Replies

Form Query Multiple fileds for one distinct term.

         

Street14

5:58 am on Nov 8, 2006 (gmt 0)

10+ Year Member



Well i have been trying to resolve this while learning a bit of php at the same time. As the previous sentence implys i do not know much about php. But im hoping some or many can help me with this.
The object of the form/query and results is to compare entries of said term.
There are about 20 fields all total.
There are 14 fields to search for one distinct term.
No entry will be duplicated in the entry.
so ID #1 Filed h1 has text bull as the entry.
In ID #1 or entry number one h2,h3,h4,h5 and so on too 14 will have different terms but will not have the text "bull" in another field.
Entery number 2 or ID #2 can have the same term "bull in it but then again in entry number 2 or ID#2 bull will not be there in any other field but the one. So it looks like this
/////table structure////
ID//sm///?///?///?///H1 //?//?///H2 ///?//?/// H3 and so on
1 //?//?////?///?//bull//?//?///eye///?//?///red and so on
2 //?//?////?//?//eye//?//?///bull///?//?///blue and so on

So you see the table above.
The form needs to be able to search the "H Fields for one term.
Now i have got something working kind of.
I can get the search to work for the term
I have to problems though one is formating of the output second problem is the query returns duplicate data.
Now the data is not duplicated in the table only the output of the query.
Here is the code i have so far.
<code>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
Search Word: <input type="text" name="query">
<input type="SUBMIT" value="Search!">
</form>
<?
$username = "street15486";
$password = "startup";
$hostname = "localhost";
$db = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");

$query = addslashes($_POST['query']);
mysql_select_db("ajumbled_bcup2006", $db);
$sql = mysql_query("SELECT * FROM compendium WHERE h1 LIKE '" . $query . "' OR h2 LIKE '" . $query . "' OR h3 LIKE '" . $query ."'") or die (mysql_error());

while($row=mysql_fetch_array($sql)){

foreach($row as $field) {
echo " , " . $field;
}
echo "<br />";
}

mysql_close($db);
?>
</code>
Id like to have the query not produce a duplicate.
Id also like to have the output in a table form like you would see in a normal sql query output with table filed headers and formatted in cells.
IM stuck at this point and do not know what to do or how to resolve it any further.
I hope someone can help

[edited by: Street14 at 6:00 am (utc) on Nov. 8, 2006]

Street14

8:12 am on Nov 8, 2006 (gmt 0)

10+ Year Member



I have a answer to this.
Setup a normal table format for showing a table from a query is the solution to both the formatting and the double posting.
A bit tricky to get them working together but it does work.