Mcpie Posted November 2, 2009 Share Posted November 2, 2009 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. Link to comment https://forums.phpfreaks.com/topic/179982-mysql-search-query-based-on-previously-pulled-array-result/ Share on other sites More sharing options...
JAY6390 Posted November 2, 2009 Share Posted November 2, 2009 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 Link to comment https://forums.phpfreaks.com/topic/179982-mysql-search-query-based-on-previously-pulled-array-result/#findComment-949487 Share on other sites More sharing options...
Mcpie Posted November 2, 2009 Author Share Posted November 2, 2009 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. Link to comment https://forums.phpfreaks.com/topic/179982-mysql-search-query-based-on-previously-pulled-array-result/#findComment-949522 Share on other sites More sharing options...
JAY6390 Posted November 2, 2009 Share Posted November 2, 2009 It would do it for each row returned by your query (so long as your code is within the while loop) Link to comment https://forums.phpfreaks.com/topic/179982-mysql-search-query-based-on-previously-pulled-array-result/#findComment-949523 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.