RON_ron Posted November 25, 2010 Share Posted November 25, 2010 I want to get the COUNT if any of these fields (Fielda, Fieldb, Fieldc, Fieldd, Fielde, Fieldf, Fieldg, Fieldh) contain the word "Banned". But this code doesn't work. $like = count("Fielda, Fieldb, Fieldc, Fieldd, Fielde, Fieldf, Fieldg, Fieldh LIKE '%".implode("%' OR Fielda, Fieldb, Fieldc, Fieldd, Fielde, Fieldf, Fieldg, Fieldh LIKE '%", explode('Banned'))."%'"); echo($like); Quote Link to comment https://forums.phpfreaks.com/topic/219802-count-banned/ Share on other sites More sharing options...
MrXHellboy Posted November 25, 2010 Share Posted November 25, 2010 This is stored in an array ? Quote Link to comment https://forums.phpfreaks.com/topic/219802-count-banned/#findComment-1139460 Share on other sites More sharing options...
RON_ron Posted November 25, 2010 Author Share Posted November 25, 2010 No. $SomeVar = 'myname'; $like = count("Fielda, Fieldb, Fieldc, Fieldd, Fielde, Fieldf, Fieldg, Fieldh LIKE '%".implode("%' OR Fielda, Fieldb, Fieldc, Fieldd, Fielde, Fieldf, Fieldg, Fieldh LIKE '%", explode('Banned'))."%'WHERE news_idz = '".$SomeVar."'"); echo($like); I'm getting these ERROR messages; Warning: Wrong parameter count for explode() Warning: implode() [function.implode]: Invalid arguments passed Quote Link to comment https://forums.phpfreaks.com/topic/219802-count-banned/#findComment-1139461 Share on other sites More sharing options...
MrXHellboy Posted November 25, 2010 Share Posted November 25, 2010 The function count() does not work like this as far as i know... explode..... You forgot the delimiter...... Quote Link to comment https://forums.phpfreaks.com/topic/219802-count-banned/#findComment-1139464 Share on other sites More sharing options...
RON_ron Posted November 25, 2010 Author Share Posted November 25, 2010 Any suggestions in getting the COUNT? Quote Link to comment https://forums.phpfreaks.com/topic/219802-count-banned/#findComment-1139465 Share on other sites More sharing options...
MrXHellboy Posted November 25, 2010 Share Posted November 25, 2010 Just give us your code and tell what you want.... We can check for you Quote Link to comment https://forums.phpfreaks.com/topic/219802-count-banned/#findComment-1139466 Share on other sites More sharing options...
suma237 Posted November 25, 2010 Share Posted November 25, 2010 $s="F1,F2,F3,F4";$y=explode(',',$s); then use array function to compare Quote Link to comment https://forums.phpfreaks.com/topic/219802-count-banned/#findComment-1139467 Share on other sites More sharing options...
RON_ron Posted November 25, 2010 Author Share Posted November 25, 2010 Help in fixing this. $SomeVar = 'myname'; $like = "SELECT Fielda, Fieldb, Fieldc, Fieldd, Fielde, Fieldf, Fieldg, Fieldh FROM db1 WHERE subjectz = '".$SomeVar."'"; $y= explode("Banned", $like); $ArrayUsrD = array($like); $ArrayMrkD = array($y); $countF = count( array_intersect($ArrayUsrD, $ArrayMrkD) ); Quote Link to comment https://forums.phpfreaks.com/topic/219802-count-banned/#findComment-1139614 Share on other sites More sharing options...
ignace Posted November 25, 2010 Share Posted November 25, 2010 If the above view is your vision on PHP programming then helping you is the worst thing one can do. Buy a book and learn PHP first you are a long way from home. Quote Link to comment https://forums.phpfreaks.com/topic/219802-count-banned/#findComment-1139632 Share on other sites More sharing options...
RON_ron Posted November 25, 2010 Author Share Posted November 25, 2010 That's somewhat I'm trying to do here... Learning! Could someone help me out? Quote Link to comment https://forums.phpfreaks.com/topic/219802-count-banned/#findComment-1139660 Share on other sites More sharing options...
Anti-Moronic Posted November 25, 2010 Share Posted November 25, 2010 That's somewhat I'm trying to do here... Learning! Could someone help me out? I think he means because you are missing some very basic things which make this problem pointless in solving: you are going to run into MANY more if you don't first buy a php book or read some tutorials. The problem here is that you are trying to implement something with php which sql should be implementing and by the looks of it your database structure is all wrong too. You need to learn some sql too. You are selecting 'from db1' which is actually a table and you are searching all of the rows in the column subjectz for the word BANNED. Why? Could be a valid reason, but my suggestion is that you would have a far easier time if you had a flag column called banned, or active and set that to 0 or 1. You are naming your columns fieldA fieldB etc - that's terrible. They should make somekind of sense, like if you came back to this 6 months later. Would you have any idea what kind of data these columns contain? I doubt it. ..wait..just realized too - you are not even running a sql query. You're simply storing the query in a variable and using count() (which counts arrays btw) and expecting it to fetch a result. You need to look at how to run sql query and count rows with mysql_num_rows(). There is a lot wrong with your code and I'm not even sure how you have gotten this far. Be glad to answer any of your other questions provided you have actually read this post and are willing to learn. Quote Link to comment https://forums.phpfreaks.com/topic/219802-count-banned/#findComment-1139664 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.