Jump to content

fife

Members
  • Posts

    381
  • Joined

  • Last visited

Everything posted by fife

  1. Thanks Jazzman1 Ok let me explain the structure of the tables in use. so I have an Asset Table idAsset AssetName idLocation Document table idDocument DocumentName DocumentStandards idDocumentStandards DocumentStandName AssetDocStand idAsset idDocument idDocumentStandards basically when someone uploads a document it has to conform to a standard that's on the system. I need to be able to check which assets do not currently have a document uploaded that matches a required standard in the current location.
  2. Hi Guys I have written this function which basically finds all assets that have a certain document associated with them in a certain location. It works great however I need the opposite. I need all the assets that don't have this document but i cant get my head around the query can anyone help me please? function GetUploadedDocsNoAsset($doctype,$archive, $location){ $colname_DocUp = "-1";if (isset($doctype)) { $colname_DocUp = $doctype;} $colname_Archive = "-1";if (isset($archive)) { $colname_Archive = $archive;}$colname_Location = "-1";if (isset($location)) { $colname_Location = $location;} $query_DocUp = sprintf("SELECT idAssetDocStand FROM AssetDocStand INNER JOINAsset ON AssetDocStand.idAsset = Asset.idAssetWHERE AssetDocStand.idDocumentStandards = %s AND AssetDocStand.Archive=%s AND Asset.idLocation = %s", GetSQLValueString($colname_DocUp, "int"), GetSQLValueString($colname_Archive, "text"), GetSQLValueString($colname_Location, "int"));$DocUp = mysql_query($query_DocUp);$totalRows_DocUp = mysql_num_rows($DocUp);return $totalRows_DocUp;}
  3. Wicked thanks again Barand you are a world of knowledge as usual. I will be updating my site.
  4. Hi Guys. Sorry for not catching up with you all Ive been away. Thank you all very much for your help. I've always used and worked with unix timestamp as I was taught that this was the best way to store dates. Barand as usual your solution is perfect and I will mark it so. So for a follow up am I right in using unix timestamps? I understand its not the best for birthdays now but I'm building a massive employee management and payment system where I will be working with dates and comparing dates a lot. For example an employee will have holidays. Currently I'm storing the start date of the holiday and the end date as unix times. Is this a bad Idea? I was going to do the same with the rota system. If so what would be a better solution? I'd rather change it now while the site is still in its infancy before I run into major issues later. Again thanks Freakers!
  5. Hi Guys. Im just trying to find a list of people with birthdays coming up in the next 14 days from a table in my db. I'm storing birthday as a unix timestamp. Currently I have one birthday coming up on the 10/12/1984 or unix time would be 471484800. My query is returning 0 as the number of birthdays when it should say 1. mysql_select_db($database_dbconnect, $dbconnect);$query_Birth = "SELECT StaffDOB FROM Staff WHERE StaffDOB BETWEEN UNIX_TIMESTAMP(CURDATE()) AND UNIX_TIMESTAMP(ADDDATE(CURDATE(), INTERVAL 14 DAY))";$Birth = mysql_query($query_Birth, $dbconnect);$totalRows_Birth = mysql_num_rows($Birth); echo $totalRows_Birth;
  6. Im trying to create a folder structure through a script on my site. At the minute I need to create one folder $topFolders = array('employment'); and within that folder set the following array of folders, $subFolders = array('references', 'starter-packs', 'certificates', 'health'); I currently have this working fine with the following code... //now make each folder within the branch$topFolders = array('employment'); foreach($topFolders as $folders){$branchTop = mkdir($thisdir . "/uploadedfiles/$branchName/" . $folders, 0777);} //now make the employment system subfolders$subFolders = array('references', 'starter-packs', 'certificates', 'health'); foreach($subFolders as $sub){mkdir($thisdir . "/uploadedfiles/$branchName/employment/" . $sub, 0777);} As you can see this is very limited. If for example I need a new top level folder called "residents" and that had the sub folders of "personal, health, notes, signatures" I would have to write a new foreach loop. Is there a way to make this more dynamic so by adding the new top level folder into the array and its corresponding sub folders the correct set of sub folders is added? I tried turning it into a function but then suffered the same fate. I think my array would look as follows employment => 'references', 'starter-packs', 'certificates', 'health', residents => 'personal', 'health', 'notes', 'signatures' etc
  7. pffft ops. Yes thank you for your time guys my mistake, you rock!
  8. Ok totally new to object so objnoob thank you for your advice. I adopted your approach to one I understand. here is my new code public function updateUserDetails($user){ $sql = sprintf("UPDATE User SET UserForename=%s, UserSurname=%s WHERE IDUser=%s",$this->db->GetSQLValueString($_POST['forename'], "text"), $this->db->GetSQLValueString($_POST['surname'], "text"),$this->db->GetSQLValueString($user->get('IDUser'), "int")); if($this->db->query($sql) === false) {echo mysql_error();} else { return true;}} then When Im calling the method if(isset($_POST['submit'])){ if($um->updateUserDetails($user)===true){header('location : /welcome.php?update=true'); } } buuuuut. it doesnt work. If the query errors it does show my error. If the query passes it doesnt run the header redirect and I dont know why
  9. I have the following two classes <?php class User {private $userdata = array(); //instantiate The User Classpublic function User(){ } public function set($var, $value) {$this->userdata[$var] = $value; } public function get($var) { if(isset($this->userdata[$var])) { return $this->userdata[$var]; } return NULL; } function __destruct() { if($this->userdata){ $this->userdata; } }} class UserService {private $db;private $error;private $fields = array(); public function __construct() {$this->db = new Database(); }//update userpublic function updateUserDetails($user){ $query = sprintf("UPDATE User SET UserForename=%s, UserSurname=%s WHERE IDUser=%s", $this->db->GetSQLValueString($_POST['forename'], "text"), $this->db->GetSQLValueString($_POST['surname'], "text"),$this->db->GetSQLValueString($user->get('IDUser'), "int")); return $this->db->query($query); } public function getCurrentUser($fields) { $this->fields = $fields; $query = sprintf("SELECT ".$this->fields." FROM User WHERE IDUser=%s", $this->db->GetSQLValueString($_SESSION['MM_Username'], "int"));$result = $this->db->query($query); if($result && $this->db->num_rows($result) > 0) { //create new user class$user = new User();$row = $this->db->fetch_assoc($result); //set rows as objectforeach($row as $key => $value){$user->set($key, $value); } return $user;} } ?> My question is as follows. On my update page Im calling the following; $um = new UserService(); $userfields = "*"; $user = $um->getCurrentUser($userfields); if(isset($_POST['submit'])){ $um->updateUserDetails($user); } This runs the update code and returns $this->db->query($query); Now im not too sure how to handle the rest of my update page. obviously I need a success and fail if statement. So I tried if(isset($_POST['submit'])){ $um->updateUserDetails($user); if(isset($um->db->query($query)){ header('location : welcome.php'); } else { echo "Error"; } } but it just says I cant use the $um->db->query() as its a private property. Im struggling to understand what I've actually returned from the updateUser method. Ive returned the full query so how do I now use this or make decisions on it?
  10. Hi mac__gyver and thanks for your reply again blunt or not I don't mind its all help. I did turn on error reporting i used ini_set('display_errors',1); error_reporting(E_ALL); which gives the following error Notice: Undefined variable: IDSystem in bla bla Now I've changed my function to include the database I'm struggling where to turn my $IDSystem into $this->IDSystem when I change my code to class System{ protected static $IDSystem = 1;private $db; //connect to databasepublic function System() { $this->db = new Database(); $this->IDSystem = $IDSystem;} //get the logo public function SystemLogo() { $Query = sprintf("SELECT BSLogo, BSName FROM BusinessSettings WHERE IDBusinessSettings = %s", GetSQLValueString($this->IDSystem, "int")); $Query = $this->db->query($Query);$Result = $this->db->fetch_assoc($Query); if(!empty($Result['BSLogo'])){echo "<img src='/images/uploads/logo/{$Result['BSLogo']} width='220px' height='100px'/>";} else {echo "<h1>{$Result['BSName']}</h1>";}}} I get the following: Notice: Undefined variable: IDSystem in which is now referring to: public function System() { $this->db = new Database(); $this->IDSystem = $IDSystem; } I apologies if i'm coming across as slow. This really is my first proper go at writing object.
  11. Thanks for the advice. I have re-written my code and now I know the problem. I have updated the class to include a database connection which has been tested and works. The problem seems to be with my $IDSystem var is completely blank even though I'm setting it to 1 straight away. class System{ protected static $IDSystem = 1;private $db; public function System() { $this->db = new Database(); } public function SystemLogo() { $Query = sprintf("SELECT BSLogo, BSName FROM BusinessSettings WHERE IDBusinessSettings = %s", GetSQLValueString($IDSystem, "int")); $Query = $this->db->query($Query); $Result = $this->db->fetch_assoc($Query); if(!empty($Result['BSLogo'])){ echo "<img src='/images/uploads/logo/{$Result['BSLogo']} width='220px' height='100px'/>"; } else { echo "<h1>{$Result['BSName']}</h1>"; } } }
  12. And it doesn't work! Im trying to write my first simple object which will just echo out a logo. I don't think the var $IDSystem is being passed through. As its my first attempted I'm struggling to see what I have wrong. class System{public $IDSystem = '1'; public function __construct() {$this->IDSystem = $IDSystem; } public function SystemLogo() { mysql_select_db($database_dbconnect, $dbconnect); $Query = sprintf("SELECT BSLogo, BSName FROM BusinessSettings WHERE IDBusinessSettings = %s", GetSQLValueString($this->IDSystem, "int")); $Query = mysql_query($Query, $dbconnect) or die(mysql_error()); $Result = mysql_fetch_assoc($Query); if(!empty($Result['BSLogo'])){ echo "<img src='/images/uploads/logo/{$Result['BSLogo']} width='220px' height='100px'/>"; } else {echo "<h1>{$Result['BSName']}</h1>"; } } } then on the page I'm writing $logo = new System;echo $logo->SystemLogo(); [/php]
×
×
  • 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.