jmr3460 Posted June 13, 2009 Share Posted June 13, 2009 I was just reading through a post that mentioned mysqli_num_row(). I was thinking of a way to use mysqli_row_num() then subtract from it a result from mysqli_result::fetch_array(), that matches any of an array that is a list of browsers that bots use. This might go something like this: $row = mysqli_number_row(); $botlist = array("a","b","c"); $bot = mysqli_result::fetch_array("$botlist"); $count = $row - $bot; echo $count; I would really like to keep this as simple as possible. Am I on the right track? My one concern is I want the $bot array to fetch the rows that have this the data in any part of the row. Will it search every field for that data? Quote Link to comment https://forums.phpfreaks.com/topic/162040-working-on-my-project/ Share on other sites More sharing options...
Maq Posted June 13, 2009 Share Posted June 13, 2009 If you have 2 arrays and want to filter out one of them, you can perform array_diff on them. i.e. $botlist = array("a","b","c"); $array = array("a","b","c","d","e","f","g","h","i","j","k","l","m"); print_r(array_diff($array, $botlist)); ?> (After reading your post again, I realized this isn't what you really wanted, but I will leave it up cause it may pose usefulness) My one concern is I want the $bot array to fetch the rows that have this the data in any part of the row. Will it search every field for that data? Sorry, I'm confused about what you're talking about. Can you explain exactly what you want to accomplish? Quote Link to comment https://forums.phpfreaks.com/topic/162040-working-on-my-project/#findComment-855110 Share on other sites More sharing options...
jmr3460 Posted June 13, 2009 Author Share Posted June 13, 2009 Thanks for the reply. I have been gone for a couple hours and could not reply any sooner> I have a counter that you may have helped me develop along with a few others from this site. It inserts data into a mysql data base table with an id, ip, time, and user_agent information. I wanted a simple way to insert all this data into the table. (this works) Since I really don't want to count the bots and such I was looking through some post and saw the mysqli_num_row() and did some research and thought that if I could count the total rows (i will call $row) in the table, then find all the rows that had bots (i will call $bots )in them and subtract $bots from $row this would come up with a more accurate number for my counter. I am sorry I am so long winded. Quote Link to comment https://forums.phpfreaks.com/topic/162040-working-on-my-project/#findComment-855223 Share on other sites More sharing options...
jmr3460 Posted June 14, 2009 Author Share Posted June 14, 2009 <?php $post2 = "wonderful"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/162040-working-on-my-project/#findComment-855346 Share on other sites More sharing options...
Maq Posted June 14, 2009 Share Posted June 14, 2009 Thanks for the reply. I have been gone for a couple hours and could not reply any sooner> I have a counter that you may have helped me develop along with a few others from this site. It inserts data into a mysql data base table with an id, ip, time, and user_agent information. I wanted a simple way to insert all this data into the table. (this works) Since I really don't want to count the bots and such I was looking through some post and saw the mysqli_num_row() and did some research and thought that if I could count the total rows (i will call $row) in the table, then find all the rows that had bots (i will call $bots )in them and subtract $bots from $row this would come up with a more accurate number for my counter. I am sorry I am so long winded. I see. I believe you can do this with a single query. Assuming you want to filter out the list of bots from the field, "ip", you can utilize the NOT IN clause. The syntax may be a bit off as I have not tested it, but I have left comments in the code. I also included 2 debugging statements, so if my syntax is incorrect, it will give you 'descriptive' error messages. ini_set ("display_errors", "1"); error_reporting(E_ALL); $botlist = array("a","b","c"); $botlist = implode(",",$botlist); $sql = "SELECT * FROM your_table WHERE ip NOT IN('$botlist')"; $result = mysqli_query($sql); // Not sure if you need the single quotes around $botlist $num_no_bots = mysqli_num_rows($result); echo $num_no_bots; ?> Quote Link to comment https://forums.phpfreaks.com/topic/162040-working-on-my-project/#findComment-855354 Share on other sites More sharing options...
jmr3460 Posted June 14, 2009 Author Share Posted June 14, 2009 Thanks I will try this as soon as I find out what settings I have to use on my editors. I seem to have something set wrong with the encoding. If you will look at my post you will see a space at the top of them and it is causing a problem with my code. I know that this is not the forum to do this in, could someone tell me where I go to ask about this question? I have tried several different editors and they all do the same thing. I am lost as far an encoding. Where do I need to post this question? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/162040-working-on-my-project/#findComment-855386 Share on other sites More sharing options...
Maq Posted June 14, 2009 Share Posted June 14, 2009 Try opening it up in VIM or notepad to see what's actually there. I have tried several different editors and they all do the same thing. I am lost as far an encoding. Where do I need to post this question? If you have a question about editors and encoding I would suggest Editor Help. Quote Link to comment https://forums.phpfreaks.com/topic/162040-working-on-my-project/#findComment-855397 Share on other sites More sharing options...
jmr3460 Posted June 14, 2009 Author Share Posted June 14, 2009 OK I get a notice and warning and fatal error. Notice: Undefined variable: botlist in /home3/simplic5/public_html/index.php on line 33 Warning: implode() [function.implode]: Bad arguments. in /home3/simplic5/public_html/index.php on line 33 Fatal error: Call to undefined function: mysqli_query() in /home3/simplic5/public_html/index.php on line 35 This is my code: <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); include("db_in.php"); $table = "counter"; $ip = getenv('REMOTE_ADDR'); $date = date("M-d-Y H:i:s", time()+3600); $browser = $_SERVER['HTTP_USER_AGENT']; if (!isset($_COOKIE['clean'])) { setcookie("clean","cleantime",time()+7200,"/"); mysql_connect($host, $user, $pass); mysql_select_db($database) or die(mysql_error()); mysql_query("INSERT INTO $table values('id','$ip','$date','$browser')") or die(mysql_error()); //$data = mysql_query("SELECT id FROM $table ORDER BY id DESC LIMIT 1;"); //$info = mysql_fetch_array($data); //$count = $info['id']; include("$botlist.php"); $botlist = implode(",",$botlist); $sql = "SELECT * FROM your_table WHERE ip NOT IN('$botlist')"; $result = mysqli_query($sql); // Not sure if you need the single quotes around $botlist $count = mysqli_num_rows($result); } else { mysql_connect($host, $user, $pass); mysql_select_db($database) or die(mysql_error()); //$data = mysql_query("SELECT id FROM $table ORDER BY id DESC LIMIT 1;"); //$info = mysql_fetch_array($data); //$count = $info['id']; include("botlist.php"); $botlist = implode(",",$botlist); $sql = "SELECT * FROM $table WHERE browser NOT IN('$botlist')"; $result = mysqli_query($sql); // Not sure if you need the single quotes around $botlist $count = mysqli_num_rows($result); } ?> <html> <body> <?php echo $count; ?> </body> </html> This is my include file: <?php $botlist = array("YandexSomething/1.0", "Baiduspider+(+http://www.baidu.com/search/spider.htm)", "TurnitinBot/2.1 (http://www.turnitin.com/robot/crawlerinfo.html)", "LinkWalker/2.0", "Gigabot/3.0 (http://www.gigablast.com/spider.html)", "Sogou web spider/4.0(+http://www.sogou.com/docs/help/webmasters.htm#07)"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/162040-working-on-my-project/#findComment-855447 Share on other sites More sharing options...
jmr3460 Posted June 14, 2009 Author Share Posted June 14, 2009 Has someone been able to look at this. line 35 is the one that selects all from table where browser not in $botlist. Am I going about this the right way. I have tried it with double quotes no quotes. I don't know what else I should try. What is a good argument for the implode function? Why are we using this function? Quote Link to comment https://forums.phpfreaks.com/topic/162040-working-on-my-project/#findComment-855707 Share on other sites More sharing options...
Maq Posted June 15, 2009 Share Posted June 15, 2009 Has someone been able to look at this. line 35 is the one that selects all from table where browser not in $botlist. Am I going about this the right way. I have tried it with double quotes no quotes. I don't know what else I should try. What is a good argument for the implode function? Why are we using this function? Is this line 33? include("$botlist.php"); The variable $botlist isn't defined here, I think you meant just, "botlist.php". Try changing this include, it should get rid of all the other errors. Yes, implode only takes an array and an optional string. Read more here - implode. Quote Link to comment https://forums.phpfreaks.com/topic/162040-working-on-my-project/#findComment-856191 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.