PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 16th, 1999, 08:59 AM
belutz
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
hi..
first of all i want to sorry about my bad english.
how do i make php script for searching in mysql database ?
i want to make a student search..
the field is student_number, name, address, and faculty.
what would the php script look like ?

Thanks

Reply With Quote
  #2  
Old July 27th, 1999, 02:45 PM
moderator
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
I'm not too clear on the details of what you're asking, but the script might look something like this.


First we need to define the query we'll be using:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
<?
mysql_connect($mysqlServer,$mysqlUser,$mysqlPassword);
mysql_select_db($mysqlDB);
if($student_id){$searchResult=mysql_query("select * from tableName where student_id='$student_id'");}
elseif($name){$searchResult=mysql_query("select * from tableName where name like '%$name%'");}
elseif($address){$searchResult=mysql_query("select * from ...
?>
[/quote]

Then you need to read the information out:

<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
<?
while($student=mysql_fetch_array($searchResult)){
echo "ID: $student[student_id]<br>";
echo "Name: $student[name]<br>";
echo "Address: $student[address]<br>";
echo "Faculty: $student[faculty]<br><br>";
}
?>
[/quote]

That may not be exactly what you want, but I hope it helps....

Reply With Quote
  #3  
Old July 27th, 1999, 03:02 PM
mfitzgerald
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
This is kind of on the same topic:

How do you cut up or format the variable before it the search begins?
For example, if the datebase has the student name as 'Steve Smith', but the user enters 'Smith, Steve' how can I split this string and search the whole database for all occurences of steve and smith?
thanks.
michael

Reply With Quote
  #4  
Old July 27th, 1999, 09:33 PM
chyrag
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
If the bits are always going to be delimited by a comma, then one can split the string by the comma and then -

$command = "select * from table where
name like '%$name1%' or
name like '%name2%';";

then mysql_db_query.. etc.

chyrag.


[This message has been edited by chyrag (edited 07-27-99).]

Reply With Quote
  #5  
Old July 28th, 1999, 05:04 PM
mfitzgerald
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Thanks.
What if there isn't a comma? What you have no control over how they enter it? How do you just dice up the string into individual complete words?
-michael

Reply With Quote
  #6  
Old July 28th, 1999, 08:22 PM
DesertFox
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Michael,

There might be a function that will splice a string into each individual word. I'm not sure but explode comes to mind.

Or, you would have to develop a script that will read each character and build a word letter by letter and when a comma or space appears use it as a marker that the word ended.


Hope this helps.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Database search engine


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway