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 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'"; 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. 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? 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 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>'); ?> 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! 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
Archived
This topic is now archived and is closed to further replies.