Dave3765 Posted October 18, 2007 Share Posted October 18, 2007 Hey, I have spent the last few hours searching the forum and Google for the correct way to do this with no luck. I am trying to use the COUNT function to search a table and simply echo a number. I have what I think is a correct mysql query, but can't put this into php despite many (many, many) failed attempts. SELECT COUNT(*) FROM items WHERE vis='Y' If anyone is able to point me in the right direction it would be most appreciated. Thanks, Dave Quote Link to comment https://forums.phpfreaks.com/topic/73853-solved-mysql-query-into-php-have-tried-for-2-hours/ Share on other sites More sharing options...
BlueSkyIS Posted October 18, 2007 Share Posted October 18, 2007 what do you mean "put this into PHP?" $sql = "SELECT COUNT(*) FROM items WHERE vis='Y'"; Quote Link to comment https://forums.phpfreaks.com/topic/73853-solved-mysql-query-into-php-have-tried-for-2-hours/#findComment-372583 Share on other sites More sharing options...
Dave3765 Posted October 18, 2007 Author Share Posted October 18, 2007 Sorry - when I said put in php I mean I would like to use php to display the number in my browser. Quote Link to comment https://forums.phpfreaks.com/topic/73853-solved-mysql-query-into-php-have-tried-for-2-hours/#findComment-372586 Share on other sites More sharing options...
brettpower Posted October 18, 2007 Share Posted October 18, 2007 what do you mean "put this into PHP?" $sql = "SELECT COUNT(*) FROM items WHERE vis='Y'"; Can you post more of your code? Can we see where you echo the results of this query? Quote Link to comment https://forums.phpfreaks.com/topic/73853-solved-mysql-query-into-php-have-tried-for-2-hours/#findComment-372592 Share on other sites More sharing options...
Dave3765 Posted October 18, 2007 Author Share Posted October 18, 2007 I am not sure exactly what I should be writing to get this number to display, and I have tried a ton of different ways with no luck. Below is the closest I have to getting this number to display: <?php include('inc/dbconnect.inc'); $pc_query = @mysql_query("SELECT COUNT(*) FROM items WHERE vis='Y'"); $pc_fetch = mysql_fetch_array($pc_query); $productcount = htmlspecialchars($pc_fetch['name']); echo('<h1>' . $productcount . '</h1>'); ?> I don't know why the htmlspecialchars is there or what it does - I copied it from another section of my script. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/73853-solved-mysql-query-into-php-have-tried-for-2-hours/#findComment-372608 Share on other sites More sharing options...
BlueSkyIS Posted October 18, 2007 Share Posted October 18, 2007 <?php include('inc/dbconnect.inc'); $pc_query = mysql_query("SELECT COUNT(*) AS rec_count FROM items WHERE vis='Y'") or die(mysql_error()); $pc_fetch = mysql_fetch_array($pc_query); $productcount = $pc_fetch['rec_count']; echo('<h1>' . $productcount . '</h1>'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/73853-solved-mysql-query-into-php-have-tried-for-2-hours/#findComment-372611 Share on other sites More sharing options...
Dave3765 Posted October 18, 2007 Author Share Posted October 18, 2007 Thanks BlueSkyIS, Works perfectly - you've saved me a ton of brain-ache Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/73853-solved-mysql-query-into-php-have-tried-for-2-hours/#findComment-372620 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.