Jump to content

ndjustin20

Members
  • Posts

    57
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

ndjustin20's Achievements

Member

Member (2/5)

0

Reputation

  1. Thank you very much for your replay. In the past I've always used simple queries to achieve what I needed. This one was by far the most complex and using JOIN makes things soooooooo MUCH SIMPLER!!!!! I'm going to definitely go in that direction from now on as it makes life so much easier. Thanks again for the help!!!
  2. I am having an issue with iterating through rows, updating a field, then sending an email depending on the date. I can get the first row to send an email too but I can't figure out why I cannot get the other rows to send an email to. I can show that there are three rows returned yet I cannot send three emails. The code is as follows and thank you in advance for your help. <?php for($numOfRows = 1; $numOfRows > 0;){ $sql = "SELECT * FROM service WHERE boosterDate BETWEEN CURDATE() AND CURDATE() + INTERVAL 30 DAY"; if(!$result = $con->query($sql)){ die('There was an error running the query [' . $con->error . ']'); } $numOfRows = $result->num_rows; //%result->store_result(); $numOfRows = var_dump($numOfRows); //echo $numOfRows; //if($numOfRows > 0){ //var_dump($numOfRows); while($row = $result->fetch_array()){ //Get all the rows and store them in an array $firstQueryRows[] = $row; } foreach($firstQueryRows as $row){ //do a new query with $row $serviceID = $row['serviceID']; $patientID = $row['patientID']; $serviceName = $row['serviceName']; $price = $row['price']; $quantity = $row['quantity']; $boosterDate = $row['boosterDate']; $totalPrice = $row['totalPrice']; $rabiesTagNumber = $row['rabiesTagNumber']; $microChipNumber = $row['microChipNumber']; $rabiesDose = $row['rabiesDose']; $rabiesVacType = $row['rabiesVacType']; $rabiesVacExpDate = $row['rabiesVacExpDate']; $rabiesSerialNumber = $row['rabiesSerialNumber']; $rabiesManufacturer = $row['rabiesManufacturer']; $rabiesVacDate = $row['rabiesVacDate']; $rabiesVacDueBy = $row['rabiesVacDueBy']; $licenseNumber = $row['licenseNumber']; $isThisARabiesCert = $row['isThisARabiesCert']; $vacDate = $row['vacDate']; $email30 = $row['email30']; $email60 = $row['email60']; $email90 = $row['email90']; //echo $serviceID . " "; $sql = "UPDATE service SET email30 = 30 WHERE serviceID = $serviceID"; if(!$result = $con->query($sql)){ die('There was an error running the query [' . $con->error . ']'); } }//End Foreach //echo $patientID; $sql = "SELECT * FROM service WHERE email30 = 30"; if(!$result = $con->query($sql)){ die('There was an error running the query [' . $con->error . ']'); } while($row = $result->fetch_array()){ //Get all the rows and store them in an array $firstQueryRows[] = $row; $patientID = $row['patientID']; //echo $patientID; } foreach($firstQueryRows as $row){ $sql = "SELECT * FROM patientInformation WHERE patientID = $patientID"; if(!$result = $con->query($sql)){ die('There was an error running the query [' . $con->error . ']'); } } while($row = $result->fetch_array()){ $firstQueryRows[] = $row; $clientID = $row['clientID']; $maleFemale = $row['maleFemale']; $species = $row['species']; $ageYears = $row['ageYears']; $ageMonths = $row['ageMonths']; $weight = $row['weight']; $dogBreed = $row['dogBreed']; $name = $row['name']; $catBreed = $row['catBreed']; $colors = $row['colors']; $illnessLast30Days = $row['illnessLast30Days']; $explainIllness = $row['explainIllness']; //echo $clientID; } foreach($firstQueryRows as $row){ $sql = "SELECT * FROM clientInformation WHERE clientID = $clientID"; if(!$result = $con->query($sql)){ die('There was an error running the query [' . $con->error . ']'); } } while($row = $result->fetch_array()){ $firstName = $row['firstName']; $lastName = $row['lastName']; $address = $row['address']; $city = $row['city']; $zip = $row['zip']; $phone = $row['phone']; $cell = $row['cell']; $state = $row['state']; $email = $row['email']; } $to = $email; $subject = "Just a friendly reminder from the Shot Spot"; $message = "Greetings " . $firstName . " " . $lastName . "\r\n" . "\r\n" . "\r\n" . "Thank you for choosing the Shot Spot for all of your animals healthcare needs. This is a friendly reminder that " . $name . " is ready for their booster on " . $boosterDate . "\r\n" . "\r\n" . "\r\n" . "Thank you for choosing the Shot Spot"; $headers = 'From: info@txshotspot.com'; mail($to, $subject, $message, $headers); }//end for loop ?>
  3. Barand thank you so much for your help. I shouldn't need a where clause though as the query should only run if the date is less than $date30 which is todays date plus 30 days. The problem I am having is the code is running regardless of true or false. I have output the boolean using var_dump to show that I am getting true and false back yet the if statement continues to run regardless. Is there maybe something buggy with it? I really LOVE your solution. So much easier!!! I was hoping to use the new DateTime object but I think I'll resign to the fact that it's just not working right at this point. Lets say I don't know a whole bunch of sql :-) except the basics. Do you have a good online tutorial that may give some good examples that you have maybe used in the past to brush up on things like between and curdate ect? I found this http://dev.mysql.com/doc/refman/5.6/en/func-op-summary-ref.html and that should do the trick for more information on sql queries.
  4. I was trying to do exactly that. I didn't want to store the 30, 60, or 90 days but I'm not able to get the DateTime object to work properly so i figured maybe just store the interval either within 30, 60, or 90 days then query that field and respond accordingly. Really what I am trying to do is use the DateTime object as I'm not very familiar with oop but it doesn't seem to be working as described in the manual. Could you have a look at my code and see if you can see something I am doing wrong? I am using php 5.4.12 and mysql 5.6.12 both loaded from a WAMP stack on a windows 7 64 bit machine.
  5. Barand I actually laughed out loud when I saw your post...nice work. From the php.net site http://ca3.php.net/manual/en/datetime.diff.php you can do this. $date1 = new DateTime($date); $date2 = new DateTime($date); Then from that point you can use a comparison operator for the two var's like <, >, or ==. For some reason this isn't working in my code. No matter true or false my field boosterWithinDays alwasy updates to 30. I have no idea why the query runs when it's false. Any help is much appreciated. Here is my code currently: <?php //date_default_timezone_set('America/Chicago'); $todaysDate = new DateTime('now'); $formattedDate = $todaysDate->format('Y-m-d'); $date = new DateTime ('now'); $date90 = $date->add(new DateInterval('P90D')); $date90 = $date->format('Y-m-d'); $date = new DateTime ('now'); $date60 = $date->add(new DateInterval('P60D')); $date60 = $date->format('Y-m-d'); $date = new DateTime ('now'); $date30 = $date->add(new DateInterval('P30D')); $date30 = $date->format('Y-m-d'); //echo $date90; //echo "<br />"; //echo $formattedDate; $sql = "SELECT * FROM service;"; if(!$result = $con->query($sql)){ die('There was an error running the query [' . $con->error . ']'); } while($row = $result->fetch_array()){ //Get all the rows and store them in an array $firstQueryRows[] = $row; } foreach($firstQueryRows as $row){ //do a new query with $row $patientID = $row['patientID']; $serviceID = $row['serviceID']; //$boosterDate = date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $row['boosterDate']))); //$date30 = date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $date30))); //$date60 = date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $date60))); //$date90 = date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $date90))); $boosterDate = new DateTime($row['boosterDate']); //$boosterDate->format("Y-m-d"); //$interval = $boosterDate->diff($date30); $boosterDate = $boosterDate->format("Y-m-d"); var_dump($boosterDate > $date30); echo "<br /><br />"; print "This is the booster date" . " " . ($boosterDate) . " "; echo "<br /><br />"; print "This is todays date plus 30 days" . " " . ($date30) . " "; if($boosterDate < $date30){ //echo "The date is less than 30" . " " . $row['serviceID'] . "<br /><br />"; //echo $date30 . "<br /><br />"; //echo $boosterDate; echo "this is being shown because boosterDate object is less than date30 object"; $sql = "UPDATE service SET boosterWithinDays = 30;"; if(!$result = $con->query($sql)){ die('There was an error running the query [' . $con->error . ']'); } }else{ NULL; } } //$date = $row['boosterDate']; //$id = $row['patientID']; //echo $date . " " . $id . "<br /><br />"; //echo date_default_timezone_get(); ?>
  6. I have been trying unsuccessfully to compare two dates using an if statement to then run another query and update a mysql database. I'm not sure where I am going wrong. If I use procedural and use date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $date30))); Then I get an update of every field in the column boosterWithinDays. If I try and use DateTime object $boosterDate = new DateTime($row['boosterDate']); $boosterDate->format("Y-m-d"); Then I get no update at all. I've set some boosterDates to more than 30 days and some to less and nothing seems to work. Here is the complete code: <?php //date_default_timezone_set('America/Chicago'); $todaysDate = new DateTime('now'); $formattedDate = $todaysDate->format('Y-m-d'); $date = new DateTime ('now'); $date90 = $date->add(new DateInterval('P90D')); $date90 = $date->format('Y-m-d'); $date = new DateTime ('now'); $date60 = $date->add(new DateInterval('P60D')); $date60 = $date->format('Y-m-d'); $date = new DateTime ('now'); $date30 = $date->add(new DateInterval('P30D')); //$date30 = $date->format('Y-m-d'); //echo $date90; //echo "<br />"; //echo $formattedDate; $sql = "SELECT * FROM service;"; if(!$result = $con->query($sql)){ die('There was an error running the query [' . $con->error . ']'); } while($row = $result->fetch_array()){ //Get all the rows and store them in an array $firstQueryRows[] = $row; } foreach($firstQueryRows as $row){ //do a new query with $row $patientID = $row['patientID']; $serviceID = $row['serviceID']; //$boosterDate = date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $row['boosterDate']))); //$date30 = date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $date30))); //$date60 = date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $date60))); //$date90 = date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $date90))); $boosterDate = new DateTime($row['boosterDate']); //$boosterDate->format("Y-m-d"); if($boosterDate < $date30){ //echo "The date is less than 30" . " " . $row['serviceID'] . "<br /><br />"; //echo $date30 . "<br /><br />"; //echo $boosterDate; $sql = "UPDATE service SET boosterWithinDays = 30;"; if(!$result = $con->query($sql)){ die('There was an error running the query [' . $con->error . ']'); } } } //$date = $row['boosterDate']; //$id = $row['patientID']; //echo $date . " " . $id . "<br /><br />"; //echo date_default_timezone_get(); ?>
  7. Thank you for the advice....I never even thought about the MySQL_real_escape_string being the issue. I'll turn on error reporting as I had forgot to when I started this little project. Thank you again as this was the problem :happy-04:
  8. Hello, I am not able to get the following code to insert. Any help is much appreciated. This is my first whack at MySqli and there are no errors being thrown. The fields in the DB are varchar and the variables do have values. I've attached the file I am working on. In the php file it's lines 22 through 48 that I am trying to resolve currently. if(!empty($firstName) && !empty($lastName) && !empty($cell)){ $sql = "SELECT * FROM clientInformation WHERE firstName = '$firstName' AND lastName = '$lastName' AND cell = '$cell' LIMIT 1;"; if(!$result = $con->query($sql)){ die('There was an error running the query [' . $con->error . ']'); }else{ $numRows = $result->num_rows; } if($numRows > 0){ $newResult = $result->fetch_assoc(); }else{ $sql = "INSERT INTO clientInformation (firstName, lastName, address, city, zip, phone, cell, state, email) VALUES ('$firstName', '$lastName', '$address', '$city', '$zip', '$phone', '$cell', '$state', '$email');"; if(!$result = $con->query($sql)){ die('There was an error running the query [' . $con->error . ']'); } } } catchPDF.php
  9. Ok so you fixed it using '.$property['propertyName'].' so each time I want to use a key=>value pairing inside a function I should us that format I would assume as that did the trick right away :) :)
  10. The I was thinking would bold that row so you knew which one was row 10 sorry any other suggestions to get it going?
  11. Ok so for some reason I am only able to get the first row returned when i used echo'<pre>';print_r($propertyName);echo'</pre>'; to check to see what is actually being pulled.
  12. The following code gave me the following error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in E:\wamp\www\leaseCMS\includes\functions.php on line 10 Line 10 is marked in bold below <?php function getProperties(){ $sql = "SELECT propertyName FROM properties;"; $result = mysql_query($sql); while($property = mysql_fetch_array($result)){ [b]echo "<td width=\"157\" height=\"24\" valign=\"middle\"><div align=\"left\"><input type=\"checkbox\" [/b] name=\"$property['propertyName']\" \"id=\"$property['propertyName']\" />$property['propertyName']</div></td>"; } } ?>
  13. Hello, New to PHP and trying to loop through rows to and get the name of the "property" in this case. I have tried foreach and while and neither seem to want to return all rows by calling the function. Does it have something to do with echo'ing the table structure or can I not return an array out of a function like this? I commented out the while loop as that wasn't working and put in a foreach loop though that didn't return all the data either. Any help is greatly appreciated <?php function getProperties(){ $sql = "SELECT propertyName FROM properties;"; $result = mysql_query($sql); //$count = mysql_num_rows($result); $property = mysql_fetch_array($result); foreach($property as $propertyName){ echo "<td width=\"157\" height=\"24\" valign=\"middle\"><div align=\"left\"><input type=\"checkbox\" name=\"$propertyName\" \"id=\"$propertyName\" />$propertyName</div></td>"; } /* for($i=0;$i>=$count;$i++){ while($property = mysql_fetch_array($result)){ $propertyName = $property['propertyName']; echo "<td width=\"157\" height=\"24\" valign=\"middle\"><div align=\"left\"><input type=\"checkbox\" name=\"$propertyName\" \"id=\"$propertyName\" />$propertyName</div></td>"; } } */ } ?>
  14. OMG!!!! ok so i was looking in the wrong script. I wasn't looking in the functions file on line 64 I was looking in the content.php file. Man I spent a long time trying to figure that out too I'm brand new to php/mysql and still going through a course on lynda.com. I really appreciate the help you guys gave me. I have another issue also. In the same script I can't make the subject name or the list item I select bold. Inside the script you'll notice i use a selected class to make whatever is selected use that style from the css file. I highlighted the information in the script below where it should be working though doesn't. <?php require_once("includes/connection.php"); ?> <?php require_once("includes/functions.php"); ?> <?php if(isset($_GET['subj'])){ $sel_subj = get_subject_by_id($_GET['subj']); $sel_page = NULL; }elseif(isset($_GET['page'])){ $sel_subj = NULL; $sel_page = get_page_by_id($_GET['page']); }else{ $sel_subj = NULL; $sel_page = NULL; } ?> <?php include("includes/header.php"); ?> <table id="structure"> <tr> <td id="navigation"> <ul class="subjects"> <?php $subject_set = get_all_subjects(); while($subject = mysql_fetch_array($subject_set)){ echo "<li"; if($subject["id"] == $sel_subj){ echo " class=\"selected\"";} echo "><a href=\"content.php?subj=" . urlencode($subject["id"]) . "\">{$subject["menu_name"]}</a></li>"; $page_set = get_pages_for_subject($subject["id"]); echo "<ul class=\"pages\">"; while($page = mysql_fetch_array($page_set)){ echo "<li><a href = \"content.php?page=" . urlencode($page['id']) . "\">{$page["menu_name"]}</a></li>"; } echo "</ul>"; } ?> </ul> </td> <td id="page"> <h2> <?php if(isset($sel_subj)){ echo $sel_subj['menu_name']; $sel_page = NULL; }elseif(isset($sel_page)){ echo $sel_page['menu_name']; $sel_page = NULL; }else{ echo "Welcome to Wdiget Corp"; } ?> </h2> </td> </tr> </table> </div> <?php require("includes/footer.php"); ?> Ok for some reason when I am typing inside this text field it jumps all over the place and i can't see what i am typing or what i am selecting so I'm not able to highlight the above code. Is there maybe a setting I need to change?
×
×
  • 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.