Jump to content

Count 'Banned'


RON_ron

Recommended Posts

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);

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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) );

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.