I have 5 tables in my database. The only two relevant tables for this is the "users" table and the "results" table. The users table holds all information, id, username, password, etc. Results is where the actual information for what I am doing is kept. Filenames, foldernames, etc.
On one page I need to display how many results someone has. The way I have set this up is each user has an id, say user 50. Then in the results, I create a new row with that users information, in the results there is also a user field. So say user 50 has 5 results or files, each one is entered with 50 in the user field. All I need to do on this page is say "Welcome <name>, you have <XX> amounts of results ready to view/download." I already have the <name> part working, I only need the XX amounts to work.
So I need a code snippet to insert into this page that will check the results table for how many in that table under users is equal to 50. Hopefully this makes sense, and I've tried tons of stuff and I just cannot get it to work.
Here is the code I'm trying to put into this page:
Code: Select all
<?php
// include needed files
require('../db_config.php');
require('../global.php');
// connect to the database
db_connect($mysql['username'],$mysql['password'],$mysql['database'],$mysql['host']);
// assign config options from database to an array
$config = get_config($mysql['prefix']);
debug_mode($config['debug_mode']);
// remove users that have not verified their email after 72 hours if email verification is enabled
if($config['verify_email']=='true' && $config['prune_inactive_users']=='true'){
PruneInactiveUsers($mysql['prefix']);
}
// make sure user is logged in
require('auth.inc.php');
// require the template engine class (MiniTemplator)
require('../lib/MiniTemplator.class.php');
$template = new MiniTemplator;
$templatedir = '../templates/';
if(isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['verify']))
{
remove_user($_SESSION['username'],$mysql['prefix']);
generate_htpasswd($mysql['prefix']);
session_destroy();
redirect('./login.php');
}
$sql= 'SELECT * FROM '.$mysql['prefix'].'users WHERE username="'.$_SESSION['username'].'"';
if(!$result = mysql_query($sql))
{
die('The following MySQL query failed. User data could not be retrieved. '.$sql);
}
// assign the user info to variables
while (($row = mysql_fetch_array($result)) != false)
{
$firstname = $row['firstname'];
}
////////////////
// Code for results amount will go here
/////////////////
$template->readFileIntoString($templatedir."overall_header.html",$header);
$template->readFileIntoString($templatedir."rc.html",$main);
$template->readFileIntoString($templatedir."overall_footer.html",$footer);
$template->setTemplateString($header . $main . $footer);
// set the first name
$template->setVariable("firstname",$firstname);
//////////////
$template->setVariable("counts",$counts);
///////////////
// add javascript to the header
$template->setVariable("code",$javascript);
$template->addBlock("code");
$template->addBlock("javascript");
$template->setVariable("footer",show_user_footer($software_signature));
$template->setVariable("pagename","My Account");
$template->generateOutput();
?>