$result = mysql_query($sql_query, $database); if (!$result) { echo mysql_errno($database) . ": " . mysql_error($database) . "\n"; echo $sql_query; echo "ERROR!"; return 0; } else { $row = mysql_fetch_row($result); return $row[0]; } } /* * The following are the local variables to get the statistics about a user's inventory. After the variables are given an initial value via * their respective function, a check is done against the sum, depSum, and oldest to see if they are blank. If so, they are given a default value. */ $numItems = getNumItems($database, $user); $sum = getSumValue($database, $user); $depSum = getDepSumValue($database, $user); $oldest = getOldest($database, $user); if ($sum == "") { $sum = 0.0; } if ($depSum == "") { $depSum = 0.0; } if ($oldest == "") { $oldest = '<br />   No Items in Inventory'; } /* * The following echo's the html code to add the statistics to the user's My Inventory page. */
} define('ROOT_PATH', $mRootpath); error_reporting(E_ALL); ini_set("display_errors", 1); $database = @mysql_connect('mysql.eecs.ku.edu', $username, $password); if (!$database) { die('Could not connect: ' . mysql_error()); } if (!mysql_select_db($username, $database)) { die('Could not select database: ' . mysql_error()); } /* * The following function generates the sql query and runs it against the database * to get the total number of items in the entire database. It does this by doing a * SELECT * on a view that returns the count of the total rows in the ITEMS table. The * function returns the result of the query. */ function getNumItems($database) { $sql_query = 'SELECT * FROM TOTAL_ITEMS'; return mysql_query($sql_query, $database); } // Gets and stores the result from the getNumItems function. $res = getNumItems($database); // echo's code with the result of the query so long as the query executed successfully while ($row = mysql_fetch_assoc($res)) { echo ' '; echo 'Keeping Track of (' . $row["COUNT(*)"] . ') items'; } //Closes the connection to the database. mysql_close($database);