![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Feb 2005
Posts: 74
Rep Power: 4
![]() |
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!
__________________
Lorem ipsum dolor sit amet... |
|
|
|
|
|
#2 |
|
Programmer
Join Date: Feb 2005
Posts: 74
Rep Power: 4
![]() |
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?
__________________
Lorem ipsum dolor sit amet... |
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() |
what language are you trying to do this in? php?
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Feb 2005
Posts: 74
Rep Power: 4
![]() |
Oops, sorry yes php.
__________________
Lorem ipsum dolor sit amet... |
|
|
|
|
|
#5 |
|
Programming Guru
![]() ![]() |
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.
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! |
|
|
|
|
|
#6 |
|
Programmer
Join Date: Feb 2005
Posts: 74
Rep Power: 4
![]() |
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.
__________________
Lorem ipsum dolor sit amet... |
|
|
|
|
|
#7 |
|
Programming Guru
![]() ![]() |
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.
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! |
|
|
|
|
|
#8 |
|
Programmer
Join Date: Feb 2005
Posts: 74
Rep Power: 4
![]() |
Cool! Thanks, I didin't know you could do that.
![]()
__________________
Lorem ipsum dolor sit amet... |
|
|
|
|
|
#9 |
|
Programming Guru
![]() ![]() |
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 :-)
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! Last edited by Pizentios; Apr 22nd, 2005 at 8:53 AM. |
|
|
|
|
|
#10 |
|
Programmer
Join Date: Feb 2005
Posts: 74
Rep Power: 4
![]() |
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
//check required fields
if (($_POST['add_work_order_client'] == "") || ($_POST['add_work_order_work'] == "") || ($_POST['add_work_order_subject'] == "")) {
echo
"<body link='black' alink='red' vlink='red'>
<font color=red><strong>Please enter all required information</strong></font><br /><br />
<a href='/add_work_order.php'>back</a>
</body>";
} else {
//connect to Mysql and select db
$conn = mysql_connect('localhost', 'root', '')
or die(mysql_error());
mysql_select_db('anchor_db', $conn) or die(mysql_error());
//get master id
$master_id = mysql_insert_id();
//add to work_orders table
$add_work = "insert into work_orders values ('', $master_id, now(), now(), '$_POST[add_work_order_work]',
'$_POST[add_work_order_subject]')";
@mysql_query($add_work) or die(mysql_error());
//Upload files
if ($_FILES['add_work_order_screen'] != "") {
@copy($_FILES[add_work_order_screen][tmp_name], "c:/Program Files/EasyPHP1-7/www/screenshot files/".$_FILES[add_work_order_screen][name]);
echo "<p>Screenshot Successfully Uploaded</p>";
} else {
echo "Couldn't Copy Screenshots File";
}
if ($_FILES['add_work_order'] != "") {
@copy($_FILES['add_work_order']['tmp_name'], "c:/Program Files/EasyPHP1-7/www/work order files/".$_FILES[add_work_order][name]);
echo "<p>Work Order Successfully Uploaded</p>";
} else {
echo "Couldn't Copy Work Order File";
}
//check relevance
if (($_POST['add_work_order_text']) || ($_POST['add_work_order_screen']) || ($_POST['add_work_order'])) {
//add to wocontents table
$add_contents = "insert into wocontents values ('', $master_id, now(), now(), '$_POST[add_work_order_text]',
'c:/Program Files/EasyPHP1-7/www/screenshot files/'.$_FILES[add_work_order_screen][name], 'c:/Program Files/EasyPHP1-7/www/work order files/'.$_FILES[add_work_order][name])";
@mysql_query($add_contents) or die(mysql_error());
}
echo "<p>Your entry has been successfully added</p>";
echo "<p><strong>Would you like to:</strong></p> <p><a href='http://localhost/add_work_order.php'>add another?</a></p>";
echo "<p><a href='http://localhost/'>Go home?</a></p>";
}
?>
__________________
Lorem ipsum dolor sit amet... |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|