SkyRanger Posted July 18, 2015 Share Posted July 18, 2015 Is it possible to count query rows and display query, tried a number of things but can't get row count: $rowhsr = $wpdb->get_results( "SELECT * FROM locations where stname like '%" . $houseaddy ."%'"); $hauntcount = $rowhsr->num_rows; echo 'Number of entries found:' . $hauntcount; foreach ( $rowhsr as $rowhsr ) { echo $rowhsr->stname } Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted July 18, 2015 Share Posted July 18, 2015 Thar wordpress query function returns the results in an array. So you can use count echo 'Number of entries found:' . count($hauntcount); Quote Link to comment Share on other sites More sharing options...
SkyRanger Posted July 19, 2015 Author Share Posted July 19, 2015 Thanks Ch0cu3r but not sure what the issue is: When somebody puts in for example: My Address In the database is 123 My Address Street houseaddy = My Address stname = 123 My Address Street count is coming up = 0 Quote Link to comment Share on other sites More sharing options...
Barand Posted July 19, 2015 Share Posted July 19, 2015 Try doing var_dump($housedddy); to see if its size and content are as expected Quote Link to comment Share on other sites More sharing options...
SkyRanger Posted July 19, 2015 Author Share Posted July 19, 2015 (edited) This is the result string(17) "my address" which is what was searched for and the proper information is displayed from the search Edited July 19, 2015 by SkyRanger Quote Link to comment Share on other sites More sharing options...
Barand Posted July 19, 2015 Share Posted July 19, 2015 There would appear to 10 printable and 7 non-printable characters in that string Quote Link to comment Share on other sites More sharing options...
SkyRanger Posted July 19, 2015 Author Share Posted July 19, 2015 Tried another search and got same result string(17) "121 mount whatley" Quote Link to comment Share on other sites More sharing options...
ginerjm Posted July 20, 2015 Share Posted July 20, 2015 No. You got a better result. This time you show a string that apparently contains 17 printable chars, as the var_dump told you. As Barand pointed out, your previous test showed only 10 printable (visible) chars, yet var_dump said there were 17 actual chars in the content. So - why are you getting non-printable chars in your input? Quote Link to comment Share on other sites More sharing options...
SkyRanger Posted July 21, 2015 Author Share Posted July 21, 2015 ok, got a new error: Notice: Trying to get property of non-object in \www\wp-content\plugins\addysearch\index.php on line 101 string(12) "815 pembroke" We found 0 results. Line 100: $rowhsr = $wpdb->get_results( "SELECT * FROM locations where stname like '%" . $houseaddy ."%'"); Line 101: $hauntcount = $rowhsr->num_rows; Line 102: var_dump($houseaddy); Quote Link to comment Share on other sites More sharing options...
ginerjm Posted July 21, 2015 Share Posted July 21, 2015 Sounds like your query failed to produce the resulting object you expect. Why do the dump before you run the query? Quote Link to comment Share on other sites More sharing options...
SkyRanger Posted July 21, 2015 Author Share Posted July 21, 2015 trying to see what the result is Quote Link to comment Share on other sites More sharing options...
ginerjm Posted July 22, 2015 Share Posted July 22, 2015 I meant 'why NOT do the dump before the query'. Quote Link to comment Share on other sites More sharing options...
SkyRanger Posted July 22, 2015 Author Share Posted July 22, 2015 doesn't matter if it is before or after the query, still getting the same result Quote Link to comment Share on other sites More sharing options...
ginerjm Posted July 22, 2015 Share Posted July 22, 2015 And is it WHAT YOU EXPECT TO SEE? Might be nice to let us know what you are getting if you want us to continue to help you. Show us your current code and what you are getting for output please. Please read this last twice so that you can be sure to give me the help I am asking for. Quote Link to comment Share on other sites More sharing options...
Solution SkyRanger Posted July 22, 2015 Author Solution Share Posted July 22, 2015 stupid me figured out the problem. I had count($hauntcount) when it was suppose to be count($rowhsr) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.