jpratt Posted October 27, 2006 Share Posted October 27, 2006 i am using the count function to return the number of rows returned by a query, but it keeps returning 1 even when I know the value i am using has hundereds of records to count. My code looks like:[code]<?php$keyword = $_GET['keyword'];mysql_select_db($database_database, $linkID);$query = "SELECT * FROM ppctrack WHERE ppcKeyword = " . $keyword;$result = mysql_query($query, $linkID);$pageview = count($result);echo $pageview;?>[/code]Anyone know what i am doing wrong? Link to comment https://forums.phpfreaks.com/topic/25325-count-function/ Share on other sites More sharing options...
wildteen88 Posted October 27, 2006 Share Posted October 27, 2006 $result does not hold the results but a result resource. A result resource points to the location in the memory where the results are stored. YOu use the result resource with othe mysql functions such as mysql_fetch_array, mysql_num_rows, mysql_result etc.What you'll want to do is to use a function called mysql_num_rows this will then return the number of rows returned from the query:[code]$pageview mysql_num_rows($result);[/code]You only use count on arrays. count then counts the number of items within the array. Link to comment https://forums.phpfreaks.com/topic/25325-count-function/#findComment-115485 Share on other sites More sharing options...
jpratt Posted October 27, 2006 Author Share Posted October 27, 2006 i changed it and still does not work. now i accually gives me an error.Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource This is what i changed my code to:[code]<?php$keyword = $_GET['keyword'];mysql_select_db($database_database, $linkID);$query = "SELECT * FROM ppctrack WHERE ppcKeyword = " . $keyword;$result = mysql_query($query, $linkID);$pageview = mysql_num_rows($result);echo $pageview;?>[/code]Any ideas?? Link to comment https://forums.phpfreaks.com/topic/25325-count-function/#findComment-115510 Share on other sites More sharing options...
kenrbnsn Posted October 27, 2006 Share Posted October 27, 2006 You need to enclose all strings in quotes in the query.Try:[code]<?php$query = "SELECT * FROM ppctrack WHERE ppcKeyword = '" . $keyword . "'";$result = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error());?>[/code]The "or die" clause will tell you any syntax errors you have with the query.Ken Link to comment https://forums.phpfreaks.com/topic/25325-count-function/#findComment-115514 Share on other sites More sharing options...
jpratt Posted October 27, 2006 Author Share Posted October 27, 2006 duh, brain freeze, thanks Link to comment https://forums.phpfreaks.com/topic/25325-count-function/#findComment-115528 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.