Re: [PHP] count clicks to count most important news
On Jan 1, 2012, at 11:26 AM, muad shibani wrote: I have a website that posts the most important news according to the number of clicks to that news the question is : what is the best way to prevent multiple clicks from the same visitor? Not a fool-proof method, but use Javascript on the client-side to stop users' from continuous clicking. Then create a token and verify the click on the server-side before considering the click as being acceptable. Cheers, tedd _ t...@sperling.com http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count clicks to count most important news
On Sun, 2012-01-01 at 11:49 -0500, Tedd Sperling wrote: On Jan 1, 2012, at 11:26 AM, muad shibani wrote: I have a website that posts the most important news according to the number of clicks to that news the question is : what is the best way to prevent multiple clicks from the same visitor? Not a fool-proof method, but use Javascript on the client-side to stop users' from continuous clicking. Then create a token and verify the click on the server-side before considering the click as being acceptable. Cheers, tedd _ t...@sperling.com http://sperling.com There are still problems with this, GET data (which essentially only what a clicked link would produce if you leave Javascript out the equation - you can't rely on Javascript) shouldn't be used to trigger a change on the server (in your case a counter increment) I did something similar for a competition site a few years ago, and stupidly didn't think about this at the time. Someone ended up gaming the system by including an image with the clicked-through URL in the src attribute, and put that on their MySpace profile page, which had more than a few visitors. Each of those visitors browser attempted to grab that image which registered a click, and because of the number of unique visitors, the clicks were registered as genuine. I'd recommend using POST data for this reason, as it's a lot more difficult for people to game. -- Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] count clicks to count most important news
On 01-01-2012 20:08, Ashley Sheridan wrote: On Sun, 2012-01-01 at 11:49 -0500, Tedd Sperling wrote: On Jan 1, 2012, at 11:26 AM, muad shibani wrote: I have a website that posts the most important news according to the number of clicks to that news the question is : what is the best way to prevent multiple clicks from the same visitor? Not a fool-proof method, but use Javascript on the client-side to stop users' from continuous clicking. Then create a token and verify the click on the server-side before considering the click as being acceptable. Cheers, tedd _ t...@sperling.com http://sperling.com There are still problems with this, GET data (which essentially only what a clicked link would produce if you leave Javascript out the equation - you can't rely on Javascript) shouldn't be used to trigger a change on the server (in your case a counter increment) I did something similar for a competition site a few years ago, and stupidly didn't think about this at the time. Someone ended up gaming the system by including an image with the clicked-through URL in the src attribute, and put that on their MySpace profile page, which had more than a few visitors. Each of those visitors browser attempted to grab that image which registered a click, and because of the number of unique visitors, the clicks were registered as genuine. I'd recommend using POST data for this reason, as it's a lot more difficult for people to game. I agree, POST data is indeed the way to go here. Personally, I would use a like image-like thing which is actually a button, using some clever javascript (personally I would use jquery for this) you can then POST data to the server based on the click. Then set a cookie which disables the button (and keeps it disabled on future visits). This should prevent average person from repeatedly clicking it. You could also log the person's IP adress and filter based on that aswell; combining various methods would be best in this case I think. To prevent the method which Ashley mentioned, using POST data isn't enough. You would want to guarantee that the link came from YOUR server instead of some different place. There are multiple ways to do this: - use a unique key as an argument in the POST which can only be clicked once. Register the key in a database before serving the page, and then unregister it once it has been served and clicked. Though if a person were to repeatedly open the page, your cache would be exhausted, and the method would become useless. - require a referrer address to come from your domain; also reasonably easily circumvented in this case - there are more, but it really depends on how much effort you want to put into preventing attacks and how much effort you expect others to put into attacking it. For example, large sites like youtube are sure to use extensive measures to prevent people from spam-clicking in any way. While sites that only cater to say 3 visitors a month don't require all that effort in the first place. Hope that helps, - Tul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count clicks to count most important news
On 1 Jan 2012, at 16:26, muad shibani wrote: I have a website that posts the most important news according to the number of clicks to that news the question is : what is the best way to prevent multiple clicks from the same visitor? I'm assuming this is not a voting system, and the news items you're counting are sourced from your own site and, with all due respect to Ash, unlikely to be a target for false clicks. All you're really wanting to do is prevent the site from registering multiple hits from the same user in a short period of time. I would probably use memcached on the server-side to store short-term information about clicks. When a news item is loaded... 1) Construct the memcache key: newsclick_article_id_ip_address. 2) Fetch the key from memcache. 3a) If it does not exist, log the hit. 3b) If it does exist, compare time() with the value and only log the hit if time() is greater. 4) Store the key with a value of time() + 300 and an expiry of the same value. This will prevent hits being logged for the same news item from the same IP address within 5 minutes of other hits. Other alternatives would be to use cookies (could get messy, and not very reliable since it requires the response from click 1 to be processed before click 2 gets started), Javascript (as suggested by tedd but without the token - it would work pretty well and would be a lot easier to implement than the above, but you sacrifice having full control over it). If I'm interpreting the requirement correctly my solution is almost certainly overkill, and a simple Javascript solution would be more than sufficient. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count clicks to count most important news
All the answers are great but Stuart Dallas' answer is what I was asking about .. thank u all I really appreciate it a lot On Sun, Jan 1, 2012 at 11:10 PM, Stuart Dallas stu...@3ft9.com wrote: On 1 Jan 2012, at 16:26, muad shibani wrote: I have a website that posts the most important news according to the number of clicks to that news the question is : what is the best way to prevent multiple clicks from the same visitor? I'm assuming this is not a voting system, and the news items you're counting are sourced from your own site and, with all due respect to Ash, unlikely to be a target for false clicks. All you're really wanting to do is prevent the site from registering multiple hits from the same user in a short period of time. I would probably use memcached on the server-side to store short-term information about clicks. When a news item is loaded... 1) Construct the memcache key: newsclick_article_id_ip_address. 2) Fetch the key from memcache. 3a) If it does not exist, log the hit. 3b) If it does exist, compare time() with the value and only log the hit if time() is greater. 4) Store the key with a value of time() + 300 and an expiry of the same value. This will prevent hits being logged for the same news item from the same IP address within 5 minutes of other hits. Other alternatives would be to use cookies (could get messy, and not very reliable since it requires the response from click 1 to be processed before click 2 gets started), Javascript (as suggested by tedd but without the token - it would work pretty well and would be a lot easier to implement than the above, but you sacrifice having full control over it). If I'm interpreting the requirement correctly my solution is almost certainly overkill, and a simple Javascript solution would be more than sufficient. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- *___* * * السجل .. كل الأخبار من كل مكان www.alsjl.com صفحة السجل على فيسبوك http://www.facebook.com/alsjl *Muad Shibani* * * Aden Yemen Mobile: 00967 733045678 www.muadshibani.com
Re: [PHP] Count the Number of Certain Elements in An Array
On Mon, Jan 11, 2010 at 6:21 PM, Alice Wei aj...@alumni.iu.edu wrote: Hi, This seems like a pretty simple problem, but I can't seem to be able to figure it out. I have a lot of elements in an array, and some of them are duplicates, but I don't want to delete them because I have other purposes for it. Is it possible for me to find out the number of certain elements in an array? For example, // Create a simple array. $array = array(1, 2, 3, 4, 5, 3,3,4,2); $total = count($array); echo $total; If I run the code, the value of $total would be 9. However, what I really want to do is to get the values of the different instances of each, like: 1 = 1 2 = 2 3 = 3 4= 2 5= 1 Is there a simple code that I use to find this out? Thanks for your help. Alice _ Hotmail: Trusted email with powerful SPAM protection. http://clk.atdmt.com/GBL/go/196390707/direct/01/ Hi, Try the function array_count_values. Regards, Jonathan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Count the Number of Certain Elements in An Array
Date: Mon, 11 Jan 2010 18:31:43 -0300 Subject: Re: [PHP] Count the Number of Certain Elements in An Array From: tapi...@gmail.com To: aj...@alumni.iu.edu CC: php-general@lists.php.net On Mon, Jan 11, 2010 at 6:21 PM, Alice Wei aj...@alumni.iu.edu wrote: Hi, This seems like a pretty simple problem, but I can't seem to be able to figure it out. I have a lot of elements in an array, and some of them are duplicates, but I don't want to delete them because I have other purposes for it. Is it possible for me to find out the number of certain elements in an array? For example, // Create a simple array. $array = array(1, 2, 3, 4, 5, 3,3,4,2); $total = count($array); echo $total; If I run the code, the value of $total would be 9. However, what I really want to do is to get the values of the different instances of each, like: 1 = 1 2 = 2 3 = 3 4= 2 5= 1 Is there a simple code that I use to find this out? Thanks for your help. Alice _ Hotmail: Trusted email with powerful SPAM protection. http://clk.atdmt.com/GBL/go/196390707/direct/01/ Hi, Try the function array_count_values. Thanks, this is cool. There is already a function for it! Regards, Jonathan _ Hotmail: Free, trusted and rich email service. http://clk.atdmt.com/GBL/go/196390708/direct/01/
Re: [PHP] count() total records for pagination with limit
PJ wrote: I seem to recall that it is possible to count all instances of a query that is limited by $RecordsPerPage without repeating the same query. I believe that COUNT() had to called immediately after the SELECT word but I neglected to bookmark the source. Dummy! You're probably thinking of SQL_CALC_FOUND_ROWS (http://dev.mysql.com/doc/refman/5.0/en/limit-optimization.html) It's not always faster though (http://www.mysqlperformanceblog.com/2007/08/28/to-sql_calc_found_rows-or-not-to-sql_calc_found_rows/). I don't like the idea of count(*) over count() or something like that as it seems rather slow fram what I read. right now I do this: $sql = SELECT * FROM book WHERE id IN (SELECT bookID FROM book_author WHERE authID IN (SELECT author.id FROM author WHERE LEFT(last_name, 1 ) = '$Auth')) ; $Count1 = mysql_num_rows(mysql_query($sql, $db)); The problem with this is if your '*' includes 50 fields (from all of the tables in the joins etc) then that is still processed in mysql taking up memory especially. Doing a count() just has 1 field - the count. $sql = select count(1) as count from book ; $result = mysql_query($sql, $db); $row = mysql_fetch_assoc($result); $count = $row['count']; $Count gives me the actual rows for display - $Count1 gives me the total rows available. Can this be streamlined any? Not really. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count() total records for pagination with limit
Chris wrote: PJ wrote: I seem to recall that it is possible to count all instances of a query that is limited by $RecordsPerPage without repeating the same query. I believe that COUNT() had to called immediately after the SELECT word but I neglected to bookmark the source. Dummy! You're probably thinking of SQL_CALC_FOUND_ROWS (http://dev.mysql.com/doc/refman/5.0/en/limit-optimization.html) It's not always faster though (http://www.mysqlperformanceblog.com/2007/08/28/to-sql_calc_found_rows-or-not-to-sql_calc_found_rows/). I don't like the idea of count(*) over count() or something like that as it seems rather slow fram what I read. right now I do this: $sql = SELECT * FROM book WHERE id IN (SELECT bookID FROM book_author WHERE authID IN (SELECT author.id FROM author WHERE LEFT(last_name, 1 ) = '$Auth')) ; $Count1 = mysql_num_rows(mysql_query($sql, $db)); The problem with this is if your '*' includes 50 fields (from all of the tables in the joins etc) then that is still processed in mysql taking up memory especially. Doing a count() just has 1 field - the count. $sql = select count(1) as count from book ; $result = mysql_query($sql, $db); $row = mysql_fetch_assoc($result); $count = $row['count']; $Count gives me the actual rows for display - $Count1 gives me the total rows available. Can this be streamlined any? Not really. OK. Your suggestion does help, though. :-) -- unheralded genius: A clean desk is the sign of a dull mind. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count the Number of Elements Using Explode
2008/10/31 Stut [EMAIL PROTECTED]: On 31 Oct 2008, at 17:32, Maciek Sokolewicz wrote: Kyle Terry wrote: -- Forwarded message -- From: Kyle Terry [EMAIL PROTECTED] Date: Fri, Oct 31, 2008 at 9:31 AM Subject: Re: [PHP] Count the Number of Elements Using Explode To: Alice Wei [EMAIL PROTECTED] I would use http://us2.php.net/manual/en/function.array-count-values.php On Fri, Oct 31, 2008 at 9:29 AM, Alice Wei [EMAIL PROTECTED] wrote: Hi, I have a code snippet here as follows: $message=1|2|3|4|5; $stringChunks = explode(|, $message); Is it possible to find out the number of elements in this string? It seems that I could do things like print_r and find out what is the last element of $stringChunks is, but is there a way where I can use code from the two lines and have it print out 5 as the number of elements that contains after the splitting? Or, am I on the wrong direction here? Thanks in advance. Alice First of all, don't top post, please. Secondly, that won't do what the OP asked for. array_count_values returns an array which tells you how often each VALUE was found in that array. so: array_count_values(array(1,2,3,4,5)) will return: array(1=1,2=1,3=1,4=1,5=1). While what the OP wanted was: some_function(array(1,2,3,4,5)) to return 5 (as in the amount of values, not how often each value was found in the array). count() would do it directly, and the other suggestions people gave do it indirectly, assuming that the values between '|' are never 1 char wide. I think you'll find Kyle was suggesting that the OP use that function to count the |'s in the string. Add 1 to that and you have the number of elements explode will produce. More efficient if you're simply exploding it to count the elements, but count would be better if you need to explode them too. -Stut For the case where you want to explode a string and afterwards count the number of elements you wind up with, Maciek is right: count() is the correct function to use. array_count_values() will not work on the original string and after exploding will have no useful effect on the resulting string as far as counting the number of separators goes. If you don't actually need to explode the string but just want to count the separators, you could use some weird logic to get array_count_values() to count the number of times '|' appeared in the original string--but it would be pointless. count_chars() would be a much better choice for what you are suggesting. Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count the Number of Elements Using Explode
On Fri, Oct 31, 2008 at 11:29 AM, Alice Wei [EMAIL PROTECTED] wrote: Hi, I have a code snippet here as follows: $message=1|2|3|4|5; $stringChunks = explode(|, $message); Is it possible to find out the number of elements in this string? It seems that I could do things like print_r and find out what is the last element of $stringChunks is, but is there a way where I can use code from the two lines and have it print out 5 as the number of elements that contains after the splitting? http://php.net/strlen http://php.net/count -- /Daniel P. Brown http://www.parasane.net/ [EMAIL PROTECTED] || [EMAIL PROTECTED] Ask me about our current hosting/dedicated server deals! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count the Number of Elements Using Explode
Hi Alice, U can simple do: $nr = ( strlen( $message ) / 2 ) + 1 ); $nr = count( explode( '|', $message ); On Fri, Oct 31, 2008 at 4:32 PM, Daniel Brown [EMAIL PROTECTED] wrote: On Fri, Oct 31, 2008 at 11:29 AM, Alice Wei [EMAIL PROTECTED] wrote: Hi, I have a code snippet here as follows: $message=1|2|3|4|5; $stringChunks = explode(|, $message); Is it possible to find out the number of elements in this string? It seems that I could do things like print_r and find out what is the last element of $stringChunks is, but is there a way where I can use code from the two lines and have it print out 5 as the number of elements that contains after the splitting? http://php.net/strlen http://php.net/count -- /Daniel P. Brown http://www.parasane.net/ [EMAIL PROTECTED] || [EMAIL PROTECTED] Ask me about our current hosting/dedicated server deals! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Thanks, Diogo Neves Web Developer @ SAPO.pt by PrimeIT.pt
RE: [PHP] Count the Number of Elements Using Explode
Hi, Thanks for all who responded, and the function is now working properly. It turned out that count function works for strings that contain the actual data inside, but when it is an empty string, a new if clause had to be set to create the count. Alice Alice Wei Indiana University, MIS 2008 Programmer/Computer Application Developer ProCure Treatment Centers, Inc. 420 N. Walnut St. Bloomington, IN 47404 812-330-6644 (office) 812-219-5708 (mobile) [EMAIL PROTECTED](email) http://www.procurecenters.com/index.php (web) Date: Fri, 31 Oct 2008 17:00:44 + From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] CC: [EMAIL PROTECTED]; php-general@lists.php.net Subject: Re: [PHP] Count the Number of Elements Using Explode Hi Alice, U can simple do: $nr = ( strlen( $message ) / 2 ) + 1 ); $nr = count( explode( '|', $message ); On Fri, Oct 31, 2008 at 4:32 PM, Daniel Brown wrote: On Fri, Oct 31, 2008 at 11:29 AM, Alice Wei wrote: Hi, I have a code snippet here as follows: $message=1|2|3|4|5; $stringChunks = explode(|, $message); Is it possible to find out the number of elements in this string? It seems that I could do things like print_r and find out what is the last element of $stringChunks is, but is there a way where I can use code from the two lines and have it print out 5 as the number of elements that contains after the splitting? http://php.net/strlen http://php.net/count -- http://www.parasane.net/ [EMAIL PROTECTED] || [EMAIL PROTECTED] Ask me about our current hosting/dedicated server deals! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Thanks, Diogo Neves Web Developer @ SAPO.pt by PrimeIT.pt _ Check the weather nationwide with MSN Search: Try it now! http://search.msn.com/results.aspx?q=weatherFORM=WLMTAG -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count the Number of Elements Using Explode
Diogo Neves wrote: Hi Alice, U can simple do: $nr = ( strlen( $message ) / 2 ) + 1 ); $nr = count( explode( '|', $message ); Or... $num = (substr_count($message, |) + 1); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count the Number of Elements Using Explode
On 31 Oct 2008, at 17:32, Maciek Sokolewicz wrote: Kyle Terry wrote: -- Forwarded message -- From: Kyle Terry [EMAIL PROTECTED] Date: Fri, Oct 31, 2008 at 9:31 AM Subject: Re: [PHP] Count the Number of Elements Using Explode To: Alice Wei [EMAIL PROTECTED] I would use http://us2.php.net/manual/en/function.array-count-values.php On Fri, Oct 31, 2008 at 9:29 AM, Alice Wei [EMAIL PROTECTED] wrote: Hi, I have a code snippet here as follows: $message=1|2|3|4|5; $stringChunks = explode(|, $message); Is it possible to find out the number of elements in this string? It seems that I could do things like print_r and find out what is the last element of $stringChunks is, but is there a way where I can use code from the two lines and have it print out 5 as the number of elements that contains after the splitting? Or, am I on the wrong direction here? Thanks in advance. Alice _ Check the weather nationwide with MSN Search: Try it now! http://search.msn.com/results.aspx?q=weatherFORM=WLMTAG -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php First of all, don't top post, please. Secondly, that won't do what the OP asked for. array_count_values returns an array which tells you how often each VALUE was found in that array. so: array_count_values(array(1,2,3,4,5)) will return: array(1=1,2=1,3=1,4=1,5=1). While what the OP wanted was: some_function(array(1,2,3,4,5)) to return 5 (as in the amount of values, not how often each value was found in the array). count() would do it directly, and the other suggestions people gave do it indirectly, assuming that the values between '|' are never 1 char wide. I think you'll find Kyle was suggesting that the OP use that function to count the |'s in the string. Add 1 to that and you have the number of elements explode will produce. More efficient if you're simply exploding it to count the elements, but count would be better if you need to explode them too. -Stut -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count
I am wanting to create an select menu for displaying the order of the item on a page. I am guessing that I need to get the count of how many items are in the db and them put them into a select menu. Your question doesn't really make a great deal of sense. Your SQL could be: SELECT COUNT(*) FROM your_table WHERE 1 Which will give you a single numeric value back (the number of rows). To put them into an HTML page: select name=mySelect optionChoose.../option option value=1Foo/option /select This is a very basic select. You can simply loop through your query results adding more option tags to add more items to the select. -- Richard Heyes http://www.websupportsolutions.co.uk Mailing list management service allowing you to reach your Customers and increase your sales. ** NOW OFFERING FREE ACCOUNTS TO CHARITIES AND NON-PROFITS ** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count
Steve, Check out the while loop (http://us.php.net/manual/en/control-structures.while.php). It'll do what you need. -- Mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count
Richard, Thank you so much for your response. The select would be created from the number of records in the db. option value=²$variable²$variable2/option The problem that I am having is rather than getting just the number of records, which is 3 currently, I would like it to be 1 for the first option, 2 for the second..., so that the user has the choice of any record. The idea would be to order the content by the highest number. I hope this makes more sense. -- Steve M. on 1/17/08 1:54 PM Richard Heyes ([EMAIL PROTECTED]) wrote: I am wanting to create an select menu for displaying the order of the item on a page. I am guessing that I need to get the count of how many items are in the db and them put them into a select menu. Your question doesn't really make a great deal of sense. Your SQL could be: SELECT COUNT(*) FROM your_table WHERE 1 Which will give you a single numeric value back (the number of rows). To put them into an HTML page: select name=mySelect optionChoose.../option option value=1Foo/option /select This is a very basic select. You can simply loop through your query results adding more option tags to add more items to the select.
Re: [PHP] count vs mysql_num_rows
On 10/8/07, Kevin Murphy [EMAIL PROTECTED] wrote: I've got a little function that just checks to see if something is in a mysql db. There are several ways to do this and was curious as to the best way. The following are 2 (simplified) versions that work just fine. If these are the best ways, which of the following is better from a performance standpoint. And if there is a way that is better than one of these, I'd love to know what that is. $query = SELECT count(id) as count FROM wncci_intranet.iAdmin_users WHERE name = '$name' LIMIT 1; $results = mysql_query($query); $row = mysql_fetch_array($results); $count = $row[count]; return $count; OR $query = SELECT id FROM wncci_intranet.iAdmin_users WHERE name = '$name' LIMIT 1; $results = mysql_query($query); $count = mysql_num_rows($results); return $count; i would do a select count() from the database. no sense in returning all the row data back to the script just to do a count on it there. that's additional network/socket transfer between the app and the database, then processing on the app side to collect all the rows into memory, etc. you also don't need to do select count(id) as count, just do a select count(id) and do a mysql_fetch_array($results, MYSQL_NUM) or mysql_fetch_row($results) - you don't need to make it an associative array, since it's only one column and the name is irrelevant. mysql_fetch_row() is the best function for what you want. you'll save any additional PHP overhead with different types of arrays being setup. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count vs mysql_num_rows
Kevin Murphy wrote: I've got a little function that just checks to see if something is in a mysql db. There are several ways to do this and was curious as to the best way. The following are 2 (simplified) versions that work just fine. If these are the best ways, which of the following is better from a performance standpoint. And if there is a way that is better than one of these, I'd love to know what that is. $query = SELECT count(id) as count FROM wncci_intranet.iAdmin_users WHERE name = '$name' LIMIT 1; $results = mysql_query($query); $row = mysql_fetch_array($results); $count = $row[count]; return $count; OR $query = SELECT id FROM wncci_intranet.iAdmin_users WHERE name = '$name' LIMIT 1; $results = mysql_query($query); $count = mysql_num_rows($results); return $count; Thanks. Is this a joke? You are using a LIMIT 1, so your count is always going to be 1. But, if you didn't use the LIMIT 1 and really wanted to see how many the results would be found, then I would do it like this. $SQL = SELECT count(id) FROMiAdmin_users WHERE name = '{$name}'; $results = mysql_query($SQL) OR die('Mysql Error: '.mysql_error()); $count = 0; if ( $results ) { list($count) = mysql_fetch_row($results); } return $count; -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count vs mysql_num_rows
Is this a joke? You are using a LIMIT 1, so your count is always going to be 1. No, its not a joke. The answer is not going to always 1, its going to be 1 (the value exists in the DB at least once) or 0 (the value doesn't exist in the DB), that's what I am trying to test for. I don't need to know how many times something exists, just if it does. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada College www.wnc.edu 775-445-3326
RE: [PHP] count vs mysql_num_rows
[snip] Is this a joke? You are using a LIMIT 1, so your count is always going to be 1. No, its not a joke. The answer is not going to always 1, its going to be 1 (the value exists in the DB at least once) or 0 (the value doesn't exist in the DB), that's what I am trying to test for. I don't need to know how many times something exists, just if it does. [/snip] If you just need to know if data exists use the query with limit 1 and test to see if 1 === $result['count']. I agree with the poster about not returning all of the rows, it is more efficient to do it this way. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count vs mysql_num_rows
At 12:47 PM -0700 10/8/07, Kevin Murphy wrote: Is this a joke? You are using a LIMIT 1, so your count is always going to be 1. No, its not a joke. The answer is not going to always 1, its going to be 1 (the value exists in the DB at least once) or 0 (the value doesn't exist in the DB), that's what I am trying to test for. I don't need to know how many times something exists, just if it does. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada College www.wnc.edu 775-445-3326 Kevin: Considering what you want to do, you might want to investigate having mysql do it for you, see here: http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count empty array
On Thu, 2006-12-21 at 13:31 -0800, Kevin Murphy wrote: I'm wondering why this is. $data = ; $array = explode(,,$data); $count = count($array); $count will = 1 $data = Test; $array = explode(,,$data); $count = count($array); $count will = 1 $data = Test,Test; $array = explode(,,$data); $count = count($array); $count will = 2 Why doesn't the first one give me an answer of 0 instead of 1. For the same reason the second one gives you a count of one. There are no commas and so only one item exists. Whether that be an string with content or the empty string itself is irrelevant. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count empty array
Kevin Murphy wrote: I'm wondering why this is. $data = ; $array = explode(,,$data); $count = count($array); $count will = 1 $data = Test; $array = explode(,,$data); $count = count($array); $count will = 1 $data = Test,Test; $array = explode(,,$data); $count = count($array); $count will = 2 Why doesn't the first one give me an answer of 0 instead of 1. This: var_dump(explode(',','')); Returns this: array(1) { [0]= string(0) } And oddly, This: var_dump(explode(',',NULL)); Returns this: array(1) { [0]= string(0) } That explains the count() result. It seems to me that the first case could go either way (The part of before the ',' is still ), but I'm unable to think of a logical reason why the second doesn't return an empty array. I know I could do a IF $data == [empty] and then not count if its empty and just set it to 0, but am wondering if there was a better way. $array = empty($data) ? array() : explode(',',$data); /* That what you're looking for? */ jon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count empty array
On Thu, 21 Dec 2006, Kevin Murphy wrote: I'm wondering why this is. $data = ; $array = explode(,,$data); $count = count($array); $count will = 1 $array has 1 element: An empty string. $data = Test; $array = explode(,,$data); $count = count($array); $count will = 1 $array has 1 element: The string Test $data = Test,Test; $array = explode(,,$data); $count = count($array); $count will = 2 $array has 2 elements:. Why doesn't the first one give me an answer of 0 instead of 1. I know I could do a IF $data == [empty] and then not count if its empty and just set it to 0, but am wondering if there was a better way. Because explode divides the string in n+1 elements, where n is the amount of , (or your favorite delimiter) found in the string. So if no , is found, explode will return 1 element: the whole string (even if it's empty). -- 21:50:04 up 2 days, 9:07, 0 users, load average: 0.92, 0.37, 0.18 - Lic. Martín Marqués | SELECT 'mmarques' || Centro de Telemática| '@' || 'unl.edu.ar'; Universidad Nacional| DBA, Programador, del Litoral | Administrador - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count empty array
Not sure why it does it, but doesn't seem to be a huge deal. I'm guessing it's because an empty string is still a string. It's not null. Anyway, it's documented at: http://us3.php.net/manual/en/function.explode.php A user writes: If you split an empty string, you get back a one-element array with 0 as the key and an empty string for the value. -TG = = = Original message = = = I'm wondering why this is. $data = ; $array = explode(,,$data); $count = count($array); $count will = 1 $data = Test; $array = explode(,,$data); $count = count($array); $count will = 1 $data = Test,Test; $array = explode(,,$data); $count = count($array); $count will = 2 Why doesn't the first one give me an answer of 0 instead of 1. I know I could do a IF $data == [empty] and then not count if its empty and just set it to 0, but am wondering if there was a better way. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 ___ Sent by ePrompter, the premier email notification software. Free download at http://www.ePrompter.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count string within a string
On 11/17/06, Børge Holen [EMAIL PROTECTED] wrote: I've figured out I need the substr_count function. However, counting strings like this: [1] [2] [3] ... [215] ... inside a large string element. damn. The string got quite a few different numbers and keys but the main key is alway within [] and is numeric. I imagine I could use a $counter++. I just dont see how I should aproach this. Anyone got an Idea? -- --- Børge Kennel Arivene http://www.arivene.net --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Apologies if I missed what you were after.. but maybe you might try this: ?php $string = 'However, counting strings like this: [1] [2] [3] ... [215] ...'; $result = preg_match_all('/\[([0-9]+)\]/U', $string, $matches); if (! $result ) echo No matches\n; echo Count: . count($matches[1]); -- Results in: Count: 4 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Count of elements in XML
Hi Jay, Check the example at http://www.weberdev.com/Manuals/PHP/function.simplexml-element-children.html Thanks, Richard -Original Message- From: Jay Paulson [mailto:[EMAIL PROTECTED] Sent: Friday, January 20, 2006 11:06 PM To: PHP LIST Subject: [PHP] Count of elements in XML I was wondering if there is a way to get the number of foo elements in my XML below? This way I could loop through each element and print out the attributes. $string = a foo name=\one\ game=\lonely\1/foo foo name=\two\ game=\again\2/foo foo name=\three\ game=\blah\3/foo foo name=\four\ game=\goodness\4/foo /a; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count and Preg_Replace Using Version 4.4.1
form'.$count.'... You can use preg_replace_callback or the e pattern modifier to let you run php code for the replacement: http://us3.php.net/manual/en/function.preg-replace-callback.php http://us3.php.net/manual/en/reference.pcre.pattern.modifiers.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count and Preg_Replace Using Version 4.4.1
On Sun, Dec 04, 2005 at 07:00:00PM -, Shaun wrote: comex [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] form'.$count.'... You can use preg_replace_callback or the e pattern modifier to let you run php code for the replacement: http://us3.php.net/manual/en/function.preg-replace-callback.php http://us3.php.net/manual/en/reference.pcre.pattern.modifiers.php Hi Comex, Thanks for your reply, I have modified the code so I have a call back function: echo = preg_replace_callback( '/p[^]*(.*?)\/p/ms', callback, file_get_contents($_GET['file']) ); function callback($matches){ return 'form name=form target=_parent ... But I still can't see how I can increment a value in each return string? function callback($matches) { static $i = 0; // -- maintains counter within function scope $i++; return form name=form$i/form; } btw, i've been meaning to mention this in the last few posts of yours, but have you considered using DOM to make this happen. When ever I see a regex solution for parsing an html document, it makes me cringe. Curt. -- cat .signature: No such file or directory -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count and Preg_Replace Using Version 4.4.1
Curt Zirzow [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Sun, Dec 04, 2005 at 07:00:00PM -, Shaun wrote: comex [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] form'.$count.'... You can use preg_replace_callback or the e pattern modifier to let you run php code for the replacement: http://us3.php.net/manual/en/function.preg-replace-callback.php http://us3.php.net/manual/en/reference.pcre.pattern.modifiers.php Hi Comex, Thanks for your reply, I have modified the code so I have a call back function: echo = preg_replace_callback( '/p[^]*(.*?)\/p/ms', callback, file_get_contents($_GET['file']) ); function callback($matches){ return 'form name=form target=_parent ... But I still can't see how I can increment a value in each return string? function callback($matches) { static $i = 0; // -- maintains counter within function scope $i++; return form name=form$i/form; } btw, i've been meaning to mention this in the last few posts of yours, but have you considered using DOM to make this happen. When ever I see a regex solution for parsing an html document, it makes me cringe. Curt. -- cat .signature: No such file or directory Hi Curt, Thanks for your reply. So basically I do something like: $doc = new DOMDocument(); $doc-loadHTML($file); $p = $doc-getElementsByTagName('p'); How would then wrap the following around each p tag: form name=form target=_parent action=/index.php?action=edit_paragraphfile='.$_GET['file'].' method=post input type=hidden name=old_html value='.htmlentities($matches[0]).' pa href=javascript:; onclick=document.form.submit();'.$matches[1].'/a/p /form BTW if its not obvious I am trying to create a CMS that lets users edit anything within a p tag! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count totals (might be 0T)
On Thu, April 21, 2005 3:36 pm, Ryan A said: Hey, Thanks for replying. That means I will have to run a query per categorywhich I would like to avoid if possible as they could be a high amount of categories as they are user created and not defined by us. ?php /* category_count.inc Provides $CATEGORY_COUNT and $CATEGORY_SIZE variables for the application. */ $query = select cno, count(*), sum(pic_size_kb) from TABLE group by cno; $cat_info = mysql_query($query) or die(mysql_error()); $CATEGORY_COUNT = array(); $CATEGORY_SIZE = array(); while (list($cno, $count, $size) = mysql_fetch_row($cat_info)){ $CATEGORY_COUNT[$cno] = $count; $CATEGORY_SIZE[$cno] = $size; } ? Only problem is that you could have a slight timing issue where the select above gets done, then somebody adds a new image, and then you display your counts, and then you display the list, and that extra image is in the list, but not counted. You *COULD* solve this by wrapping a transaction around the whole mess if it's really critical, but you probably don't need it. Thanks, Ryan On 4/22/2005 12:08:31 AM, Drewcore ([EMAIL PROTECTED]) wrote: run another sql query: select pic_size_kb from table where pic_category='$current_category, then make a loop that increments a) the total number of records (ie total number of pics in category), and then adds the pic size from each record to some variable (eg $total_kb) and then you have your total. hope that helps. drew On 4/21/05, Ryan A [EMAIL PROTECTED] wrote: Hi again, Am faced with a new problem (either that or working straight 10 hours is catching up!) Heres my table (easy to figure out so i wont waste your time explaining the fields): cno, date_added, pic_name, pic_size_kb, pic_desc_text, pic_category the way i am displaying the data is like this (thanks to Phillip and Andy from this list) __ category here -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.308 / Virus Database: 266.10.1 - Release Date: 4/20/2005 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count totals (might be 0T)
Hey, Thanks for replying. That means I will have to run a query per categorywhich I would like to avoid if possible as they could be a high amount of categories as they are user created and not defined by us. Thanks, Ryan On 4/22/2005 12:08:31 AM, Drewcore ([EMAIL PROTECTED]) wrote: run another sql query: select pic_size_kb from table where pic_category='$current_category, then make a loop that increments a) the total number of records (ie total number of pics in category), and then adds the pic size from each record to some variable (eg $total_kb) and then you have your total. hope that helps. drew On 4/21/05, Ryan A [EMAIL PROTECTED] wrote: Hi again, Am faced with a new problem (either that or working straight 10 hours is catching up!) Heres my table (easy to figure out so i wont waste your time explaining the fields): cno, date_added, pic_name, pic_size_kb, pic_desc_text, pic_category the way i am displaying the data is like this (thanks to Phillip and Andy from this list) __ category here -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.308 / Virus Database: 266.10.1 - Release Date: 4/20/2005 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count totals (might be 0T)
Hi, Friday, April 22, 2005, 8:03:06 AM, you wrote: RA Hi again, RA Am faced with a new problem (either that or working straight 10 hours is RA catching up!) RA Heres my table (easy to figure out so i wont waste your time explaining the RA fields): RA cno, RA date_added, RA pic_name, RA pic_size_kb, RA pic_desc_text, RA pic_category RA the way i am displaying the data is like this (thanks to Phillip and Andy RA from this list) RA __ RA category here 2pics, 90kb | RA - RA | pic-here | pic_desc_text | RA | pic-here | pic_desc_text | RA __ RA category here 2pics, 160kb | RA - RA | pic-here | pic_desc_text | RA | pic-here | pic_desc_text | RA - RA When I sql the DB I call it like this: select picture_name,more fields from table where cno=x order by category. RA Any ideas as to how i get how many pics per category and size per category? RA I'm not sure if its a PHP thing or a MySql thing... RA Last problem for the day...then i hit the sack! RA Thanks in advance, RA Ryan Something like SELECT COUNT(pic_name) as pic_count, SUM(pic_size_kb) as pic_total FROM pic_table GROUP BY pic_category -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Count totals(might be 0T)
Ryan A mailto:[EMAIL PROTECTED] on Thursday, April 21, 2005 3:03 PM said: When I sql the DB I call it like this: select picture_name,more fields from table where cno=x order by category. Any ideas as to how i get how many pics per category and size per category? I'm not sure if its a PHP thing or a MySql thing... By either running a query for each category grabbing the data you want. Or by grabbing the data you want in the initial query and adding it all up BEFORE you start to do you display logic. So the second option would be: 1. Get all the data. 2. Loop through all the data creating the tally(s) you want. 3. Loop through the data again creating your visual gropings and throwing in the tally(s) you created earlier. Try both options and time them. Chris. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count with match probelm
Richard Lynch wrote: ... $how_many = mysql_result(mysql_query(SELECT COUNT(*), MATCH(ad_sub, ad_text) AGAINST('$words') AS score from .$tcname.ads WHERE MATCH(ad_sub, ad_text) AGAINST('$words') FROM .$tcname.ads where is_confirmed=1),0); H. Actually, I *can* tell you that you shouldn't have FROM in there twice. You've messed up your query something awful with that. also he just wants the count with this statement so: 'MATCH(ad_sub,ad_text) AGAINST('$words') AS score' shouldn't be part of this query, instead: SELECT COUNT(*) FROM .$tcname.ads where is_confirmed=1 WHERE MATCH(ad_sub,ad_text) AGAINST('$words') -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count with match probelm
On Tue, March 22, 2005 11:30 pm, Ryan A said: $q=mysql_query(select cno,date_and_time,MATCH(ad_sub, ad_text) AGAINST('$words') AS score from .$tcname.ads WHERE MATCH(ad_sub, ad_text) AGAINST('$words') AND is_confirmed=1 LIMIT $limit1, $limit2); This is pretty much a MySQL question, really... But: There is a new-ish SQL_CALC_FOUND_ROWS constant you can use in your query to get MySQL to tell you how many rows you would have gotten without the LIMIT clause. You may be able to use that. which is running fine...my problem is I am using a class for pagination which requires the total number of records that will be returned to break the query into pagesand which will give me the values of $limit1 and , $limit2 which i will use in the above statement...but running a count() is not working, it gives me an error, what other options do i have other than running the same query twice and using mysql_num_rows? (which i think would be quite intensive/wasteful as i am querying @ 100 rows each time) This is my count() query, maybe theres a problem here? Probably. But since you only told us it gives me an error and don't tell use *WHAT* the error is, we really can't help you, can we? $how_many = mysql_result(mysql_query(SELECT COUNT(*), MATCH(ad_sub, ad_text) AGAINST('$words') AS score from .$tcname.ads WHERE MATCH(ad_sub, ad_text) AGAINST('$words') FROM .$tcname.ads where is_confirmed=1),0); H. Actually, I *can* tell you that you shouldn't have FROM in there twice. You've messed up your query something awful with that. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] COUNT(*) Output Question
Wouldn't count(sku) work? -Original Message- From: Tom Ray [Lists] [mailto:[EMAIL PROTECTED] Sent: Monday, August 02, 2004 3:20 PM To: [EMAIL PROTECTED] Subject: [PHP] COUNT(*) Output Question Hey- I'm query my mySQL database to see how many of each Sku has been ordered. I am doing my query as: $count=mysql_query(SELECT sku, COUNT(*) FROM orders GROUP BY sku); But my question is how do I use PHP to output the COUNT(*) results? When I run the command when I'm logged into mySQL I get the following: mysql select sku, count(*) from orders group by sku\g +--+--+ | sku | count(*) | +--+--+ | 10001|1 | | 10001a |1 | | 10003|2 | | 10005|1 | | 10011|1 | +--+--+ I just can't figure out a way to output that Count(*) column into something HTML friendly...any help or thoughts on this would be appreciated! TIA -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] COUNT(*) Output Question
* Thus wrote Tom Ray [Lists]: Hey- I'm query my mySQL database to see how many of each Sku has been ordered. I am doing my query as: $count=mysql_query(SELECT sku, COUNT(*) FROM orders GROUP BY sku); alias the count(*) column: SELECT sku, COUNT(*) as qty FROM orders GROUP BY sku Curt -- First, let me assure you that this is not one of those shady pyramid schemes you've been hearing about. No, sir. Our model is the trapezoid! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] COUNT(*) Output Question
From: Tom Ray [Lists] [EMAIL PROTECTED] $count=mysql_query(SELECT sku, COUNT(*) FROM orders GROUP BY sku); But my question is how do I use PHP to output the COUNT(*) results? When I run the command when I'm logged into mySQL I get the following: I assume you're fetching associative arrays from the result and $r['sku'] works, but you're not sure how to get the COUNT(*) value? Well, $r['COUNT(*)'] would work, but you could also use an alias: SELECT sku, COUNT(*) AS mycount FROM orders GROUP BY sku and then use $r['mycount'] to retrieve the value (after using mysql_fetch_assoc/array, of course). ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] COUNT(*) Output Question
Thanks JohnI didn't think of thatI've been working on this catalog admin interface for to long..my brain is mush. John W. Holmes wrote: From: Tom Ray [Lists] [EMAIL PROTECTED] $count=mysql_query(SELECT sku, COUNT(*) FROM orders GROUP BY sku); But my question is how do I use PHP to output the COUNT(*) results? When I run the command when I'm logged into mySQL I get the following: I assume you're fetching associative arrays from the result and $r['sku'] works, but you're not sure how to get the COUNT(*) value? Well, $r['COUNT(*)'] would work, but you could also use an alias: SELECT sku, COUNT(*) AS mycount FROM orders GROUP BY sku and then use $r['mycount'] to retrieve the value (after using mysql_fetch_assoc/array, of course). ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count number of occurences of character in a string
Hello Diana, Tuesday, June 8, 2004, 11:11:27 AM, you wrote: DC what function can I use to count the number of occurences of a certain DC character in a string? substr_count or count_chars would work. Best regards, Richard Davey -- http://www.launchcode.co.uk - PHP Development Services I am not young enough to know everything. - Oscar Wilde -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] count number of occurences of character in a string
what function can I use to count the number of occurences of a certain character in a string? substr_count() ...? rich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count number of occurences of character in a string
substr_count() http://www.php.net/manual/en/function.substr-count.php what function can I use to count the number of occurences of a certain character in a string? -- Diana Castillo Global Reservas, S.L. C/Granvia 22 dcdo 4-dcha 28013 Madrid-Spain Tel : 00-34-913604039 Fax : 00-34-915228673 email: [EMAIL PROTECTED] Web : http://www.hotelkey.com http://www.destinia.com
Re: [PHP] count the elements of each dimension of the array
[EMAIL PROTECTED] wrote: I have this script: ? $ojpp[] = 1; $ojpp[] = 2; $ojpp[] = 3; $ojpp[] = 4; This is illegal. Only one pair of empty square brackets is allowed. How whould php know where to add the new key? $ojpp[][] = 1; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count()
Anthony Ritter wrote: Greetings- I'm have the follwing string called $text and throughout this string I'd like to split this into an array by calling spliti() at the tag called PAGEBREAK. So, I count the array elements starting at 0 and get to 9. When I call count(), I get 11. Could somebody please explain why this is? Thank you. TR . ? $text= aaa[PAGEBREAK] //this is the 0 element bbb[PAGEBREAK] //[1] ccc[PAGEBREAK] //[2] ddd[PAGEBREAK] //[3] eee[PAGEBREAK] //[4] fff[PAGEBREAK] //[5] ggg[PAGEBREAK] //[6] hhh[PAGEBREAK] //[7] iii[PAGEBREAK] //[8] jjj[PAGEBREAK] //...and this is the 9th element ; There are 10 '[PAGEBREAK]' substrings in the string. If the string is split apart at these substrings, it will give you total 11 parts. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count()
Marek Kilimajer [EMAIL PROTECTED] wrote in message: There are 10 '[PAGEBREAK]' substrings in the string. If the string is split apart at these substrings, it will give you total 11 parts. Thank you. TR -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Count online users question
If your website uses PHP sessions, and you store those sessions in a database table you could; $query = select count(*) from session_table where .session_datetime \ .date(Y-m-d H:i:s, strtotime(date(Y-m-d H:i:s). -1 hour)) .\ ; ...the reset of a mysql query to get result. Note that the 1 hour is an arbitrary amount of time and people do come back after 1 hour, but if your session lifetime is set to be less than an hour, you may want to use that same time limit. You were correct in your original assumption that the count will almost never be very precise. Warren -Original Message- From: Mike D [mailto:[EMAIL PROTECTED] Sent: Wednesday, November 26, 2003 2:57 PM To: [EMAIL PROTECTED] Subject: [PHP] Count online users question Hi all, I am trying to figure an accurate way to calculate how many users are viewing a site, at any particular time. This task is very simple except for one part - How do you determine when a person has left the site...apache hasn't served anymore requests from a particular ip for xx minutes ?? - MD .. Mike Dunlop AWN, Inc. // www.awn.com [ e ] [EMAIL PROTECTED] [ p ] 323.606.4237 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Count lines or chars
I guess you could do something like : ?php function countLines($filename) { if(file_exists($filename)) { $linecount=0; $fs = file($filename); while (list ($linenum, $linec) = each($fs)) { $linecount++; } return $linecount; } } $local_file = /path/to/testfile.txt; $lines = countLines($local_file); ? That would count all the lines in the file. /Morten -Original Message- From: Markus [mailto:[EMAIL PROTECTED] Sent: 17. oktober 2003 11:25 To: [EMAIL PROTECTED] Subject: [PHP] Count lines or chars Hi PHP-gurus :-) I'd like to count the lines within a file and store the result within a variable. Every line begins with the char %. Would it be easier to count these chars and how could I do that? Thanks for your help. markus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count lines or chars
Markus wrote: Hi PHP-gurus :-) I'd like to count the lines within a file and store the result within a variable. Every line begins with the char %. Would it be easier to count these chars and how could I do that? Thanks for your help. markus Maybe this way: $file = file( '/some/file.ext' ); $lines_count = count( $file ); -- Pavel a.k.a. Papi -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count() numerical arrays....
Use explode instead... $num_list_array = explode(, $num_list) more information at php.net/explode Cesar CF High wrote: Hey all. Another simple, yet baffling for me, question: I have a comma delimited list of numbers; e.g. $num_list = 1,2,3,4 I split the number list to array -- $num_list_array = split(, $num_list) I then count the number of elements -- $count = count($num_list_array); I do not get 4 for $count, rather 1! I can't stand coming up with cludgy workarounds just to count the number of elements in a numerical list. Any ideas? --Noah -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count() numerical arrays....
CF High wrote: I split the number list to array -- $num_list_array = split(, $num_list) Any ideas? split uses a regular expression. I think you want to use explode here. $num_list_array = explode(',', $num_list) - Brad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count() numerical arrays....
* Thus wrote CF High ([EMAIL PROTECTED]): Hey all. Another simple, yet baffling for me, question: I have a comma delimited list of numbers; e.g. $num_list = 1,2,3,4 I split the number list to array -- $num_list_array = split(, $num_list) I then count the number of elements -- $count = count($num_list_array); I do not get 4 for $count, rather 1! I can't stand coming up with cludgy workarounds just to count the number of elements in a numerical list. So you just want to count how many digits their are? $num_list = 1,2,3,4; $count = substr_count($num_list, ,) + 1; http://php.net/substr_count No sense of all the extra work in putting it into an array. HTH, Curt -- I used to think I was indecisive, but now I'm not so sure. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count rows
mysql_num_rows gives the number of rows. But don't even think of doing it this way if you just want the number of rows and don't want the data. The correct way is to use a query such as [sql] select count(*) from table [/sql] this will return just one row and it wil tell you how many rows are in your table and your database will be a lot happier :-) John Taylor-Johnston wrote: Help me out here. I want to get a numeral on the number of records in a table. What is the function? http://www.php.net/manual-lookup.php?pattern=fetch%2Browslang=en http://www.php.net/manual-lookup.php?pattern=fetch%2Brecordslang=en ? :) John -- http://www.raditha.com/php/progress.php A progress bar for PHP file uploads. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] COUNT(*)
Actually that does retrieve the number of rows.. // Query $query = SELECT COUNT(*) AS count FROM pet; // Execute Query $result = mysql_query($query); // Get the result of query named count $count = mysql_result($result,0); echo $count. is the number of rows; Cheers! Rick In order to seek truth it is necessary once in the course of our life to doubt as far as possible all things. - Rene Descartes From: Yury B. [EMAIL PROTECTED] Reply-To: [EMAIL PROTECTED] Date: Thu, 31 Jul 2003 19:46:40 +0200 To: [EMAIL PROTECTED] Subject: [PHP] COUNT(*) Hi I used to use old fashioned mysql quieries but moderm mysql apparently became more flexible so. I want to understand how to use some of the new features like COUNT(*) Let's say I have $result=SELECT COUNT(*) FROM pet; $sql=mysql_query($result); while ($row=mysql_fetch_array($sql)){ $pet_name=$row['pet_name']; echo ..; } the question is how do I actually retrieve the number of rows of sql query result? Yury -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count up from 7
Richard -- ...and then Richard Whitney said... % % Braindead! Hey, who are you callin' names?!? % % I need to evaluate a number if greater than 7 and add a value per increment. Greater than seven is easy. Adding a value is easy. Per increment can be a little tricky but we'll assume for the moment that the window is 1. The code $sum = 67 ; # starting value $trg = 7 ;# trigger value $add = 6 ;# what we add each time $num = 10 ; # what we're evaluating (hardcoded here!) for ( $num ; $trg $num ; $trg++ ) { $sum += $add ; } print when num = $num, sum = $sum\n ; should do for a starting point, though, and produces bash-2.05a$ php -q /tmp/inc.php when num = 10, sum = 85 bash-2.05a$ php -q /tmp/inc.php when num = 20, sum = 145 bash-2.05a$ php -q /tmp/inc.php when num = 7, sum = 67 bash-2.05a$ php -q /tmp/inc.php when num = 1, sum = 67 when run. Extra credit if you write it as a recursive function :-) % I'm frazzled and can't think straight. You can't ask straight, either :-) Give us more details! % % Thanks Guys! HTH HAND :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, Science and Health http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! pgp0.pgp Description: PGP signature
Re: [PHP] count up from 7
Huh? Not really following what you want to achieve, but: ? $n = 9; $floor = 7; if($n $floor) { $diff = $n - $floor; //eg 2 // no idea what you want to do from here } ? on 25/03/03 10:58 AM, Richard Whitney ([EMAIL PROTECTED]) wrote: Braindead! I need to evaluate a number if greater than 7 and add a value per increment. I'm frazzled and can't think straight. Thanks Guys! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count up from 7
not sure if this is what you're looking for: if ( $var 7 ) { // do stuff } - cheers, Sebastian - Original Message - From: Richard Whitney [EMAIL PROTECTED] | Braindead! | | I need to evaluate a number if greater than 7 and add a value per increment. | I'm frazzled and can't think straight. | | Thanks Guys! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count characters
On Sun, 12 Jan 2003 [EMAIL PROTECTED] wrote: I want to count characters without space character. $char=hello world so the result should be 10. Can anybody help me? $char=hello world; $temp=str_replace( , , $char); echo strlen($temp); should give you 10. RDB -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count characters
Try the following code, please note you may want to trim() the string as well if it is coming from a user. ?php $char = 'hello world'; $number_characters = strlen(str_replace(' ', '', $char')); ? Jason On Sun, 2003-01-12 at 10:32, [EMAIL PROTECTED] wrote: I want to count characters without space character. $char=hello world so the result should be 10. Can anybody help me? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count characters without space
On Saturday 11 January 2003 08:51 pm, [EMAIL PROTECTED] wrote: who knowes how to count the charcaters in a string without the space character? you need to be more clear. number of characters in the string except space? number of distinct characters in the string except space? include other non-space whitespace (\t \n \r etc)? case sensitive? this is really not hard at all and would be educational for you to write yourself, as an exercise in learning php. one approach: 1. create an empty string, charsfound. for each character in your input string, see if the character already exists in charsfound (use strchr or strpos). if it's a space, continue the loop (don't exec the code below). if it's already there, skip to the next character. if it's not yet there, increment a counter, add the character to charsfound and continue the loop. at the end of the input string exit the loop. the counter is the number of distinct non-space characters in the input string. putting the increment a counter elsewhere (but in the appropriate places) in the loop will give you the number of non-space (not distinct) characters in the input string. tiger -- Gerald Timothy Quimpo tiger*quimpo*org gquimpo*sni-inc.com tiger*sni*ph Public Key: gpg --keyserver pgp.mit.edu --recv-keys 672F4C78 Veritas liberabit vos. Doveryai no proveryai. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count characters without space
who knowes how to count the charcaters in a string without the space character? Using a regular expression to strip out all the spaces before passing to the word counting function seems easiest. You'll be left to adapt it to PHP, but the regexp is: 's/ //g' That removes all spaces. If it gives an error, try s/\ //g to escape the space. Pass the result to whatever you use to count the number of characters. -Jeff SIG: HUP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count in PHP
why not: select count(*) as counter from table - Original Message - From: Tyler Longren [EMAIL PROTECTED] To: Chuck PUP Payne [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, September 10, 2002 1:02 PM Subject: Re: [PHP] Count in PHP $sql = mysql_query(SELECT * FROM table ORDER BY whatever); echo(mysql_num_rows($sql)); that should do it. tyler On Tue, 10 Sep 2002 00:58:26 -0400 Chuck \PUP\ Payne [EMAIL PROTECTED] wrote: I am wanting to do a count in PHP. I want to be able to count the number of records from a given database and display this count on the page. Can this be done using PHP or is the sql thing? Chuck Payne -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Count in PHP
it's best done in sql using select count(*) but can be done in php by looping through the result set -Original Message- From: Chuck PUP Payne [mailto:[EMAIL PROTECTED]] Sent: Tuesday, September 10, 2002 2:58 PM To: PHP General Subject: [PHP] Count in PHP I am wanting to do a count in PHP. I want to be able to count the number of records from a given database and display this count on the page. Can this be done using PHP or is the sql thing? Chuck Payne -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count in PHP
$sql = mysql_query(SELECT * FROM table ORDER BY whatever); echo(mysql_num_rows($sql)); that should do it. tyler On Tue, 10 Sep 2002 00:58:26 -0400 Chuck \PUP\ Payne [EMAIL PROTECTED] wrote: I am wanting to do a count in PHP. I want to be able to count the number of records from a given database and display this count on the page. Can this be done using PHP or is the sql thing? Chuck Payne -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count number of rows in table.
And do I need to use any other functions like mysql_fetch_row() ? Martín marqués [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]... On Sáb 24 Ago 2002 11:19, Tony Harrison wrote: How would I count the number of rows in a mysql table with a WHERE clause? select count(*) from table_name WHERE . Saludos... :-) -- Porqué usar una base de datos relacional cualquiera, si podés usar PostgreSQL? - Martín Marqués |[EMAIL PROTECTED] Programador, Administrador, DBA | Centro de Telematica Universidad Nacional del Litoral - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count number of rows in table.
On Sáb 24 Ago 2002 11:19, Tony Harrison wrote: How would I count the number of rows in a mysql table with a WHERE clause? Martín marqués [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]... select count(*) from table_name WHERE . From: Tony Harrison [EMAIL PROTECTED] Sent: Saturday, August 24, 2002 5:54 PM Subject: Re: [PHP] Count number of rows in table. And do I need to use any other functions like mysql_fetch_row() ? Yes. It's a regular sql statement, so you must fetch the results. $sql = select count(*) from table_name WHERE .; $result = mysql_query($sql) or die(mysql_error); $row = mysql_fetch_row($result); $rowCount=$row[0]; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count number of rows in table.
$sql = select count(*) from table_name WHERE .; $result = mysql_query($sql) or die(mysql_error); $row = mysql_fetch_row($result); $rowCount=$row[0]; or $sql = select count(*) from table_name WHERE .; $result = mysql_query($sql) or die(mysql_error); $rowCount=mysql_result($result); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count number of rows in table.
or, you should be able to simply do this, without the cost of fetching the results: $result = mysql_query(SELECT count(*) FROM table WHERE); $num_rows = mysql_num_rows($result); echo $num_rows Rows\n; $sql = select count(*) from table_name WHERE .; $result = mysql_query($sql) or die(mysql_error); $row = mysql_fetch_row($result); $rowCount=$row[0]; or $sql = select count(*) from table_name WHERE .; $result = mysql_query($sql) or die(mysql_error); $rowCount=mysql_result($result); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count number of rows in table.
On Sunday 25 August 2002 22:07, salamander wrote: or, you should be able to simply do this, without the cost of fetching the results: $result = mysql_query(SELECT count(*) FROM table WHERE); $num_rows = mysql_num_rows($result); echo $num_rows Rows\n; No. This only returns 1 row regardless. SELECT COUNT(*) FROM ... only returns a single row with a single column containing the row count. Using mysql_num_rows() on that will always return 1. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* I'm going to Vietnam at the request of the White House. President Johnson says a war isn't really a war without my jokes. -- Bob Hope */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count number of rows in table.
okay, so then a select * and then a num_rows ... On Sunday, August 25, 2002, at 10:11 AM, Jason Wong wrote: On Sunday 25 August 2002 22:07, salamander wrote: or, you should be able to simply do this, without the cost of fetching the results: $result = mysql_query(SELECT count(*) FROM table WHERE); $num_rows = mysql_num_rows($result); echo $num_rows Rows\n; No. This only returns 1 row regardless. SELECT COUNT(*) FROM ... only returns a single row with a single column containing the row count. Using mysql_num_rows() on that will always return 1. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* I'm going to Vietnam at the request of the White House. President Johnson says a war isn't really a war without my jokes. -- Bob Hope */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count number of rows in table.
I think you were on the right track with your first response. Selecting a count(*) gives you the number of rows returned without the overhead of actually returning all of the rows to PHP. Most people will rename the count as something more easy to reference (and/or more descriptive) in the result set: select count(*) as num_movies from movies where actor='Val Kilmer'; What Jason was trying to explain is that the data you are looking for is actually in the query you performed. You specifically queried for the number of rows. Your result set consists of a single row with a single element, num_movies. Happy hacking. Chris salamander wrote: okay, so then a select * and then a num_rows ... On Sunday, August 25, 2002, at 10:11 AM, Jason Wong wrote: On Sunday 25 August 2002 22:07, salamander wrote: or, you should be able to simply do this, without the cost of fetching the results: $result = mysql_query(SELECT count(*) FROM table WHERE); $num_rows = mysql_num_rows($result); echo $num_rows Rows\n; No. This only returns 1 row regardless. SELECT COUNT(*) FROM ... only returns a single row with a single column containing the row count. Using mysql_num_rows() on that will always return 1. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] count link clicks
Write a link wrapper that you would use like this: a href=wrap.php/www.domain.com/path/file.html Then in wrap.php: ?php $link = substr($PATH_INFO,1); ... increment counter in database for $link ... header('Location: $link'); ? -Rasmus On Tue, 13 Aug 2002 [EMAIL PROTECTED] wrote: How do I count how many times a user clicks on a certain link? (and put it into and array or variable I guess). I want to be able to repeat a certain action on the same page as many times as the user clicks on the link($PHP_SELF). Thanks, - Vic __ Post your ad for free now! http://personals.yahoo.ca -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] count link clicks
Really? That sounds more complicated than I think I need it to be, can't I use something like: 'a href='.$PHP_SELF.'?add_form='.$value.'' and somehow (this is what I need to know) get $value to increase in value as the user clicks on the link again and again... What I want to do in the final product is to display a text imput form onece and if the user clicks on the link the form (same) will be displayed again under the first one. - Vic -Original Message- From: Rasmus Lerdorf [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 13, 2002 2:49 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: [PHP] count link clicks Write a link wrapper that you would use like this: a href=wrap.php/www.domain.com/path/file.html Then in wrap.php: ?php $link = substr($PATH_INFO,1); ... increment counter in database for $link ... header('Location: $link'); ? -Rasmus On Tue, 13 Aug 2002 [EMAIL PROTECTED] wrote: How do I count how many times a user clicks on a certain link? (and put it into and array or variable I guess). I want to be able to repeat a certain action on the same page as many times as the user clicks on the link($PHP_SELF). Thanks, - Vic __ Post your ad for free now! http://personals.yahoo.ca -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php __ Post your ad for free now! http://personals.yahoo.ca -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] count link clicks
Really? That sounds more complicated than I think I need it to be, can't I use something like: 'a href='.$PHP_SELF.'?add_form='.$value.'' and somehow (this is what I need to know) get $value to increase in value as the user clicks on the link again and again... Nope, you would be fighting race conditions forever with an approach like that. You need an atomic way to increment a counter. The best way to do that is to use the builtin atomicity of a database engine. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] count link clicks
I have no database, this has to be done in PHP - Vic -Original Message- From: Rasmus Lerdorf [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 13, 2002 3:05 PM To: vic Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: RE: [PHP] count link clicks Really? That sounds more complicated than I think I need it to be, can't I use something like: 'a href='.$PHP_SELF.'?add_form='.$value.'' and somehow (this is what I need to know) get $value to increase in value as the user clicks on the link again and again... Nope, you would be fighting race conditions forever with an approach like that. You need an atomic way to increment a counter. The best way to do that is to use the builtin atomicity of a database engine. -Rasmus __ Post your ad for free now! http://personals.yahoo.ca -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] count link clicks
Then you are going to have to lock a text file, but chances are you will end up deadlocking things. I'd rethink the whole thing if I were you. -Rasmus On Tue, 13 Aug 2002, vic wrote: I have no database, this has to be done in PHP - Vic -Original Message- From: Rasmus Lerdorf [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 13, 2002 3:05 PM To: vic Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: RE: [PHP] count link clicks Really? That sounds more complicated than I think I need it to be, can't I use something like: 'a href='.$PHP_SELF.'?add_form='.$value.'' and somehow (this is what I need to know) get $value to increase in value as the user clicks on the link again and again... Nope, you would be fighting race conditions forever with an approach like that. You need an atomic way to increment a counter. The best way to do that is to use the builtin atomicity of a database engine. -Rasmus __ Post your ad for free now! http://personals.yahoo.ca -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] count link clicks
I think I'm on the right track with: ?php $i = $value++; // Show first link echo 'a href='.$PHP_SELF.'?add_form='.$value.' New paragraph /a /font'; // Isert form html into $data_fields variable $data_fields = 'html html blah blah a href='.$PHP_SELF.'?add_form='.$value.' New paragraph /a'; while ($i = $value) { echo $data_fields; } ? The only problem is that it runs for an infinite number of times, I want it to run for as many times as the http://domain.com?add_form=1 (IE: 1 in this case) defines. - Vic __ Post your ad for free now! http://personals.yahoo.ca -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] count link clicks
You need to use a javascript (client side language) if you want to accomplish this without reloading the page. Something like thike this but you would need to do some more RD at a javascript form or something cuz I know PHP a lot better than javascript === The functions: script language=Javascript var count; function addForm() { if(!count) { count=0; } writeForm(count); count++; } function writeForm(num) { var link = 'a href=javascript:void(0); onMouseDown=addForm('+num+');' } /script You're link: a href=\javascript:void(0);\ onMouseDown=\addForm();\ More stuff here... Really? That sounds more complicated than I think I need it to be, can't I use something like: 'a href='.$PHP_SELF.'?add_form='.$value.'' and somehow (this is what I need to know) get $value to increase in value as the user clicks on the link again and again... What I want to do in the final product is to display a text imput form onece and if the user clicks on the link the form (same) will be displayed again under the first one. - Vic -Original Message- From: Rasmus Lerdorf [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 13, 2002 2:49 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: [PHP] count link clicks Write a link wrapper that you would use like this: a href=wrap.php/www.domain.com/path/file.html Then in wrap.php: ?php $link = substr($PATH_INFO,1); ... increment counter in database for $link ... header('Location: $link'); ? -Rasmus On Tue, 13 Aug 2002 [EMAIL PROTECTED] wrote: How do I count how many times a user clicks on a certain link? (and put it into and array or variable I guess). I want to be able to repeat a certain action on the same page as many times as the user clicks on the link($PHP_SELF). Thanks, - Vic __ Post your ad for free now! http://personals.yahoo.ca -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php __ Post your ad for free now! http://personals.yahoo.ca -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Mike Dunlop Webmaster Animation World Network [EMAIL PROTECTED] http://www.awn.com (323) 606-4238 office (323) 466-6619 fax 6525 Sunset Blvd. GS10 Los Angeles, CA 90028 USA -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] count link clicks
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 13, 2002 12:23 PM To: 'Rasmus Lerdorf'; 'vic' Cc: [EMAIL PROTECTED] Subject: RE: [PHP] count link clicks I think I'm on the right track with: ?php // // CHANGE THIS: // // $i = $value++; // /// // TO THIS: $value = $add_form + 1; // Show first link echo 'a href='.$PHP_SELF.'?add_form='.$value.' New paragraph /a /font'; // Isert form html into $data_fields variable $data_fields = 'html html blah blah a href='.$PHP_SELF.'?add_form='.$value.' New paragraph /a'; // CHANGE THIS: // // while ($i = $value) { // echo $data_fields; // } // // TO THIS: for($i=0; $i$add_form; $i++) { echo $data_fields; } ? The only problem is that it runs for an infinite number of times, I want it to run for as many times as the http://domain.com?add_form=1 (IE: 1 in this case) defines. - Vic __ Post your ad for free now! http://personals.yahoo.ca -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] count link clicks
Can someone tell me how I can make an array increase its index? (ie a script that pushes values into an array) I figured if in the link: a href='.$PHP_SELF.'?add_form='.$value.' instead of $value (or if value was an array) I could do something like: for ($i=0; $icount($myarray); i++) { } or something like: foreach($array as $num) { } I really wish I knew how to make something like: If isset blah blah increase the values in this array and then echo this variable as many times as array has values; - Vic -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 13, 2002 3:23 PM To: 'Rasmus Lerdorf'; 'vic' Cc: [EMAIL PROTECTED] Subject: RE: [PHP] count link clicks I think I'm on the right track with: ?php $i = $value++; // Show first link echo 'a href='.$PHP_SELF.'?add_form='.$value.' New paragraph /a /font'; // Isert form html into $data_fields variable $data_fields = 'html html blah blah a href='.$PHP_SELF.'?add_form='.$value.' New paragraph /a'; while ($i = $value) { echo $data_fields; } ? The only problem is that it runs for an infinite number of times, I want it to run for as many times as the http://domain.com?add_form=1 (IE: 1 in this case) defines. - Vic __ Post your ad for free now! http://personals.yahoo.ca -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php __ Post your ad for free now! http://personals.yahoo.ca -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] count link clicks
THANK YOU! THANK YOU! This does exactly what I need it to! I wish they thought me how to count at PHP kindergarten. - Vic -Original Message- From: Dave at Sinewaves.net [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 13, 2002 3:20 PM To: [EMAIL PROTECTED]; 'Rasmus Lerdorf'; 'vic' Cc: [EMAIL PROTECTED] Subject: RE: [PHP] count link clicks -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 13, 2002 12:23 PM To: 'Rasmus Lerdorf'; 'vic' Cc: [EMAIL PROTECTED] Subject: RE: [PHP] count link clicks I think I'm on the right track with: ?php // // CHANGE THIS: // // $i = $value++; // /// // TO THIS: $value = $add_form + 1; // Show first link echo 'a href='.$PHP_SELF.'?add_form='.$value.' New paragraph /a /font'; // Isert form html into $data_fields variable $data_fields = 'html html blah blah a href='.$PHP_SELF.'?add_form='.$value.' New paragraph /a'; // CHANGE THIS: // // while ($i = $value) { // echo $data_fields; // } // // TO THIS: for($i=0; $i$add_form; $i++) { echo $data_fields; } ? The only problem is that it runs for an infinite number of times, I want it to run for as many times as the http://domain.com?add_form=1 (IE: 1 in this case) defines. - Vic __ Post your ad for free now! http://personals.yahoo.ca -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php __ Post your ad for free now! http://personals.yahoo.ca -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Count
Hi, I want to make this sql query visual does anybody have any idea :-) SELECT date_format(t_timestamp_opened,'%Y %m %d'), count(date_format(t_timestamp_opened,'%Y %m %d')) FROM crm.ticket group by date_format(t_timestamp_opened, '%Y %m %d') order by t_timestamp_opened; Visual? What do you mean? You want to display the results on the page? In that case, just step through using mysql_fetch_array and echo each row. Or did you want something else? Cheers Jon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count concarent logins (newbie)
in A web site where logins are managed with php sesions is it possible to count how many concurent users are loged in ?? I believe that one way is to keep in a mysql table every login user but how can i delete a loged-in record when user session terminates abnormal If you use the database, you many have to delete the session after a timeout period. Of course that means you you need to update the session table everytime a page is opened.. /dkm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count
can do another way $sql = select count(fieldname) from Products; $result=mysql_query($sql); $myrow=$mysql_fetch_row($result); $countrows = $myrow[0]; ( or might be $myrow[1] check out) will do the job /sagar - Original Message - From: David Robley [EMAIL PROTECTED] To: Kevin P [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, August 30, 2001 6:06 AM Subject: Re: [PHP] Count On Thu, 30 Aug 2001 08:16, Kevin P wrote: Hi I have counted some rows in MySQL and I need to know how to pull out the number of rows. SELECT COUNT(*) AS myCount FROM Products Thanks Kevin $query = SELECT COUNT(*) AS myCount FROM Products; $result = mysql_db_query($database, $query); $row = mysql_fetch_array($result); extract($row); echo $myCount; might do the trick; unless I've left a syntax error in there :-) -- David Robley Techno-JoaT, Web Maintainer, Mail List Admin, etc CENTRE FOR INJURY STUDIES Flinders University, SOUTH AUSTRALIA I'm so broke, I can't even pay attention. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Count
On Thu, 30 Aug 2001 08:16, Kevin P wrote: Hi I have counted some rows in MySQL and I need to know how to pull out the number of rows. SELECT COUNT(*) AS myCount FROM Products Thanks Kevin $query = SELECT COUNT(*) AS myCount FROM Products; $result = mysql_db_query($database, $query); $row = mysql_fetch_array($result); extract($row); echo $myCount; might do the trick; unless I've left a syntax error in there :-) -- David Robley Techno-JoaT, Web Maintainer, Mail List Admin, etc CENTRE FOR INJURY STUDIES Flinders University, SOUTH AUSTRALIA I'm so broke, I can't even pay attention. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Count total
Assuming MySQL... ? $score = mysql_query(SELECT SUM(score), userid, name FROM score_table GROUP BY userid); mysql_query(DELETE FROM totalscore_table); while (list($score, $userid, $name) = mysql_fetch_array($scores)) mysql_query(INSERT INTO totalscore_table (userid, name, totalscore) VALUES ('$userid', '$name', '.addslashes($totalscore).')); ? /* Chris Lambert, CTO - [EMAIL PROTECTED] WhiteCrown Networks - More Than White Hats Web Application Security - www.whitecrown.net */ - Original Message - From: Martin Kampherbeek [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, August 19, 2001 5:34 AM Subject: [PHP] Count total Hi, Who can help me with the following problem? I have the tables score and totalscore. Score: id userid name score Totalscore: userid name totalscore In the table score one user can have mutiple scores. But in totalscore the userid is unique. Now I want to count all the score's of a user en place this at the same user in totalscore. Example of score: 11Martin10 22John5 33Richard 12 41Martin 3 53Richard8 61Martin 7 72John15 So I would like to know the total score of each user. But I don't know how to do this. Who can help me out? Cheers, Martin. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Count total
On Sun, 19 Aug 2001, Martin Kampherbeek wrote: Hi, Who can help me with the following problem? I have the tables score and totalscore. Score: id userid name score Totalscore: userid name totalscore In the table score one user can have mutiple scores. But in totalscore the userid is unique. Now I want to count all the score's of a user en place this at the same user in totalscore. Example of score: 11Martin10 22John5 33Richard 12 41Martin 3 53Richard8 61Martin 7 72John15 So I would like to know the total score of each user. But I don't know how to do this. Who can help me out? insert into totalscores (userid,name,totalscore) select userid, name, sum(score) as totalscore from scores group by userid; -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Count total
On 19-Aug-2001 Martin Kampherbeek wrote: Hi, Who can help me with the following problem? I have the tables score and totalscore. Score: id userid name score Totalscore: userid name totalscore In the table score one user can have mutiple scores. But in totalscore the userid is unique. Now I want to count all the score's of a user en place this at the same user in totalscore. Example of score: 11Martin10 22John5 33Richard 12 41Martin 3 53Richard8 61Martin 7 72John15 So I would like to know the total score of each user. But I don't know how to do this. Who can help me out? REPLACE INTO Totalscore SELECT userid,name,sum(score) from Score GROUP BY userid; Regards, -- Don Read [EMAIL PROTECTED] -- It's always darkest before the dawn. So if you are going to steal the neighbor's newspaper, that's the time to do it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] count()?
Jeremy Morano wrote: Hi, I was woundering how to read and find the # of records in my table... Do I use count()??? select count(*) from table regards Wagner -- Madness takes its toll. Please have exact change. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] count number of email sent to us
How about when there is two people click on the email link at the same time (which could happen on internet) , what will happen to the value that will pass to javascript variables as number of click? Jack [EMAIL PROTECTED] Love your enemies, it will drive them nuts - Original Message - From: Francis Fillion [EMAIL PROTECTED] To: Jack [EMAIL PROTECTED] Cc: Zak Greant [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, July 18, 2001 10:19 AM Subject: Re: [PHP] count number of email sent to us Yes you can send javascript stuff to php, juste use a form form name=test method=POST action=xy.php input type=hidden name=click /form script function whatever(){ document.test.click.value= nomberofclick; document.test.submit(); } /script or something like that and $click will have the number of click in xy.php I'm not sure if this is good, can someone double check? Jack wrote: Sorry, It is mistyping here. I mean, we normally use variables from php to do something in javascript function. But how could we use value from variables in javascript function to do something in php function? Jack [EMAIL PROTECTED] Love your enemies, it will drive them nuts - Original Message - From: Zak Greant [EMAIL PROTECTED] To: Jack [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Wednesday, July 18, 2001 2:39 AM Subject: Re: [PHP] count number of email sent to us Check the list archives - this question gets posed quite often. --zak - Original Message - From: Jack [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Wednesday, July 18, 2001 1:38 PM Subject: Re: [PHP] count number of email sent to us Yes, that is the point here. We normally use variables from php to do something in php function, how could we use javascript variables to do something in php function? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- Francis Fillion, BAA SI Broadcasting live from his linux box. And the maintainer of http://www.windplanet.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] count number of email sent to us
hi jack, the easiest way for you to do this is by using javascript. do somethins like: a href=mailto:[EMAIL PROTECTED]; onClick=countClick()Big George/a and have a javascript function like: script... function countClick()= { ...do stuffs } /script i dont know if you can embed php in javascript function or not, or any other method you can use. halmi/ On Wed, 18 Jul 2001 14:17:57 -0500 Jack [EMAIL PROTECTED] wrote: Dear people, I have an email link on my page like this a href=mailto:[EMAIL PROTECTED]; Big George /a and I want to know how may people click on on this particular link to keep the record, may be insert this record into a table as well ( but don't erally have to) Is there any technique at all to achieve this? cheers Jack [EMAIL PROTECTED] Love your enemies, it will drive them nuts halmi/ /** http://affroman.com **/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] count number of email sent to us
Yes, that is the point here. We normally use variables from php to do something in php function, how could we use javascript variables to do something in php function? Jack [EMAIL PROTECTED] Love your enemies, it will drive them nuts - Original Message - From: halmi yasin [EMAIL PROTECTED] To: Jack [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Wednesday, July 18, 2001 10:43 AM Subject: Re: [PHP] count number of email sent to us hi jack, the easiest way for you to do this is by using javascript. do somethins like: a href=mailto:[EMAIL PROTECTED]; onClick=countClick()Big George/a and have a javascript function like: script... function countClick()= { ...do stuffs } /script i dont know if you can embed php in javascript function or not, or any other method you can use. halmi/ On Wed, 18 Jul 2001 14:17:57 -0500 Jack [EMAIL PROTECTED] wrote: Dear people, I have an email link on my page like this a href=mailto:[EMAIL PROTECTED]; Big George /a and I want to know how may people click on on this particular link to keep the record, may be insert this record into a table as well ( but don't erally have to) Is there any technique at all to achieve this? cheers Jack [EMAIL PROTECTED] Love your enemies, it will drive them nuts halmi/ /** http://affroman.com **/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] count number of email sent to us
Check the list archives - this question gets posed quite often. --zak - Original Message - From: Jack [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Wednesday, July 18, 2001 1:38 PM Subject: Re: [PHP] count number of email sent to us Yes, that is the point here. We normally use variables from php to do something in php function, how could we use javascript variables to do something in php function? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] count number of email sent to us
Sorry, It is mistyping here. I mean, we normally use variables from php to do something in javascript function. But how could we use value from variables in javascript function to do something in php function? Jack [EMAIL PROTECTED] Love your enemies, it will drive them nuts - Original Message - From: Zak Greant [EMAIL PROTECTED] To: Jack [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Wednesday, July 18, 2001 2:39 AM Subject: Re: [PHP] count number of email sent to us Check the list archives - this question gets posed quite often. --zak - Original Message - From: Jack [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Wednesday, July 18, 2001 1:38 PM Subject: Re: [PHP] count number of email sent to us Yes, that is the point here. We normally use variables from php to do something in php function, how could we use javascript variables to do something in php function? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] count number of email sent to us
Both topics are covered frequently :) --zak Jack wrote: Sorry, It is mistyping here. I mean, we normally use variables from php to do something in javascript function. But how could we use value from variables in javascript function to do something in php function? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] count number of form fields?
A multiple dropdown lists will produce an array is you put [] when naming the list. You than need to count how many elements you have in the array. py p.s. it could be done in javascript as well, but it's so easy in php :) - Original Message - From: Jaxon [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, July 13, 2001 3:32 PM Subject: [PHP] count number of form fields? Hi, Can someone give me an example of how to count the number of form fields entered? E.g. let's say I have three dropdown lists, the first is mandatory, and the second two are optional. I want to be able to tell my target php script how many of the dropdowns are populated. thanks in advance! jaxon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] count() multidimensional array
can't say for sure, but a good guess is some problems with undefined vars. try using fforeach insted, its alot simpler. ?php foreach($check as $j_pos = $j_val) foreach($check[$j_pos] as $i_pos = $i_val) $message .= {$pre[$j_pos][$i_pos]} {$post[$j_pos][$i_pos]} {$name[$j_pos][$i_pos]} {$city[$j_pos][$i_pos]} {$state[$j_pos][$i_pos]} \n; ? input type='checkbox' name='check[0][0]' value='1' checked input type='checkbox' name='check[0][1]' value='1' input type='checkbox' name='check[1][0]' value='1' checked input type='checkbox' name='check[1][1]' value='1' checked input type='checkbox' name='check[2][0]' value='1' input type='checkbox' name='check[2][1]' value='1' input type='checkbox' name='check[3][0]' value='1' input type='checkbox' name='check[3][1]' value='1' checked ok, now we have an example, $check[0][0] $check[1][0] $check[1][1] $check[3][1] are set, the others are not. you can see why 'for($c = 0; $c count($check); $c++)' will not work. foreach simplifies things alot. you also do not need to check 'if ($check[$j][$i] == 1)' becase if it is set at all, then it 'had' to be checked. Is this what you were looking for ? -- Chris Lee [EMAIL PROTECTED] Dean Martin [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I have a multidimensional array being created by a form. Most fields are pre-populated with a few that people can add to the list. There is a box beside each row that they can check whether that item is in or not. My code to list only the rows that were checked is this.. for ($j=1 ; $j=5; $j++) { for ($i=0 ; $icount($check[$j]) ; $i++) { if ($check[$j][$i] == 1)//was boxed checked? { $message .= $pre[$j][$i]. .$post[$j][$i]. .$name[$j][$i]. .$city[$j][$i]. .$state[$j][$i]\n; } } } This code is creating an endless loop and times out the server with memory overruns. What am I missing? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] count() multidimensional array
Dean Martin [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... My code to list only the rows that were checked is this.. for ($j=1 ; $j=5; $j++) SNIP This code is creating an endless loop and times out the server with memory overruns. What am I missing? In the end-loop condition, you're using assignment ('=') instead of if-equal ('=='). Effectively, the loop runs until 5 == 0 ;-) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]