Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Linux, Apache, MySQL > MySQL Help

MySQL Help Post any question relating to MySQL here and hopefully someone can help

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2004-07-26, 02:41 PM
Anonymous Coward
Guest
 
Posts: n/a
Default

Given
--------------
TABLE NAMES
Name:
mary
bob
steve

TABLE SENTENCES
ID: Sentence:
1 mary is hot
2 bob hit steve
3 steve likes steve
--------------

Please help me generate a query using PHP/MYSQL that is fast and works with large tables to do the following:

Determine the number of Names in each Sentence.

The result should look like this:

RESULT
SENTENCES.ID: COUNT(NAMES):
1 1
2 2
3 2

Please send any help to php-editors.com@nospam.phor.net

Thanks <_<
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2004-07-26, 03:18 PM
Xnuiem's Avatar
Senior Member
 
Join Date: May 2004
Location: DFW, Texas
Posts: 1,104
Xnuiem will become famous soon enough
Send a message via Yahoo to Xnuiem
Default

I thought there may have been a way to do this with MySQL but I cant find it.

1. Create an array of all the names

Code:
$nameArray = array();
$result = mysql_query("select distinct(lower(name)) from names");
while(list($name) = mysql_fetch_row($result)){
  $nameArray[] = $name;
}
2. Run through getting counts. I dont know what you want to do with the data, so I will put it into a simple array so you can do what you want.

Code:
$final = array();
$result = mysql_query("select id, lower(sentence) from sentences");
while(list($id, $sent) = mysql_fetch_row($result)){
  $count=0;
  foreach($nameArray as $n){
    $count += substr_count($sent, $n);
   }
   $final[$id] = $count;
}
__________________
I rarely give code examples.
No, I have never used IIS or Windows of any kind as a web server. Get a real OS!
Please don't PM me, I won't respond.
Reply With Quote
  #3 (permalink)  
Old 2004-07-27, 09:35 AM
Anonymous Coward
Guest
 
Posts: n/a
Default

thanks :P
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

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



All times are GMT -5. The time now is 06:50 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.