Jump to content

Recommended Posts

Hey,

 

I have a basic understanding of php but I need a little help to do something.

 

I have rows in database table `users` called 'views', 'favourites' and 'subscribers' etc. The values in each of them rows are expressed as numbers ie 'user1 has 35 subscribers'

 

I want to be able to create a simple feature which reads this data and converts it into one total number.

 

e.g.

data for user1

profile views: 150

favourites: 50

subscribers: 10

 

total: 210

 

Which i can then use as a basic foundation for a points system.

 

I don't know how to count using sql and pull the data and merge it all.

 

Can someone help or assist me with this problem?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/238490-help-with-sql-count/
Share on other sites

I'm assuming you know how to connect to a database and use a simple mysql_query.

 

So try something like this (assuming you have a function called conn() that handles the database connection and that there is a field in the database called username):

$username = 'Johnny Bravo';
$conn = conn('database_name');
$q= mysql_query("select `views`,`favourites`,`subscribers` from `users` where `username`= '$username'",$conn);
$r = mysql_fetch_assoc($);
@mysql_close($conn);
if(!empty($r)){
$total = $r['views'] + $r['favourites'] + $r['subscribers'];
echo $total;
}else{
  echo 'username not found in database';
}

Link to comment
https://forums.phpfreaks.com/topic/238490-help-with-sql-count/#findComment-1225531
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.