saltedm8 Posted June 17, 2011 Share Posted June 17, 2011 Hi, I am in urgent need of some urgent help I need to connect to my database and count the amount of posts by user id 1155 then display the number of posts SELECT * FROM `vbpost` WHERE `userid` =1155 ; I am really sorry to ask such an easy one but I am not confident with php and I need this quite quickly also if anyone knows vbulletin 4, maybe you could include a query to put that number into a users post count ( saltedm8 ) table name webproca_vb thank you Link to comment https://forums.phpfreaks.com/topic/239668-connect-to-database-and-count-tables/ Share on other sites More sharing options...
The Little Guy Posted June 17, 2011 Share Posted June 17, 2011 SELECT count(*) as total FROM `vbpost` WHERE `userid` =1155 ; Link to comment https://forums.phpfreaks.com/topic/239668-connect-to-database-and-count-tables/#findComment-1231157 Share on other sites More sharing options...
fRAiLtY- Posted June 17, 2011 Share Posted June 17, 2011 SELECT COUNT(*) FROM 'vbpost' WHERE 'userid'=1155; That should display the number of occurences. Link to comment https://forums.phpfreaks.com/topic/239668-connect-to-database-and-count-tables/#findComment-1231158 Share on other sites More sharing options...
mikosiko Posted June 17, 2011 Share Posted June 17, 2011 SELECT COUNT(*) FROM 'vbpost' WHERE 'userid'=1155; That should display the number of occurences. no is not... ' are not the same as ` Link to comment https://forums.phpfreaks.com/topic/239668-connect-to-database-and-count-tables/#findComment-1231160 Share on other sites More sharing options...
saltedm8 Posted June 17, 2011 Author Share Posted June 17, 2011 thanks tried <?php $con = mysql_connect("localhost","xxxxxxxx","xxxxxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } $go = 'SELECT count( webproca_vb ) as total FROM `vbpost` WHERE `userid` =1155' ; $result = mysql_query($go); echo $result ; mysql_close($con); ?> just getting a blank page, how can I see the result in number form ? thanks Link to comment https://forums.phpfreaks.com/topic/239668-connect-to-database-and-count-tables/#findComment-1231173 Share on other sites More sharing options...
The Little Guy Posted June 17, 2011 Share Posted June 17, 2011 You need to convert the result to a php array, <?php $con = mysql_connect("localhost","xxxxxxxx","xxxxxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } $go = 'SELECT count( webproca_vb ) as total FROM `vbpost` WHERE `userid` =1155' ; $result = mysql_query($go); // Note this line: $row = mysql_fetch_assoc($result); echo $row['total']; mysql_close($con); ?> Link to comment https://forums.phpfreaks.com/topic/239668-connect-to-database-and-count-tables/#findComment-1231184 Share on other sites More sharing options...
saltedm8 Posted June 17, 2011 Author Share Posted June 17, 2011 thank you very much.. why would I get this ? Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/webproca/public_html/aaaaa.php on line 14 no results Link to comment https://forums.phpfreaks.com/topic/239668-connect-to-database-and-count-tables/#findComment-1231188 Share on other sites More sharing options...
The Little Guy Posted June 17, 2011 Share Posted June 17, 2011 Change this line: $result = mysql_query($go); to this: $result = mysql_query($go)or die(mysql_error()); This will tell us what the mysql error is. Link to comment https://forums.phpfreaks.com/topic/239668-connect-to-database-and-count-tables/#findComment-1231198 Share on other sites More sharing options...
saltedm8 Posted June 17, 2011 Author Share Posted June 17, 2011 ahh, no database selected ? how could that be I thought this did that $go = 'SELECT count( webproca_vb ) as total FROM `vbpost` WHERE `userid` =1155' ; Link to comment https://forums.phpfreaks.com/topic/239668-connect-to-database-and-count-tables/#findComment-1231199 Share on other sites More sharing options...
xyph Posted June 17, 2011 Share Posted June 17, 2011 mysql_select_db( 'dbname', $con ); Link to comment https://forums.phpfreaks.com/topic/239668-connect-to-database-and-count-tables/#findComment-1231203 Share on other sites More sharing options...
The Little Guy Posted June 17, 2011 Share Posted June 17, 2011 you connected but didn't choose a database to use, like this: $con = mysql_connect("localhost","xxxxxxxx","xxxxxxxx"); mysql_select_db("my_cool_database"); Link to comment https://forums.phpfreaks.com/topic/239668-connect-to-database-and-count-tables/#findComment-1231204 Share on other sites More sharing options...
saltedm8 Posted June 17, 2011 Author Share Posted June 17, 2011 I am in debt to everyone who replied, thank you very much,, worked Link to comment https://forums.phpfreaks.com/topic/239668-connect-to-database-and-count-tables/#findComment-1231207 Share on other sites More sharing options...
xyph Posted June 17, 2011 Share Posted June 17, 2011 Debt can be solved by donating to PHPFreaks Link to comment https://forums.phpfreaks.com/topic/239668-connect-to-database-and-count-tables/#findComment-1231225 Share on other sites More sharing options...
The Little Guy Posted June 17, 2011 Share Posted June 17, 2011 Debt can be solved by donating to PHPFreaks You mean to me. Link to comment https://forums.phpfreaks.com/topic/239668-connect-to-database-and-count-tables/#findComment-1231229 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.