Jump to content

connect to database and count tables


saltedm8

Recommended Posts

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

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

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);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.