Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 20th, 2005, 10:43 AM   #1
dmorales
Programmer
 
Join Date: Feb 2005
Posts: 74
Rep Power: 4 dmorales is on a distinguished road
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...
dmorales is offline   Reply With Quote
Old Apr 20th, 2005, 10:49 AM   #2
dmorales
Programmer
 
Join Date: Feb 2005
Posts: 74
Rep Power: 4 dmorales is on a distinguished road
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...
dmorales is offline   Reply With Quote
Old Apr 20th, 2005, 11:16 AM   #3
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
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!
Pizentios is offline   Reply With Quote
Old Apr 21st, 2005, 8:51 AM   #4
dmorales
Programmer
 
Join Date: Feb 2005
Posts: 74
Rep Power: 4 dmorales is on a distinguished road
Oops, sorry yes php.
__________________
Lorem ipsum dolor sit amet...
dmorales is offline   Reply With Quote
Old Apr 21st, 2005, 9:06 AM   #5
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
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!
Pizentios is offline   Reply With Quote
Old Apr 21st, 2005, 1:36 PM   #6
dmorales
Programmer
 
Join Date: Feb 2005
Posts: 74
Rep Power: 4 dmorales is on a distinguished road
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...
dmorales is offline   Reply With Quote
Old Apr 21st, 2005, 3:45 PM   #7
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
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!
Pizentios is offline   Reply With Quote
Old Apr 21st, 2005, 11:20 PM   #8
dmorales
Programmer
 
Join Date: Feb 2005
Posts: 74
Rep Power: 4 dmorales is on a distinguished road
Cool! Thanks, I didin't know you could do that.
__________________
Lorem ipsum dolor sit amet...
dmorales is offline   Reply With Quote
Old Apr 22nd, 2005, 8:44 AM   #9
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
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.
Pizentios is offline   Reply With Quote
Old Apr 22nd, 2005, 12:38 PM   #10
dmorales
Programmer
 
Join Date: Feb 2005
Posts: 74
Rep Power: 4 dmorales is on a distinguished road
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...
dmorales is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:35 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC