![]() |
Mysql search question?
How do I make my search box work?
I want them to search a specific field in a specific table and display matching results as a link, which you could click and then view informaiton pertaining to that subject. The part I don't know how to do is the search and display as a link. Can anyone help me? A short example code would be great! |
oh, and I know you have to use MATCH correct? but how do I display results? and how do I narrow the fields I"m searching whithin?
|
what language are you trying to do this in? php?
|
Oops, sorry yes php.
|
Here's a example of the php website:
[PHP] <?php // Connecting, selecting database $link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password') or die('Could not connect: ' . mysql_error()); echo 'Connected successfully'; mysql_select_db('my_database') or die('Could not select database'); // Performing SQL query $query = 'SELECT * FROM my_table'; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); // Printing results in HTML echo "<table>\n"; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "\t<tr>\n"; foreach ($line as $col_value) { echo "\t\t<td>$col_value</td>\n"; } echo "\t</tr>\n"; } echo "</table>\n"; // Free resultset mysql_free_result($result); // Closing connection mysql_close($link); ?> [/PHP] a list of all mysql related functions along with a few examples etc can be found here: http://ca3.php.net/manual/en/ref.mysql.php hope that helps. |
and to list them as links?
So it lists possible matches then you can select the one your are looking for and it will link you to more information about that item. |
to list em as links:
[PHP] <?php // Connecting, selecting database $link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password') or die('Could not connect: ' . mysql_error()); echo 'Connected successfully'; mysql_select_db('my_database') or die('Could not select database'); // Performing SQL query $query = 'SELECT * FROM my_table'; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); // Printing results in HTML echo "<table>\n"; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "\t<tr>\n"; foreach ($line as $col_value) { echo "\t\t<td><a href=\"www.somedomain/somepage.php?action=viewresult\">$col_value</a></td>\n"; } echo "\t</tr>\n"; } echo "</table>\n"; // Free resultset mysql_free_result($result); // Closing connection mysql_close($link); ?> [/PHP] something like that. you just need to put the html link tags around what you want. |
Cool! Thanks, I didin't know you could do that. :)
|
heh, you can do all sorts of things with php.
oh, and see this part: [PHP] echo "\t\t<td><a href=\"www.somedomain/somepage.php?action=viewresult\">$col_value</a></td>\n"; [/PHP] see the action var after the page name and the ? you can get the value of that var by doing this: [PHP] $mynewvar = $_GET['action']; //or you could just call the var strait, like into a if statment: if ($_GET['action'] == "something") { //do something. } //or you could pass it to a switch (my personaly fav way of doing stuff like that) switch ($_GET['action']) { case "something1": //do something1 break; case "something2": //do something2 break; } [/PHP] not sure if you knew how to do that, just thought i'd post and try and help out :-) anyways, if you got more questions, done hesitate to post em around here. also, since this is a php question, i moved it to the php forum :-) |
Ok thanks! Maybe you can help me a little with this part. This is the submit script for this piece of the db. What I"m wanting to do is take the file path and the name of the files uploaded and add them to their respective fields in a table. But everything I"ve tried causes an error or just inserts array[name] every time. so here's the code I"m using and maybe you can tell me what's wrong with it.
:
<?php |
| All times are GMT -5. The time now is 11:58 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC