Search the Community
Showing results for tags 'sql'.
-
Hi all, im using the following sql query to select data from two tables where the most recent value for 'par' is > 6. SELECT patients.*, addobs.*, DATE_FORMAT(addobs.datetime, '%d/%m/%Y %H:%i:%s') as dti1 FROM addobs INNER JOIN patients ON addobs.MRN = patients.MRN WHERE addobs.datetime = (SELECT MAX(OLAST.datetime) FROM addobs AS OLAST WHERE OLAST.MRN = patients.MRN) AND addobs.par > 6 AND NOT addobs.hidden = 'yes' AND COALESCE(patients.ward,'') != 'dc' order by addobs.par ASC I would like to extend this query to also return as 'dti2', the datetime value that par > 6 LAST BECAME true. To clarify, if i have 5 values as follows: datetime par 06-18-2013 05:00:00 7 06-18-2013 04:00:00 8 06-18-2013 03:00:00 7 06-18-2013 02:00:00 2 06-18-2013 01:00:00 10 Then the datetime to be returned by my query as dti2 would be 06-18-2013 03:00:00, as this is the time that par>6 LAST BECAME true (and it has STAYED true since this time) This is to be distinguished from 06-18-2013 01:00:00 (which is when PAR>6 FIRST became true) and also to be distinguished from 06-18-2013 05:00:0 (which is when PAR>6 was LAST true) To give some context for further clarity: PAR is a measure of how unwell a patient is (larger numbers = more unwell). So i am trying to create a list of unwell patients. I want to return patients who have a PAR score of >6 (which is what my query currently achieves) and the amount of time they have had CONSECUTIVE par scores >6. From my limited knowledge of sql i would have thought that this could be done somehow with coalesce but im not sure exactly how. i have tried a few different things with no luck. I hope that all makes sense, i get a little confused even explaining it! Thanks for any help anyone can give in advance, Best, Matt
-
Hi All, So I am using this query to return some values.: $Find_Query2 = mysql_query("SELECT patients.*, addobs.* FROM addobs INNER JOIN patients ON addobs.MRN = patients.MRN WHERE addobs.datetime = (SELECT MAX(OLAST.datetime) FROM addobs AS OLAST WHERE OLAST.MRN = patients.MRN) AND addobs.par > 6 AND NOT addobs.hidden = 'yes' AND COALESCE(patients.ward,'') != 'dc' order by addobs.par ASC"); However, i one of the values ('datetime') is in the php datetime format yyyy-mm-dd hh:ii:ss. I want to return this in a different format dd/mm/yyyy hh:ii:ss. I tried using DATE_FORMAT as thats what i usually use to do this but i think my syntax is wrong as it is returning no results for 'datetime' in the way i am using it. I think im getting confused with my brackets somewhere. $Find_Query2 = mysql_query("SELECT patients.*, addobs.* FROM addobs INNER JOIN patients ON addobs.MRN = patients.MRN WHERE addobs.datetime = (SELECT DATE_FORMAT(MAX(OLAST.datetime), '%d/%m/%Y %H:%i:%s') FROM addobs AS OLAST WHERE OLAST.MRN = patients.MRN) AND addobs.par > 6 AND NOT addobs.hidden = 'yes' AND COALESCE(patients.ward,'') != 'dc' order by addobs.par ASC"); Can anybody tell me what im doing wrong here? Thanks in advance for any help, Matt
-
I'm designing a website for a wine wholesaler that needs to be able to update and display their product catalog in a certain specific way. The site in development is at www.metrocellars.com/new/ Let me first begin by outlining the database tables in use: location​ - a table of 6 records, the broader breakdown of geographic location (Brazil, California, etc.) These rows are used in the navigation menu, and each location has many "regions" referencing them. region​ - the more specific area of origin of each product (wine). Each "Region" references one of the 6 broader "Locations". product​ - The meat of the db, each Product record references a Producer/Winery (PID), a specific Region (RID - which also references a broader Location), and a specific Varietal (VID - Wine type/color). The left part of the image below shows part of the Product table. winery​ - This table holds records of each Winery/Producer referenced by PID in Product table. varietals - This table lists each type of wine, (Pinot, Merlot, etc) referenced by VID in the Product table. ​ On the right side of the above image, I included a visual of the relevant tables with FK relation lines. I haven't figured out which ON DELETE/UPDATE to use, as I got errors a couple times from child rows as I was assigning indexes/keys. I'm a little rusty with the SQL at the moment. Using this model, I need to be able to output the data to a wine list page, but I am having problems putting together the right queries and loops to list the data in the requested format. Here is an example of what the page content should look like when the 'region' California (LID = 2) is clicked on the nav menu. California Slo Down Wines http://www.slodownwines.com/ Broken Dreams Sexual Chocolate Central Coast Jackhammer http://jackhammerwine.com Pinot Noir Happy Canyon of Santa Barbara Cimarone Winery http://www.cimarone.com/ 3CV Bank 3CV Cilla’s Blend Le Clos Secret Gran Premio 3CV Estate Sauvignon Blanc Dragonette Cellars http://dragonettecellars.com/ GMS Rose Sauvignon Blanc Happy Canyon Vineyards http://happycanyonvineyard.com/ Ten Goal Merlot http://happycanyonvineyard.com/ Piocho Margerum Wine Company Sybarite Sauvignon Blanc Paso Robles Spaceman Vineyards Reserve Airspace Santa Barbara County Ampelos Cellars Syrache - Syrah & Grenache Margerum Wine Company http://www.margerumwinecompany.com/ Chenin Blanc M5 Riesling Uber Reserve Tercero http://tercerowines.com/ Grenache Grenache Blanc The Climb Santa Lucia Highlands Jackhammer http://jackhammerwine.com Chardonnay Santa Maria Tyler Winery Bien Nacido Pinot Noir Sta Rita Hills Ampelos Cellars http://ampeloscellars.com/ Pinot Noir Lambda Reserve Rho Reserve Viognier Dragonette Cellars http://dragonettecellars.com/ In the above list, each heading is a record of each "Region" with the same LID as California in the Location table. LID = 2, so I need to list each Region within California, and within each of those listings, list each Wine that has the same RID as that Region, but grouped by their respective Wineries. Basically, there are a few Wineries that have products (child rows I believe) with differing Regions of origin. So, there are products that can have the same PID, but different RID. You can get an idea of the format from the above example. My problem is, is how would I nest the loops and queries, and what joins would be necessary? Any and all help is a godsend. This has been quite a headache.
-
Hi all, So I have a page which uses mysql_query to select some variables from a table, and then produces an array in order to plot this information on a graph (data used for this depends on the unique id which is obtained by $_GET [‘mrn’]. This is all working fine. However, what I want to do now is include multiple copies of these graphs on a single page (graphs for different mrn’s). I tried to do this by including the files like this: <php $_GET[mrn] = "1"; include('graph.php'); ?> //some html <php $_GET[mrn] = "2"; include('graph.php'); ?> The problem with this method has been that although it works once, the second you include a second graph it stops working (presumably because I have tried to assign two different values to the same variable by effectively defining it twice?) My question is therefore, is there some way to include a file, get its output (draw its graph), and then stop including it, so that I can start including the next file (drawing next graph). My reading so far has led me to believe there probably isn’t a way? Am I correct about that? Does anyone have any ideas about how I might get this working using a different technique? Thanks in advance for any help, Matt
-
OK time for a very tricky mysql query (well, tricky for me anyway)… I have two tables: ‘patients’ and ‘obs’ Variables in patients: MRN, name, others1 Variables in obs: MRN, par (numeric value), time_recorded (datetime value), others2 Each time a new par value is added to obs: MRN, datetime, others 2 are recorded also (there are no null values). Multiple par values are therefore added over time for the same MRN number (as different rows in the table) I want to make a query that will select * from patients and * from obs using inner join using MRN only when the most recent par value for each unique MRN in obs was >6 For some context: MRNs are hospital numbers of patients and par is a score of how unwell they are. I am trying to produce a list of all the patients who’s most recent par value recorded in obs is >6 and print their details. I think I have managed to work out the inner join part: SELECT * from obs INNER JOIN patients ON obs.MRN = patient.MRN. What I just can’t figure out however is how to select only records where the most recent par for that particular MRN (ie patient) was > 6. I suppose one way to do this is to select all data from both tables using inner join MRN where obs.par >6, and then sort by mrn, the sort by datetime decending, and then only print the top returned result for each unique mrn, but im not really sure if that last part is possible? I hope all that makes sense? Any guidance or ideas anyone has about how to achieve this would be very helpful. Thanks all in advance for any replies, Matt
-
I have a SQL query where I am retrieving information to a table. I would like to only retrieve data from yesterday. I found some PHP code which I´ve formated to look exactly as the Date does in the database (2013-05-30) YYYY-mm-dd but I can´t get it to work. Does someone see what the error might be? <?php $date = new DateTime(); $date->add(DateInterval::createFromDateString('yesterday')); $conn = mysql_connect($dbhost, $dbuser, $dbpassword); if(! $conn ) { die('Could not connect: ' . mysql_error()); } mysql_select_db($dbname, $conn); echo '<STYLE TYPE="text/css">'; echo 'TD{font-family: Arial; font-size: 9pt;}'; echo '</STYLE>'; echo '<table border=1><thead><tr><th>Namn</th><th>Datum</th><th>SE Mail</th><th>SE Backoffice</th><th>DK Mail</th><th>DK Backoffice</th><th>NO Mail</th><th>NO Backoffice</th><th>FI Mail</th><th>FI Backoffice</th></tr></thead><tbody>'; $q = mysql_query("SELECT id, name, Date, SEMail, SEBackoffice, DKMail, DKBackoffice, NOMail, NOBackoffice, FIMail, FIBackoffice FROM maildata WHERE Date = $date->format('Y-m-d')"); while($f = mysql_fetch_array($q)) { echo '<tr><td>'.$f['name'].'</td><td>'.$f['Date'].'</td><td>'.$f['SEMail'].'</td><td>'.$f['SEBackoffice'].'</td><td>'.$f['DKMail'].'</td><td>'.$f['DKBackoffice'].'</td><td>'.$f['NOMail'].'</td><td>'.$f['NOBackoffice'].'</td><td>'.$f['FIMail'].'</td><td>'.$f['FIBackoffice'].'</td></tr>'; } echo '</tbody></table>'; mysql_close($conn); ?>
-
Hi all, So im quite new to sql queries and ive been reading how to use if else but i ccant figure out what im getting wrong in this one. Can anyone help? I want to use a datetime variable (which is an automatic timestamp 'datetime') but only if the user has not manually over-ridden this by entering their own datetime ('datetime_man). I have tried to use IF ELSE but im getting it wrong somewhere. Is the syntax right? $Find_Query1 = mysql_query("SELECT DATE_FORMAT(datetime,'%Y/%m/%d %H:%i:%s') AS datetime2 IF datetime_man='null' ELSE DATE_FORMAT(datetime_man,'%Y/%m/%d %H:%i:%s') AS datetime2, DATE_FORMAT(datetime,'%H:%i on %d/%m/%y') AS datetime3 IF datetime_man='null' ELSE DATE_FORMAT(datetime,'%H:%i on %d/%m/%y') AS datetime3, SBP, SBP_R, SBP_B, DBP, DBP_R, DBP_B, HR, HR_R, HR_B, RR, RR_R, RR_B, SpO2, SpO2_R, SpO2_B, O2flow, O2flow_R, O2flow_B, O2device, O2deviceOther, TEMP, TEMP_R, TEMP_B, AVPU FROM addobs WHERE mrn='$Search' AND DATE(datetime)='$Date' AND NOT hidden = 'yes' order by datetime2 ASC"); Thanks in advance for the help, Matt
-
Hello, I have a table called profiles. I have 3 colums, id,property,value The property has the items name,rating,birthday and the column value holds the value of each property. Now i want to order my results by the property rating and value Desc. I'm stuck here how i can do this ? Can anyone helps me with that ?
-
hi, im a newbie here. im seeking help for my problem. i am also new in php but have some knowledge in sql here's my problem. my boss wants to enable update the baking chamber table once the Estimated End Time reached only. meaning if the end time doesn't meet there will be a pop up on the page that operator cannot finished unless the estimated end time is reached. Please kindly help check my code and see screenshot attached for your reference. Thanks in advanced guys. if($_POST['submit']=="Bake Finished") { $time = strftime('%I:%M %p'); $hours = strftime('%H'); $min = strftime('%M'); $query=mysql_query("SELECT * FROM tbl_baking_chamber"); while($result=mysql_fetch_array($query)) { $recno=$result['RecNo']; if(isset($_POST[$recno])!=NULL) { mysql_query("UPDATE tbl_baking_chamber set tbl_baking_chamber.TotalTime='$TotalTime' where RecNo='".$recno."'"); mysql_query("UPDATE tbl_baking_chamber set tbl_baking_chamber.EndTime='$CurrentDate - $time' where RecNo='".$recno."'"); mysql_query("UPDATE tbl_baking_chamber set tbl_baking_chamber.Status='Finished' where RecNo='".$recno."'"); } } } if($_POST['submit']=="On Baking" || $_POST['submit']=="Bake Finished") { echo "<table class='tbl_Forbaking' cellspacing='1' border='0' width='680'>"; echo "<form action='Applications.php?type=BGABaking' method='post'>"; echo "<tr>"; //echo "<td class='text2' align='center' bgcolor='e3e6e5' height='40'>"."MODEL"."</td>"; echo "<td class='text2' align='center' bgcolor='e3e6e5'>"."SERIAL NUMBER"."</td>"; echo "<td class='text2' align='center' bgcolor='e3e6e5'>"."DEFINED <br> BAKE TIME"."</td>"; echo "<td class='text2' align='center' bgcolor='e3e6e5'>"."BATCH"."</td>"; echo "<td class='text2' align='center' bgcolor='e3e6e5'>"."LOCATION"."</td>"; echo "<td class='text2' align='center' bgcolor='e3e6e5'>"."START TIME"."</td>"; echo "<td class='text2' align='center' bgcolor='e3e6e5'>"."ESTIMATED <br> END TIME"."</td>"; echo "<td class='text2' align='center' bgcolor='e3e6e5'>"."<input type='submit' name='submit' value='Bake Finished' class='btn_Bake'>"."</td>"; $Query = mysql_query("SELECT * FROM tbl_baking_chamber where Status='On Baking'"); $count = mysql_num_rows($Query); $bgcolor="e3e6e5"; while($result = mysql_fetch_array($Query)) { if($bgcolor=='e3e6e5') { $bgcolor='e9ebea'; } else { $bgcolor='e3e6e5'; } echo "<tr>"; //echo "<td class='text1' align='center' bgcolor='$bgcolor'>".$result['Model']."</td>"; echo "<td class='text1' align='center' bgcolor='$bgcolor'>".$result['Serial']."</td>"; echo "<td class='text1' align='center' bgcolor='$bgcolor'>".$result['BakingHours']."</td>"; echo "<td class='text1' align='center' bgcolor='$bgcolor'>".$result['Batch']."</td>"; echo "<td class='text1' align='center' bgcolor='$bgcolor'>".$result['Chamber']."</td>"; echo "<td class='text1' align='center' bgcolor='$bgcolor'>".$result['StartTime']."</td>"; echo "<td class='text1' align='center' bgcolor='$bgcolor'>".$result['SEndTime']."</td>"; echo "<td class='text1' align='center' bgcolor='$bgcolor'>"."<input type='checkbox' value='$result[RecNo]' id='$result[RecNo]' name='$result[RecNo]'>"."</td>"; } echo "</form>"; echo "<tr>"; echo "<td>"."<br/>"; echo "<tr>"; echo "<td class='text4'>"."Total QTY.: $count"; echo "</table>"; }
-
Hi all, Ok so i have a bit of a tricky question. I am using a query to return just time from a datetime variable '_sfm_form_submision_time_' based on a few conditions as follows: if(isset($_GET['mrn'])) { $Search = $_GET['mrn']; $Find_Query1 = mysql_query("SELECT DATE_FORMAT(_sfm_form_submision_time_,'%H:%i') AS time, SBP FROM obs WHERE mrn='$Search' AND DATE(_sfm_form_submision_time_) = $chosendate() order by time ASC"); if(!$Find_Query1) { die(mysql_error()); } while($row = mysql_fetch_assoc($Find_Query1)) { echo '<br/> TIME: '.$row['time']; echo '<br/> SBP: '.$row['SBP']; echo '<br/>'; } $numCount = mysql_num_rows($Find_Query1); if ($numCount < 1) { print("no sbp/time found for that mrn on chosen date"); } However, i want to make a correction to the returned 'time', for daylight saving. In the UK daylight saving time (British Summer Time - BST) starts at 1am on the last Sunday in March (1am GMT), and finishes at 2am BST (ie 1am GMT) on the last Sunday in October. To make things more complex, my server saves datetimes as 4 hours behind GMT (which i cant change), so i also want to correct for this. So, if the date '_sfm_form_submision_time_' was recorded was in daylight saving time I want to add 3 hours to 'time', otherwise i want to add 4 hours to 'time'. Does anyone have any clue how to do this?? Any help anyone can give would be amazing! Thanks Matt
-
Dear all, Here is my scenario, I have a php page called index.php which is linked to dashboard. At the index page i will have 40-50 href's each with a id like dashboard.php/subcat=1 When a user click's particular href they will be forwarded to a page called dashboard and there i get this id. $subcat=$_REQUEST['subcat']; This dashboard is dynamic. In this page i have three different div's. Each with different query and result display. For example: My first div has a query and some 50 results. I want a display first four rows and remaining as a ajax pagination. similarly for the other two div's. There is no problem in using ajax pagination because it will be executed in different page and result will be display here. But the real problem is in each of my query i should pass the original subcat id which is what make the dashboard dynamic. Now, i need someway to pass this dynamic id for my external pagination for each query.
- 1 reply
-
- php
- pagination
-
(and 2 more)
Tagged with:
-
Hi all, Im new to php and im trying to do something a bit fiddly. I was wondering if anyone knows how... I have a table 'obs' with columns '_sfm_form_submision_time_' (date and time of submission of dataset in format YYYY-MM-DD HH:MM:SS), 'mrn', 'sbp' and a few other variables. I want to echo the sbp and TIME (in the format HH:MM from _sfm_form_submision_time_), as long as the DATE of submission was today (ie date in _sfm_form_submision_time_ is current date) for a given value for mrn (passed from previous page). Ie, if 3 data sets were entered today for mrn 001 then i want to display the times these were entered, and the sbp entered. I have this so far but it keeps telling me no results for mrns that have datasets enetered today, so somewhere the code must be wrong but i can't figure out where! Any help to find the problem would be amazing, thanks! <?php //STEP 1 Connect To Database $connect = mysql_connect("localhost","jasperss_par1","password"); if (!$connect) { die("MySQL could not connect!"); } $DB = mysql_select_db('jasperss_par1pats'); if(!$DB) { die("MySQL could not select Database!"); } //STEP 2 Check Valid Information if(isset($_GET['mrn'])) { //STEP 3 Declair Variables $Search = $_GET['mrn']; $Find_Query1 = mysql_query("SELECT DATE_FORMAT(_sfm_form_submision_time_,'%H:%i') TIMEONLY, SBP FROM obs WHERE mrn='$Search' AND _sfm_form_submision_time_=CURRENT_DATE()"); if(!$Find_Query1) { die(mysql_error()); } // STEP 4 Get results while($row = mysql_fetch_assoc($Find_Query1)) { echo '<br/> TIME: '.$row['_sfm_form_submision_time_']; echo '<br/> SBP: '.$row['SBP']; echo '<br/>'; } $numCount = mysql_num_rows($Find_Query1); // STEP 5 error message if no results if ($numCount < 1) { print("no sbp found for that mrn today"); } } ?> Thanks again! M
-
Hi All! So I’ve never really used SQL or PHP before, this is my first project. The idea is that nurses can search for patients in one table of a hospital database (patients table), and enter new records of their heart rate and blood pressure in a separate database table (observations table). I have managed to set up a database and the tables, and made a search form (searching using MRN, which is the patient's hospital number) which returns the patient details (name, dob, etc...) <?php //STEP 1 Connect To Database $connect = mysql_connect("localhost","jasperss_par1","k_dD6JsB"); if (!$connect) { die("MySQL could not connect!"); } $DB = mysql_select_db('jasperss_par1pats'); if(!$DB) { die("MySQL could not select Database!"); } //STEP 2 Check Valid Information if(isset($_GET['search'])) { //STEP 3 Declair Variables $Search = $_GET['search']; $Find_Query1 = mysql_query("SELECT * FROM patients WHERE mrn LIKE '%$Search%' "); if(!$Find_Query1) { die(mysql_error()); } while($row = mysql_fetch_assoc($Find_Query1)) { echo '<br/> MRN: '.$row['mrn']; echo '<br/> First Name: '.$row['fname']; echo '<br/> Last Name: '.$row['lname']; echo '<br/> Date of Birth: '.$row['dob']; echo '<br/> <a href="http://test.com/nextpage.php?mrn= ' .$row['mrn']>Click here</a>; } echo 'no patients were found'; } ?> There’s a few things I just can’t figure out how to do, although I should imagine it’s fairly straight forward when you know how! Any help or ideas anyone has would be very much appreciated. 1) The database will not record a number which starts with 0! (eg if I save a MRN number as 0001, it just saves as 1). I have tried various field types but can’t seem to do it. Does anyone know if there is a field type that will accept numbers starting with 0? 2) I only want my search to find the record if the exactly correct MRN number is entered. However, if I replace the ‘like’ condition with =, I get no returned results, even if I search for exactly the correct number, I can’t figure out why. 3) Because I only want to display one result, how do I echo ‘multiple results found’ if there is more than one record with the same mrn. 4) I want to link onto the next page, is there some way I can ‘post’ forward some of the data on this page (in order so i can autofill part of the form on the linked page with MRN and name, so the nurses can just fill in heart rate and blood pressure for that patient and submit it to observations table). You can see I have tried to do it by parsing the MRN in the link, but I must have the syntax wrong somewhere because its not working :-(. Thanks very much in advance for any help anyone can give me with this. Matt
-
Hi all, I have very limited knowledge of HTML and SQL but I’m trying to create a web user interface to allow updating of medical records. The idea is to use an HTML web form to search a SQL database for a record based on a patient number, and return and display the patients name and date of birth, along with another form that can be used to enter a new record for that patient which could then update the database by adding this record. (ie would need to create a new database table with date, time and whatever data was input into the form (say 5 more fields). Im guessing that to do this one would need to pass the data using PHP somehow, but im afraid I don’t have enough knowledge of how. Can anybody help advise me on how to do this? Thanks in advance for any replies, Matt
-
So I have a site with product categories, sub-cats, sub-sub, sub-sub-sub, and even sub-sub-sub-sub. So each category could be up to 5 levels deep. I want to be able to go to a category page and pull all the categories, and sub-cats this category belongs to, to create a sitemap. The database is structured like: category_id | category_name | parent_id | category_url 1 | Clothes | null | clothes 2 | Shirts | 1 | shirts 3 | Designer Shirts | 2 | designer-shirts So if I was to create a sitemap for Designer Shirts, I would want <a href="index.php">Home</a> >> <a href="clothes">Clothes</a> >> <a href="clothes/shirts">Shirts</a> >> <a href="clothes/shirts/designer-shirts">Design Shirts</a> So I want to do a mysql join that will find me all the categories that belong to the current page, and pull the urls (urls also have the parents urls contained too). And the query has to be useable for any hierachy of the category page.
-
What I'm doing is dynamically creating a table that automatically calculates the due date (based off of original, single DB entry) and what I need to do NOW is interrupt the loop at a certain point to inject a payment from another table. Here's the code that I have: while($startdate <= $today) { if ($startdate <= $pmt_date) { echo '<tr><td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. date("m.d.Y", $startdate) . '</center></td>'; echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$" . $english_format_number = number_format($row["supportamount"], 2, '.',',') . '</center></td>'; echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>$0.00</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. $intacc . '</center></td>'; echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. $appint . '</center></td>'; echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. $appprinc . '</center></td>'; echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. $bal . '</center></td></td>'; $startdate = strtotime('+1 month', $startdate); } else { echo '<tr><td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. date("m.d.Y", $pmt_date) . '</center></td>'; echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>$0.00</center></td>'; echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$".$english_format_number = number_format($row2["pmt_amt"], 2, '.',',') . '</center></td>'; echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. $intacc . '</center></td>'; echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. $appint . '</center></td>'; echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. $appprinc . '</center></td>'; echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. $bal . '</center></td></td>'; } } echo '</table>'; There's only one instance of what is needed being injected working, then it repeated continuously. What I need to do it have it only apply ONCE during that loop... possibly a foreach() statement? If so, how would I do that and have the $pmt_date array automatically generated and how would the table generate?
-
need to generate the correct format of this report, please advise if what i want is feasible or not. what i want is that at the image below i only want to show a distinct value under Severity, Category 2 and Category 3 columns, meaning there should just be one entry for Severity 3 and Severity 5 under Severity column and same goes for the Category 2 and Category 3 column entries here is the image: below is my SQL statement which generated the image above: $dates = $_POST['dates']; $sql="SELECT DISTINCT trouble_type_priority, category_1, category_2, status FROM tbl_main WHERE resolved_date = '$dates' ORDER BY trouble_type_priority,category_1,category_2"; here is the other part of the code: echo "<table width='150' border=0 align='center'> <tr> <th colspan='2'>Remaining Tickets:</th> </tr> <tr> <th width='72'>Wireless:</th> <th><input type='text' name='WirelessRemaining' id='WirelessRemaining' size='7' /></th> </tr> <tr> <th>Wireline:</th> <th><input type='text' name='WirelineRemaining' id='WirelineRemaining' size='7' /></th> </tr>"; echo "<table width='auto' cellpadding='1px' cellspacing='0px' border=1 align='center'> <tr> <th colspan='3' align='center'>Ticket Bucket</th> <th colspan='3' align='center'>Status</th> </tr> <tr> <th width='auto' align='center'>Severity</th> <th width='auto' align='center'>Category 2</th> <th width='auto' align='center'>Category 3</th> <th width='auto' align='center'>Resolved</th> <th width='auto' align='center'>Re-assigned</th> <th width='auto' align='center'>Closed</th> <th width='auto' align='center'>Grand Total</th> </tr>"; while($info = mysql_fetch_array($myData)) { echo "<form action='report.php' method='post'>"; echo"<tr>"; echo "<td align='center'>" . $info['trouble_type_priority'] . "<input type=hidden name=trouble_type_priority value=" . $info['trouble_type_priority'] . " size='1' maxlength='1' /> </td>"; echo "<td align='center'>" . $info['category_1'] . "<input type=hidden name=category_1 value=" . $info['category_1'] . "' /> </td>"; echo "<td align='center'>" . $info['category_2'] . "<input type=hidden name=category_2 value=" . $info['category_2'] . "' /> </td>"; echo "<td align='center'>" . $info['status'] . "<input type=hidden name=status value=" . $info['status'] . "' /> </td>"; echo "</tr>"; echo "</form>"; } } echo "</table>"; echo "<table width='auto' cellpadding='1px' cellspacing='0px' border=1 align='center'> <tr> <th colspan='3' align='center'>Total</th> <th> </th> <th> </th> <th> </th> </tr>"; echo "</table>";
-
I am moving my site and database to a new server. The configuration is nearly the same except the new server is 64bit. I can connect to the database remotely with the username and password that I have in my php code to connect. Here is my database connect code: <?php $serverName = 'Nick_C_Desktop\SQLEXPRESS'; $connectionInfo = array('Database'=>'CSLogs', 'UID'=>'cslogslogin', 'PWD'=>'123456'); $connection = sqlsrv_connect($serverName, $connectionInfo); ?> This code worked perfectly fine on my old server, but gives me this error: Fatal error: Call to undefined function sqlsrv_connect() in C:\wamp\www\cslogs\includes\db_connect.php on line 4 I have these two items in my php.ini file enabled: extension=php_pdo_sqlsrv_53_ts.dll extension=php_sqlsrv_53_ts.dll Which is what I had before. Using Wamp Server. PHP 5.3.13 all the same as before. What else am I missing that is not allowing this to connect to the SQL server. Thanks in advance!
-
need help in generating report from my db, i have a main page which i used to retrieved, delete data from db and i want to add a button that can generate a report. retrieve and delete button is already working, just need to make report generator work as well, because nothing is happening when i click on the Report Generator button, below is my main page code: <script type="text/javascript"> $(document).ready(function(){ $("#RetrieveList").on('click',function() { var xid = $('#XiD').val(); var date = $('#Date').val(); $.post('retrieve_test.php',{xid:xid, date:date}, function(data){ $("#results").html(data); }); return false; }); $("#DeletefromDB").click(function() { if (confirm("Are you sure you want to delete?")) var id = $('input[name=checkbox]:checked').map(function() { return $(this).val(); }).get(); $.post('delete_test.php',{id:id}, function(data){ $("#result").html(data); }); return false; }); }); $("#Report").click(function() { var date = $('#Date').val(); $.post('report.php',{date:date}, function(data){ $("#results").html(data); }); return false; }); </script> <form id="form2" name="form2" method="post" action=""> <table width="741" border="0" align="center"> <tr> <th colspan="9" align="center" style="font-size:14px" scope="col">Xid, Name:<span> <select name="XiD" id="XiD"> <option value="AAA">AAA</option> <option value="BBB">BBB</option> <option value="" selected="selected">Please Select...</option> </select> </span><span style="font-size:14px"> <label for="date">Date:</label> <input type="text" name="Date" id="Date" size="8"/> </span></th> </tr> <tr> <th colspan="9" scope="col"> </th> </tr> <tr> <th colspan="9" scope="col"> <div align="center"> <input name="action" type="button" id="RetrieveList" value="Retrieve List" /> <input name="action" type="button" id="DeletefromDB" value="Delete from DB" /> <input name="Clear" type="reset" id="Clear" value="Clear" onClick="window.location.reload()" /> <input name="action" type="button" id="Report" value="Report Generator" /> </div> <label for="Clear"></label> <div align="center"></div></th> </tr> </table> </form> <div id="results"> </div> while here is my report generator php code which doesn't seem to work: <?php require 'include/DB_Open.php'; $date = $_POST['date']; $sql="SELECT trouble_type_priority, category_1, category_2, status, COUNT (*) AS Total FROM tbl_main WHERE resolved_date = '$date' GROUP BY trouble_type_priority, category_1, category_2, status"; $myData = mysql_query($sql)or die(mysql_error()); echo "<table width='auto' cellpadding='1px' cellspacing='0px' border=1 align='center'> <tr> <th colspan='3' align='center'>Ticket Bucket</th> <th colspan='3' align='center'>Status</th> </tr> <tr> <th width='auto' align='center'>Severity</th> <th width='auto' align='center'>Category 2</th> <th width='auto' align='center'>Category 3</th> <th width='auto' align='center'>Resolved</th> <th width='auto' align='center'>Re-assigned</th> <th width='auto' align='center'>Grand Total</th> </tr>"; while($info = mysql_fetch_array($myData)) { echo"<tr>"; echo "<td align='center'>" . $info['trouble_type_priority'] . "</td>"; echo "<td align='center'>" . $info['category_1'] . "</td>"; echo "<td align='center'>" . $info['category_2'] . "</td>"; echo "<td align='center'>" . $info['status'] . "</td>"; echo "</tr>"; } echo "</table>"; include 'include/DB_Close.php'; ?> here is the image of how i want my report to be generated:
-
please help, inserting datas from my textfields combined with my textareas to db not working, please help on how to combine my VALUES properly. I cant seem to figure out how to combine the implode for my textareas and the other values from textfields. below is my PHP code: $Category2 = $_POST['Category2']; $Category3 = $_POST['Category3']; $Status = $_POST['Status']; $Date = $_POST['Date']; $Severity = $_POST['Severity']; $BanType = $_POST['BanType']; $XiD = $_POST['XiD']; $Ticket = $_POST['Ticket']; //Process the input textareas into arrays $PhoneNumber = array_map('mysql_real_escape_string', explode("\n", $_POST['PhoneNumber'])); $Createdate = array_map('mysql_real_escape_string', explode("\n", $_POST['Createdate'])); $RemedyTicketNo = array_map('mysql_real_escape_string', explode("\n", $_POST['PhoneNumber'])); //Determine the values with the least amoutn of elements $min_count = min($PhoneNumber, $Createdate, $RemedyTicketNo); //Create array to hold INSERT values $values = array(); //Create the INSERT values for($index=0; $index<$min_count; $index++) { $values[] = "('{$PhoneNumber[$index]}', '{$Createdate[$index]}', '{$RemedyTicketNo[$index]}')"; } if (isset($RemedyTicketNo)) { $sql="INSERT into tbl_main (ars_no, phone_number, category_1, category_2, status, create_date, resolved_date, trouble_type_priority, ban_type, employee_id_name) VALUES ('" . implode (', ', $values) ."', '".$Category2."', '".$Category3."', '".$Status."', '".$Date."', '".$Severity."', '".$BanType."', '".$XiD."')"; $result=mysql_query($sql); header("Location: smp_backend_test.php"); }
-
I have 2 tables that I want to compare and find the users that the username is not following and then display the username of the person not being followed. Table 1: users Table 2: follow In my head I see table 1 getting a list of all the usernames (column name is "username" from table 1) and then gets a list of all the usernames the user ($username) is not following (column name is "followname" from table 2). How do I make it compare the two lists and not display the usernames the user is following already? Table two is set up like so: (username) (User they follow) username followname derekshull dvdowns derekshull testuser testuser dvdowns Here's what I have so far. It's displaying users, but it's displaying users I follow and don't follow. Weird. $alluserslookup = mysql_query("SELECT * FROM users WHERE username!='$username'"); $thefollowerslookup = mysql_query("SELECT * FROM follow WHERE username='$username'"); while ($followersrow = mysql_fetch_assoc($thefollowerslookup)) { $afollower = $followersrow['followname']; while ($allusersrow = mysql_fetch_assoc($alluserslookup)) { $allusers = $allusersrow['username']; if ($afollower != $allusers) { echo "<a href='viewprofile.php?viewusername=$allusers'>$allusers</a><br>"; } } }
-
Hi all! I am new so don't hate if I write something in a bad way. Thanks. I have a "logical captcha" which is like a quiz. Here is my code. I don't know what is wrong with it <?php $database_db="general"; $user_db="root"; $password_db="somepass"; $host_db="localhost"; $link = mysqli_connect($host_db, $user_db, $password_db, $database_db); if (mysqli_connect_errno()) { die ("couldnot connect: ".mysqli_connect_error()); exit(); } $answer = $_POST['answer']; if (array_key_exists("answer", $_POST) AND array_key_exists("question", $_POST)) { $id = intval($_POST['question']); $sql="SELECT question, answer FROM captcha WHERE question='$id' AND answer='".mysqli_real_escape_string($link, $answer)."'"; $result = mysqli_query($link, $sql) or exit('$sql failed: '.mysqli_error($link)); $num_rows = mysqli_num_rows($result); if($num_rows > 0) { header("Location: success.php"); } else { header("Location: error.php"); } exit; } else { $query = "SELECT id, question FROM `captcha` ORDER BY RAND() LIMIT 1"; if ($result = mysqli_query($link, $query)) { if ($row = mysqli_fetch_assoc($result)) { $id = $row["id"]; $question = $row["question"]; } } } ?> <html> <body> <form method="post"> <?php echo $question; ?><br /> <input type="hidden" name="question" id="question" value="<?php echo $id; ?>" /> <input type="text" name="answer" id="answer" /><br /> <input type="submit" name="submit" value="submit" /><br /> </form> </body> </html> So the problem is that it always redirects to error.php, even if I enter the right answer
-
Hi, I'm in the middle of constructing my registration and login form and I keep getting this error when I try to process the login. Here's the error I'm getting: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'firstname' cannot be null Here's the PHP code: <?php class Users { public $firstname = null; public $lastname = null; public $username = null; public $email = null; public $password = null; public $salt = "Zo4rU5Z1YyKJAASY0PT6EUg7BBYdlEhPaNLuxAwU8lqu1ElzHv0Ri7EM6irpx5w"; public function __construct( $data = array() ) { if( isset( $data['username'] ) ) $this->username = stripslashes( strip_tags( $data['username'] ) ); if( isset( $data['password'] ) ) $this->password = stripslashes( strip_tags( $data['password'] ) ); } public function storeFormValues( $params ) { $this->__construct( $params ); } public function userLogin() { $success = false; try{ $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD ); $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $sql = "SELECT * FROM members WHERE username = :username AND password = :password LIMIT 1"; $stmt = $con->prepare( $sql ); $stmt->bindValue( "username", $this->username, PDO::PARAM_STR ); $stmt->bindValue( "password", hash("sha256", $this->password . $this->salt), PDO::PARAM_STR ); $stmt->execute(); $valid = $stmt->fetchColumn(); if( $valid ) { $success = true; } $con = null; return $success; }catch (PDOException $e) { echo $e->getMessage(); return $success; } } public function register() { $correct = false; try { $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD ); $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $sql = "INSERT INTO members(firstname, lastname, username, email, password) VALUES(:firstname, :lastname, :username, :email, :password)"; $stmt = $con->prepare( $sql ); $stmt->bindValue( "firstname", $this->firstname, PDO::PARAM_STR ); $stmt->bindValue( "lastname", $this->lastname, PDO::PARAM_STR ); $stmt->bindValue( "username", $this->username, PDO::PARAM_STR ); $stmt->bindValue( "email", $this->email, PDO::PARAM_STR ); $stmt->bindValue( "password", hash("sha256", $this->password . $this->salt), PDO::PARAM_STR ); $stmt->execute(); return "Registration Successful <br/> <a href='index.php'>Login Now</a>"; }catch( PDOException $e ) { return $e->getMessage(); } } } ?> My database layout is as follows Field Type Null Default Comments user_id int(11) No firstname varchar(50) No lastname varchar(50) No username varchar(50) No email varchar(50) No password var(250) No Indexes: Keyname Type Cardinality Field PRIMARY PRIMARY 0 user_id username UNIQUE 0 username email UNIQUE 0 email
-
Hello all, I'm having a bit of a problem with my code here. I'm trying to allow the user to enter a number (an office number) from a database, and based on that value, after submitting it, an html table will fill with the appropriate results (lastName, firstName, jobTitle). For whatever reason, though, I keep getting this error: "Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in... <website name> <line number>" It's very weird, because I'm doing this straight from notes / w3 and I'm still getting errors. I'm still new to this, so I'm sorry if I'm sounding completely inexperienced... well I am haha. Anyway, here's the code: <!DOCTYPE html > <html lang ="en"> <head> <title> Homepage </title> </head> <body bgcolor="gray"> <h1 align=middle> Welcome to the Site </h1> <?php DEFINE ('DB_USER', '*******); DEFINE ('DB_PASSWORD', '******'); DEFINE ('DB_HOST','*****'); DEFINE ('DB_NAME','******'); $dbc = @mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME) or die ('Could not connect to MySQL: '.mysqli_connect_error($dbc) ); mysqli_set_charset($dbc, 'utf8'); //$r = @mysqli_query($dbc, $q); ?> <form action ="Homepage.php" method="get"> Enter Office Code: <input type="text" name="oCode" id="OfficeCode" maxlength="15"> <input type="submit" name="formSubmit" value="Submit"> </form> <? $code = $_GET['oCode']; $result = mysqli_query($dbc, "select lastName, firstName, jobTitle from Employees where OfficeCode='$code'"); echo "<table border='1'>"; echo "<tr>"; echo "<th>LastName</th>"; echo "<th>FirstName</th>"; echo "<th>Job Title</th>"; echo "</tr>"; while ($row = mysqli_fetch_array($result)) //this is where I'm getting the error { echo "<tr>"; echo "<td>" . $row['lastName'] . "</td>"; echo "<td>" . $row['firstName']. "</td>"; echo "<td>" . $row['jobTitle'] . "</td>"; echo "</tr>"; } echo "</table>"; mysqli_close($dbc); ?> Any help would be great. Thank you!