fife
Members-
Posts
381 -
Joined
-
Last visited
Everything posted by fife
-
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.
-
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;}
-
Wicked thanks again Barand you are a world of knowledge as usual. I will be updating my site.
-
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!
-
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;
-
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
-
pffft ops. Yes thank you for your time guys my mistake, you rock!
-
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
-
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?
-
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.
-
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>"; } } }
-
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]
-
OK guys simple lesson for everyone. Don't declare your query twice in your scripts. One over rides the other. Ops. Sorry for wasting anyone's time.
-
yes calsect all lower case. Am I somehow not including it in the loop?
-
I have a query which is looking for events on any given month of the year. It looks as follows... $events = array();mysql_select_db($database_dbconnect, $dbconnect);$query = "SELECT calsect, title,idcalendar, DATE_FORMAT(event_date,'%Y-%m-%d') AS event_date FROM calendar WHERE event_date LIKE '$year-$month%'";$result = mysql_query($query, $dbconnect) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) {$events[$row['event_date']][] = $row;} I then have a function which calls a calendar. As the function is looping through days of the week it also checks on each day if there is any event. If there is it prints it. If not it moves on to the next day. It actually works great. I can echo the title, idcalendar and the event_date but I can not the calsect field. /* print "blank" days until the first of the current week */for($x = 0; $x < $running_day; $x++):$calendar.= '<td class="calendar-day-np"> </td>';$days_in_this_week++;endfor; /* keep going with days.... */for($list_day = 1; $list_day <= $days_in_month; $list_day++):$calendar.= '<td class="calendar-day"><div style="position:relative;height:100px;">';/* add in the day number */$calendar.= '<div class="day-number">'.$list_day.'</div>'; $event_day = sprintf('%04d-%02d-%02d', $year, $month, $list_day); /* list the events */if(isset($events[$event_day])) {foreach($events[$event_day] as $event) { //My title appears but the $event['calsect'] is not!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! $calendar.='<div class="' .$event['calsect']. '">' .$event['title']. '</div>';}}else {$calendar.= str_repeat('<p> </p>',2);} If I view source on an event I get this. <div class="">Test Event</div> where class should equal $event['calsect'] (or blue in this case) .
-
Calling events from an array within a loop from a function
fife replied to fife's topic in PHP Coding Help
Ok I have changed my main query //from //SELECT title,idcalendar, DATE_FORMAT(event_date,'%Y-%m-%D') AS event_date FROM calendar WHERE event_date LIKE '$year-$month%' //to SELECT title,idcalendar, DATE_FORMAT(event_date,'%Y-%m-%d') AS event_date FROM calendar WHERE event_date LIKE '$year-$month%' which will output in the format 2013-07-16 I have also updated //from $event_day = $year.'-'.$month.'-'.$list_day; //to $event_day = sprintf('%04d-%02d-%02d',$year,$month,$list_day); The query again is working when type directly into phpmyadmin but the foreach loop on the page $event_day = sprintf('%04d-%02d-%02d',$year,$month,$list_day); /* list the events */if(isset($events[$event_day])) {foreach($events[$event_day] as $event) {$calendar.= '<div class="event">'.$event['title'].'</div>'; }}else {$calendar.= str_repeat('<p> </p>',2);} Still seems to be outputting 2 empty paragraph tags for the events. Is there anyway I can see if $event_day has values? Even in my query only before hand would do. //how do I make this line print the events here? while($row = mysql_fetch_assoc($result)) {$events[$row['event_date']][] = $row;} -
Calling events from an array within a loop from a function
fife replied to fife's topic in PHP Coding Help
The full function /* draws a calendar */function draw_calendar($month,$year,$events = array()){ /* draw table */$calendar = '<table cellpadding="0" cellspacing="0" class="calendar">'; /* table headings */$headings = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');$calendar.= '<tr class="calendar-row"><td class="calendar-day-head">'.implode('</td><td class="calendar-day-head">',$headings).'</td></tr>'; /* days and weeks vars now ... */$running_day = date('w',mktime(0,0,0,$month,1,$year));$days_in_month = date('t',mktime(0,0,0,$month,1,$year));$days_in_this_week = 1;$day_counter = 0;$dates_array = array(); /* row for week one */$calendar.= '<tr class="calendar-row">'; /* print "blank" days until the first of the current week */for($x = 0; $x < $running_day; $x++):$calendar.= '<td class="calendar-day-np"> </td>';$days_in_this_week++;endfor; /* keep going with days.... */for($list_day = 1; $list_day <= $days_in_month; $list_day++):$calendar.= '<td class="calendar-day"><div style="position:relative;height:100px;">';/* add in the day number */$calendar.= '<div class="day-number">'.$list_day.'</div>'; $event_day = $year.'-'.$month.'-'.$list_day; /* list the events */if(isset($events[$event_day])) {foreach($events[$event_day] as $event) {$calendar.= '<div class="event">'.$event['title'].'</div>'; }}else {$calendar.= str_repeat('<p> </p>',2);} $calendar.= '</div></td>';if($running_day == 6):$calendar.= '</tr>';if(($day_counter+1) != $days_in_month):$calendar.= '<tr class="calendar-row">';endif;$running_day = -1;$days_in_this_week = 0;endif;$days_in_this_week++; $running_day++; $day_counter++;endfor; /* finish the rest of the days in the week */if($days_in_this_week < :for($x = 1; $x <= (8 - $days_in_this_week); $x++):$calendar.= '<td class="calendar-day-np"> </td>';endfor;endif; /* final row */$calendar.= '</tr>'; /* end the table */$calendar.= '</table>'; /** DEBUG **/$calendar = str_replace('</td>','</td>'."\n",$calendar);$calendar = str_replace('</tr>','</tr>'."\n",$calendar); /* all done, return result */return $calendar;} function random_number() {srand(time());return (rand() % 7);} /* date settings */$month = (int) ($_GET['month'] ? $_GET['month'] : date('m'));$year = (int) ($_GET['year'] ? $_GET['year'] : date('Y')); /* select month control */$select_month_control = '<select name="month" id="month">';for($x = 1; $x <= 12; $x++) {$select_month_control.= '<option value="'.$x.'"'.($x != $month ? '' : ' selected="selected"').'>'.date('F',mktime(0,0,0,$x,1,$year)).'</option>';}$select_month_control.= '</select>'; /* select year control */$year_range = 7;$select_year_control = '<select name="year" id="year">';for($x = ($year-floor($year_range/2)); $x <= ($year+floor($year_range/2)); $x++) {$select_year_control.= '<option value="'.$x.'"'.($x != $year ? '' : ' selected="selected"').'>'.$x.'</option>';}$select_year_control.= '</select>'; /* "next month" control */$next_month_link = '<a href="index.php?month='.($month != 12 ? $month + 1 : 1).'&year='.($month != 12 ? $year : $year + 1).'" class="control">Next Month >></a>'; /* "previous month" control */$previous_month_link = '<a href="index.php?month='.($month != 1 ? $month - 1 : 12).'&year='.($month != 1 ? $year : $year - 1).'" class="control"><< Previous Month</a>'; /* bringing the controls together */$controls = '<form method="get">'.$select_month_control.$select_year_control.' <input type="submit" name="submit" value="Go" /> '.$previous_month_link.' '.$next_month_link.' </form>'; -
I am making a php calendar but struggling to get the query to work. The php calendar is made through a function with 3 variables fed into it. you can find the full calendar http://davidwalsh.name/php-event-calendar Anyway back to my variables. 3 of them.... $month, $year, $events Which are gotten as so.... /* date settings */$month = (int) ($_GET['month'] ? $_GET['month'] : date('m'));$year = (int) ($_GET['year'] ? $_GET['year'] : date('Y')); /* get all events for the given month */$events = array();mysql_select_db($database_dbconnect, $dbconnect);$query = "SELECT title,idcalendar, DATE_FORMAT(event_date,'%Y-%m-%D') AS event_date FROM calendar WHERE event_date LIKE '$year-$month%'";$result = mysql_query($query, $dbconnect) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) {$events[$row['event_date']][] = $row;} Now I have my 3 vars I feed them into my function with the following line <?php echo draw_calendar($month,$year,$events); ?> Now within my function there is the following line to print out the event on any given day /* list the events */if(isset($events[$event_day])) {foreach($events[$event_day] as $event) {$calendar.= '<div class="event">'.$event['title'].'</div>'; }}else {$calendar.= str_repeat('<p> </p>',2);} As you can see if it finds an event it will show it and if it cant it will show 2 empty paragraph tags. I have an event in my database and under the field titled event_date and the event is for 2013-07-16 00:00:00 which is obviously today. If I use MySQL to run the query it pulls back my event quite happy. As soon as I run it in the webpage I get my empty paragraph tags back. Please help
-
Ok I have solved it. So when the second anchor is clicked the page does not refresh it just moves. Too force a refresh ive put another var in the url so www.example.com#pyro became www.example.com?string=1#pyro this made the page refresh
-
I have a page with 2 divs that can be hidden. Now when I load the page the URL looks as follows www.example.com/wedding.php#pyromusicals or it could be www.example.com/wedding.php#just-fireworks now im trying to hide a different div depending on the anchor value and if there is no anchor then hide them both. Here is my code so far $(document).ready(function() { // Get # parameter var param = document.URL.split('#')[1]; if (param == 'pyromusicals') { $(".hidden-div2").hide(); } else if (param == 'purely-fireworks') { $(".hidden-div1").hide(); } }); The problem is that on page load neither works but if you manually hit refresh then the jquery starts working. The links on the page are just html links <li><a href="/wedding-fireworks.php#pyromusicals" title="View information about pyromusical displays for weddings">Pyromusicals</a></li> <li><a href='/wedding-fireworks.php#purely-fireworks' title="View information about wedding fireworks"><span>Purely Fireworks</span></a></li> Any ideas. I am completely new to java and jquery so I'd have no idea where to begin trouble shooting this.
-
Thanks guys that solved it. Sort of. It ruins my record set paging as paging thinks theres still 700 records when theres only 12 unique but its fine. Here is my new code from barand SELECT Calls.Call_Ref, Calls.Link_to_Contract_Header, Calls.Order_No, Calls.Date_Received, Calls.Scheduled_Date_Time, Clients.Co_Name, Clients.Post_Code, LU_Call_Types.Call_Type_Description, LU_Call_Types.Type_Band, LU_Call_Status.Call_Status_Description, LU_Company_Types.Company_Type_DescriptionFROM { oj (((Siclops_Dispense.dbo.Calls Calls INNER JOIN Siclops_Dispense.dbo.LU_Call_Types LU_Call_Types ON Calls.Call_Type = LU_Call_Types.Call_Type_Code) INNER JOIN Siclops_Dispense.dbo.LU_Call_Status LU_Call_Status ON Calls.Last_Event_Status = LU_Call_Status.Call_Status_Code) INNER JOIN Siclops_Dispense.dbo.Clients Clients ON Calls.Link_to_Client = Clients.Client_Ref) LEFT OUTER JOIN Siclops_Dispense.dbo.LU_Company_Types LU_Company_Types ON Clients.Company_Type = LU_Company_Types.Company_Type_Code} WHERE Calls.Link_to_Contract_Header = '".$row_rs_member['companyident']."' AND (LU_Call_Types.Type_Band = 'Project' OR LU_Call_Types.Type_Band = 'Project Complete' OR LU_Call_Types.Type_Band = 'Project Invoiced') AND (LU_Call_Status.Call_Status_Description = 'Reported Done' OR LU_Call_Status.Call_Status_Description = 'PTF Rep Done' OR LU_Call_Status.Call_Status_Description = 'Proforma Sent' OR LU_Call_Status.Call_Status_Description = 'Paperwork Recvd' OR LU_Call_Status.Call_Status_Description = 'In Query' OR LU_Call_Status.Call_Status_Description = 'Cryo PW Sent' OR LU_Call_Status.Call_Status_Description = 'Complete' OR LU_Call_Status.Call_Status_Description = 'Awaiting P/work' OR LU_Call_Status.Call_Status_Description = 'Awaiting Invoic' OR LU_Call_Status.Call_Status_Description = 'Await TB Return' OR LU_Call_Status.Call_Status_Description = 'ApplicationSent') ORDER BY LU_Call_Types.Call_Type_Description ASC, Calls.Scheduled_Date_Time DESC Then in the if statement you just check if field is unique.
-
thanks Barand Ill give that a try
-
Yes thats exactly what I want. The field was named poorly previously and is actually names of pubs. The table pulls back each time an engineer went to a pub. I only want to show each pub once and when you click it you then get all the other calls. So on the page im only echoing "Call_Status_Description" but the othe fields need to be there for the query to work properly.
-
Yes I still want to show those. I have just tried this but it also fails SELECT DISTINCT ON (LU_Call_Status.Call_Status_Description) , Calls.Call_Ref, Calls.Link_to_Contract_Header, Calls.Order_No, Calls.Date_Received, Calls.Scheduled_Date_Time, Clients.Co_Name, Clients.Post_Code, LU_Call_Types.Type_Band, LU_Call_Status.Call_Status_Description, LU_Company_Types.Company_Type_DescriptionFROM { oj (((Siclops_Dispense.dbo.Calls Calls INNER JOIN Siclops_Dispense.dbo.LU_Call_Types LU_Call_Types ON Calls.Call_Type = LU_Call_Types.Call_Type_Code) INNER JOIN Siclops_Dispense.dbo.LU_Call_Status LU_Call_Status ON Calls.Last_Event_Status = LU_Call_Status.Call_Status_Code) INNER JOIN Siclops_Dispense.dbo.Clients Clients ON Calls.Link_to_Client = Clients.Client_Ref) LEFT OUTER JOIN Siclops_Dispense.dbo.LU_Company_Types LU_Company_Types ON Clients.Company_Type = LU_Company_Types.Company_Type_Code} WHERE Calls.Link_to_Contract_Header = '".$row_rs_member['companyident']."' AND (LU_Call_Types.Type_Band = 'Project' OR LU_Call_Types.Type_Band = 'Project Complete' OR LU_Call_Types.Type_Band = 'Project Invoiced') AND (LU_Call_Status.Call_Status_Description = 'Reported Done' OR LU_Call_Status.Call_Status_Description = 'PTF Rep Done' OR LU_Call_Status.Call_Status_Description = 'Proforma Sent' OR LU_Call_Status.Call_Status_Description = 'Paperwork Recvd' OR LU_Call_Status.Call_Status_Description = 'In Query' OR LU_Call_Status.Call_Status_Description = 'Cryo PW Sent' OR LU_Call_Status.Call_Status_Description = 'Complete' OR LU_Call_Status.Call_Status_Description = 'Awaiting P/work' OR LU_Call_Status.Call_Status_Description = 'Awaiting Invoic' OR LU_Call_Status.Call_Status_Description = 'Await TB Return' OR LU_Call_Status.Call_Status_Description = 'ApplicationSent')
-
Hi Barand the call status description looks as follows call1 call1 call1 call1 call2 call2 call3 call4 call4 I just want call1 call2 call3 call4 I thought using group by would sort this? I have also tried DISTINCT on this field but that does not work either