Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP Search MySQL Field
Old 11-17-2005, 08:05 AM PHP Search MySQL Field
Skilled Talker

Posts: 58
Trades: 0
Hi,

I have a field in a table with the following value

FIELD 1 = BA340-A380-Airbus

There is about 50 fields.

I need to run a search to show me all the fields that somewhere in its text have A380 in it. How do I go about getting this done?

I can search in the whole field but I dont know how to search for only one word inside that field.

Thanks!!
Llama is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-17-2005, 08:20 AM
Nahele's Avatar
Extreme Talker

Posts: 204
Trades: 1
Since there are a relative low number of entires in your database, you can simply grab all the rows and then use php to search if "A380" is found in field 1 with strpos($each_row, $searching_for) command.

something along the lines of:
PHP Code:
//connect to database

$results mysql_query (SELECT FROM table_name);
while (
$row mysql_fetch_array ($results)) {
  if (
strpos($row[0], "A380") <> false) {
    print (
$row[0]);   //or whatever you want to do here with that entry
  
}

There might be a way to do in mysql so you don't have to import the entire table, but I don't know how

Last edited by Nahele; 11-17-2005 at 08:28 AM..
Nahele is offline
Reply With Quote
View Public Profile
 
Old 11-17-2005, 09:26 AM
Skilled Talker

Posts: 58
Trades: 0
Hi, this unfortunately does not to seem to work in my instance.

Let me try and better explain... ( i suck with this)

ROW 1 - FIELD 1: BA240-A380-Airbus
- FIELD 2: Part Name 1
ROW 2 - FIELD 1: BC234-B747-Boeing
- FIELD 2: Part Name 2
ROW 3 - FIELD 1: BR241-A380-AirF
- FIELD 2: Part Name 3

I then want to search for and display all the records containing the text "A380".

So my result should look like:

"Part Name 1" and "Part Name 2" has used A380.

Does this explain a little better?
Can you help me please?
Llama is offline
Reply With Quote
View Public Profile
 
Old 11-17-2005, 09:27 AM
Skilled Talker

Posts: 58
Trades: 0
Sorry Typ-O :-)

it should read:

"Part Name 1" and "Part Name 3" has used A380.
Llama is offline
Reply With Quote
View Public Profile
 
Old 11-17-2005, 10:02 AM
Skilled Talker

Posts: 58
Trades: 0
I got it right!!!
I used MySQL rather than PHP

Thanks for the help anywhoo,.... here is the code I used...

<?php

$query= "SELECT * FROM parts WHERE part_componant1 = '$sel_componant_1' LIKE '%B747%'";

$rs = mysql_query($query) or die(mysql_error());
$num_rows = mysql_num_rows($rs);

while ($row = mysql_fetch_array($rs))
{
$id = $row['Id'];
$used_on = $row['used_on_1'];
echo ($used_on . '<br>');

}


?>
Llama is offline
Reply With Quote
View Public Profile
 
Old 11-17-2005, 08:19 PM
Nahele's Avatar
Extreme Talker

Posts: 204
Trades: 1
Good to know for future sql queries.
Nahele is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP Search MySQL Field
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.22385 seconds with 12 queries