Jump to content

MySQL Search Query based on previously pulled Array result


Mcpie

Recommended Posts

Hi guys, sorry for what is probably a stupidly easy question, but I've been pulling my hair out all morning over this, and as you will soon see, I have no idea what I'm doing.

 

Basically, I have a two step process here.

 

Step 1: Select all Headline data from MySQL where the field ArticleURL contains my address of choice.

Step 2: Using the Headlines generated in Step 1, query the database again and get a count of all Headline duplicates.

 

Step 1 is pretty simple:

 

  1 <?PHP
  2
  3 $connect = mysql_connect("localhost","user","password");
  4
  5 mysql_select_db("database",$connect);
  6
  7 $query = mysql_query("SELECT Headline FROM blogs table WHERE articleURL LIKE '%http://www.url.com%';");
  8 
  9 while ($array = mysql_fetch_array($query)){
  11 What the heck goes here?}
  12?>
  

 

The next step is to use those values ( in an array), to populate the next query.  I suspect I need to use a loop, but don't know what to enter to get Mysql and PHP to play nice  e.g,

 

SELECT COUNT(Headline) FROM table WHERE Headline LIKE '%ARRAY-RESULT1%';

 

I want it to then loop through all the array results and simply spit out the number of duplicates found.

 

Any help would be greatly appreciated.

You need to use the $array in that part. for instance, if you wanted to use the content of a certain colum and assign it to a variable you can do so like this

 

$variable_name = $array['column_name'];

so you could have

$post_content = $array['content'];

for example

Thanks for your respose.

 

Quick question-- wouldn't that only search and match the first value, then quit?

 

E.g, I think it would perfect for the first match, but I don't think it would go through 1, 2, 3 etc and spit out the required values.

 

Example Data

 

Headline            ArticleURL

Mcpie Sucks      google.com

Mcpie Sucks      ask.com

Mcpie can't code google.com

Mcpie can't code ask.com

 

 

The first query, if targetted at google.com woul return two results.  Mcpie Sucks and Mcpie can't code.  I would then want to query based on the first Headline and get a return value of 2.  Then have it go through the second value, and also, in this case, return a value of 2.

 

Make sense?  Thanks again for your time.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.