PHP - Problem In Highlighting Display Data Using Select Statement With Css Class
Hi...
I have query in highlighting null data using this code: Code: [Select] <?php include 'config.php'; $currentEmpID = $_SESSION['empID']; if(!isset($_POST['Regsubmit_'])){ $DATE1 = $_GET['Regfirstinput']; $DATE2 = $_GET['Regsecondinput']; $sql = "SELECT DISTINCT IF(ISNULL(a.LOG_IN), 'rdc', '') AS LOGIN_CLASS, IF(ISNULL(a.LOG_OUT), 'rdc', '') AS LOGOUT_CLASS, a.EMP_ID, CONCAT(LASTNAME, ', ' , FIRSTNAME) AS FULLNAME, a.LOG_IN, a.LOG_OUT FROM $ATTENDANCE.attendance_build AS a JOIN $ADODB_DB.employment em ON (a.EMP_ID = em.EMP_NO AND em.STATUS IN ('Reg Operatives', 'Reg Staff')) WHERE LOG_IN BETWEEN '$DATE1' AND '$DATE2' OR ISNULL(LOG_IN) OR ISNULL(LOG_OUT)"; $DTR = $conn3->GetAll($sql); $smarty->assign('attendance', $DTR); } $smarty->display('header_att.tpl'); $smarty->display('RegAttendance.tpl'); $smarty->display('footer.tpl'); ?> and here is the tpl code: Code: [Select] {section name=att loop=$attendance} <tr> <td colspan="2">{$attendance[att].EMP_ID}</td> <td colspan="2">{$attendance[att].FULLNAME}</td> <td colspan="2" class="{$attendance[att].LOGIN_CLASS}">{$attendance[att].LOG_IN|date_format:"%d-%m-%Y %I:%M %p"}</td> <td colspan="2" class="{$attendance[att].LOGOUT_CLASS}">{$attendance[att].LOG_OUT|date_format:"%d-%m-%Y %I:%M %p"}</td> </tr> {sectionelse} <tr><td colspan="1">No DATA</td></tr> {/section} this code highlight the null value of login or logout or both. this is the css: Code: [Select] .rdc {background-color:#ff0000;} Now, I need to revised my query statement, because i have separate code for adding attendance if the employee has no attendance or no login or no logout. I just want to happen is if the employee is already add his attendance in NRS table or should I said if the LOG_IN in attendance table is equal to TIME_IN in NRS table the data will have a color yellow. For Example: I have this data in attendance table: EMP_ID = 012012 LOG_IN = NULL LOG_OUT = 2011-12-12 13:35:00 I will his attendance in NRS table to have his attendance: EMP_NO = 012012 TIME_IN = 2011-12-12 05:35:00 TIME_OUT = 2011-12-12 13:35:00 In my above query the LOG_IN has a background color of RED. I want to happen is if I add his attendance in NRS the EMP_NO, LOG_IN, LOGOUT will have a color to notice that it is already have in NRS. Because theirs a scenario that the employee has no login or no logout or both. Feel free to ask me if my explanation is not clear to you. Thank you in advance Similar Tutorials
In the same $-POST , i wanted to perform update and delete. With the updated and deleted database, I need to select the updated data from the database. However, it tells me: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in... .I am new to sql in php, is it true that i cannot perform sql in this way? Or is there any suggestion to perform select straight after deleting and updating? CANCEL BOOK RESERVATION if(isset($_POST['cancelres'])) { $query = "DELETE FROM reserved_books WHERE id='$resid';"; //delete reservation $query .="UPDATE reserved_books SET queue = queue - 1 WHERE bookid = '$bookid' AND queue > '$bookqueue';";//update queue number where reservation that queue behind/after/ the current reservation $query_run = mysqli_multi_query($connection, $query); if($query_run) { $_SESSION['success'] = "Reservation Cancelled"; } else { $_SESSION['status'] = " Reservation Not Cancelled"; } $query= "SELECT title FROM books WHERE id = '$bookid';"; //get book title from db $query_run = mysqli_query($connection,$query); if(mysqli_num_rows($query_run)>0) { foreach ($query_run as $row) { $title = $row['title']; } } $bookres = "SELECT * FROM reserved_books WHERE bookid = '$bookid' AND queue = 1"; $bookres_run = mysqli_query($connection,$bookres); foreach($bookres_run as $row) { $res_username = $row['username']; $res_id = $row['id']; } $query= "SELECT option_value FROM settings WHERE option_name = 'email_temp_rescollect'"; //get email template from db $query_run = mysqli_query($connection,$query); if(mysqli_num_rows($query_run)>0) { $row = mysqli_fetch_array($query_run); $rescollect_template = $row[0]; }}
Hi all, I am a php student and i am doing a project in php. I am doing the project of online attendance register. I am stuck with the part of reports. We need to select three different values from an HTML form and pick the selected rows and wants to display those rows in a table. I have done a code but it is not working. Please help me out of this issue. HTML Form: <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body><form action="reportpro.php" method="get" name="services"> <table width="447" border="0" align="center" > <tr style="text-align: center"> <td width="441"><table width="481" border="1"> <tr> <td width="216"><div align="center"> SECTION </div></td> <td width="102"><div align="center"> MONTH </div></td> <td width="141"><div align="center"> YEAR </div></td> </tr> <tr> <td><select name="section" id="select"> <option>SERVICES-A</option> <option>SERVICES-B</option> <option>SERVICES-C</option> </select></td> <td><select name="month" id="select"> <option>01</option> <option>02</option> <option>03</option> <option>04</option> <option>05</option> <option>06</option> <option>07</option> <option>08</option> <option>09</option> <option>10</option> <option>11</option> <option>12</option> </select></td> <td><select name="year" id="select"> <option>2014</option> <option>2015</option> <option>2016</option> <option>2017</option> <option>2018</option> <option>2019</option> <option>2020</option> </select></td> </tr> <tr> <td colspan="4"> <center><input name="submit" type="submit" id="submit" formaction="reportpro.php" formmethod="get" value="Search"></center></td> </tr> </table> <p> </p> <p> </p> <p> </p></td> </tr> </table> </form> </body> </html> PHP Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="" method="get"> <table border="1" align="center" > <tr> <td>BOOK NO</td> <td>Name</td> <td>Desigination</td> <td>Section</td> <td>Day</td> <td>Month</td> <td>Year</td> <td>Attendance</td> </tr> <?php $con=mysql_connect("localhost","root",""); mysql_select_db("niy",$con); $m=$_REQUEST['month']; $y=$_REQUEST['year']; $sec=$_REQUEST['section']; $sql="select month='$m', year='$y', sectn='$sec' from attendance "; echo $sql; $res=mysql_query($sql,$con); while($row=mysql_fetch_array($res)) { ?> <tr> <td><?php echo $row[1];?></td> <td><?php echo $row[2];?></td> <td><?php echo $row[3];?></td> <td><?php echo $row[4];?></td> <td><?php echo $row[5];?></td> <td><?php echo $m;?></td> <td><?php echo $y;?></td> <td><?php echo $row[8];?></td> </tr> <?php } ?> </table> </body> </html> I have got a set of data for a country for each week of the year, but want to display the data a quarter at a time, using a form which posts a value into LIMIT, which was OK for the 1st quarter, but for subsequent quarters I needed to use LIMIT in the form LIMIT start, rows.
I found by experiment that this had to be the last statement in the query.
when I added the start I got an error:
Parse error: syntax error, unexpected ',' in /homepages/43/d344817611/htdocs/Admin/Visitdata.php on line 10
Here is the SQL part of my code:
$Visit_data="SELECT WeekNo.WNo, WeekNo.WCom, Countries.Country, ctryvisits.CVisits FROM ctryvisits LEFT JOIN Countries ON ctryvisits.country=Countries.CID LEFT JOIN WeekNo ON ctryvisits.WNo=WeekNo.WNo WHERE Countries.Country = '".$_POST["Country"]."' ORDER BY ctryvisits.WNo LIMIT '".$_POST["QUARTER"]."'" - 13, '".$_POST["QUARTER"]."'";Is this the best way of doing what I require or is there an easier way of achieving what I want? Hi everybody i am beginnet with working with sql in php..so i confused.....i made one scripte and i am making the secound and now i am facing a problem....i hope u could help!! i have a dat=abse of my chatroom....this is the code i typed...please have a look at it! Code: [Select] $usern=$_SESSION['etchat_'.$this->_prefix.'username']; $con1 = mysql_connect("localhost","manosir_main","********"); if (!$con1) { die('Could not connect: ' . mysql_error()); } mysql_select_db("manosir_manoshos_main", $con1); $users= mysql_query(" select etchat_user_online_user_sex from db1_etchat_useronline where etchat_user_online_user_name = $usern "); in my database, i ahve a table called db1_etchat_useronline that keeps record of online users in chatroom. as u usee i qant to to get the user sex ( etchat_user_online_user_sex) of th current user!!! as u see i conected to database correctly but now i dont know how to echo the $users . before this i echo my sql results with mysql_fetch_array ..but now i cant.......i got nothing!!!! can someone help me!!!!! I had this working, but when I try and get fancy and use AJAX the data doesn't display. I think this is a PHP problem though. My code for the select form including AJAX code Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB"> <head> <title>AJAX Example</title> <link rel="stylesheet" type="text/css" href="Form.css" media="screen" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("tr:odd").addClass("odd"); }); </script> <script type="text/javascript"> function showPlayers(str) { var xmlhttp; if (str=="") { document.getElementById("DataDisplay").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); else {// code for IE6, IE5 } xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("DataDisplay").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","Query.php?category_id="+str,true); xmlhttp.send(); } </script> </head> <body> <h1">AJAX Example</h1> <?php #connect to MySQL $conn = @mysql_connect( "localhost","username","pw") or die( "You did not successfully connect to the DB!" ); #select the specified database $rs = @mysql_SELECT_DB ("MyDB", $conn ) or die ( "Error connecting to the database test!"); ?> <form name="sports" id="sports"> <legend>Select a Sport</legend> <select name="category_id" onChange="showPlayers(this.value)"> <option value="">Select a Sport:</option> <?php $sql = "SELECT category_id, sport FROM sports ". "ORDER BY sport"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) { echo "<option value=\"".$row['category_id']."\">".$row['sport']."</option>\n "; } ?> </select> </form> <br /> <div id="DataDisplay"></div> </body> </html> Query.php <?php #get the id $id=$_GET["category_id"]; #connect to MySQL $conn = @mysql_connect( "localhost","username","pw") or die( "Error connecting to MySQL" ); #select the specified database $rs = @mysql_SELECT_DB ("MyDB", $conn ) or die ( "Could not select that particular Database"); #$id="category_id"; #create the query $sql ="SELECT * FROM sports INNER JOIN players ON sports.category_id = players.category_id WHERE players.category_id = '".$id."'"; echo $sql; #execute the query $rs = mysql_query($sql,$conn); #start the table code echo "<table><tr><th>Category ID</th><th>Sport</th><th>First Name</th><th>Last Name</th></tr>"; #write the data while( $row = mysql_fetch_array( $rs) ) { echo ("<tr><td>"); echo ($row["category_id"] ); echo ("</td>"); echo ("<td>"); echo ($row["sport"]); echo ("</td>"); echo ("<td>"); echo ($row["first_name"]); echo ("</td>"); echo ("<td>"); echo ($row["last_name"]); echo ("</td></tr>"); } echo "</tr></table>"; mysql_close($conn); ?> I think the problem is either with this part in the AJAX Code: [Select] xmlhttp.open("GET","Query.php?category_id="+str,true); or most likely in my Query.php code when I wasn't using AJAX and using POST it worked fine, but adding the AJAX stuff and GET it doesn't work. When I echo out the SQL the result is Code: [Select] SELECT * FROM sports INNER JOIN players ON sports.category_id = players.category_id WHERE players.category_id = '' so the category_id is not being selected properly and that is the primary key/foreign key in the MySQL table which connects the JOIN. This is a continuation of a previous post. I am trying to get the names of countries that are in a database table. It's not working! All I get is a Submit button, but no data. This is what I understand from the code that Psycho suggested: I am unfamiliar with the function and the use of the FOREACH constuct. looking at the PHP manual there are two syntaxes. It appears that Psyhco has used the second form where the current element's key is assigned to $key variable for each itteration. foreach (array_expression as $key => $value The 2 variables he used are $id and $label I assume that the line: $optionsHTML = ''; is the array built from the expression: $optionsHTML .= "{$label}\n"; Because I was not familiar with the PDO method, but have used mysqli, I had to rewrite the data retrival part which I believe is OK. I guess that the line : $countryOptions = buildSelectOptions($countries); is used in conjunction with the function to build the array. The HTML part that Psycho wrote puts the variable into the Form format for a selection list. Why is the $optionsHTML also inclosed in the option tags? Have I got the HTML part correct or is it the data extraction part that is incorrect? Here is the code: <? include("AddStats_admin_connect.php"); //connect to database doDB(); //Function to build select options based on passed array function buildSelectOptions($options) { $optionsHTML = ''; foreach($options as $id => $label) { $optionsHTML .= "<option value='{$id}'>{$label}</option>\n"; } return $optionsHTML; } //Run query to get the ID and Name from the table //Then populate into an array $clist_sql = "SELECT CID, Country FROM Countries"; $clist_res= mysqli_query($mysqli, $clist_sql) or die(mysqli_error($mysqli)); if (mysqli_num_rows($clist_res) < 1) { //this Country not exist $display_block = "<p><em>You have selected an invalid Country.<br/> Please try again.</em></p>"; } $countries = array(); while($Ctry_info = mysqli_fetch_array($clist_res)) { $countries[$Ctry_info['CID'] = $Ctry_info['Country']]; } $countryOptions = buildSelectOptions($countries); ?> <!DOCTYPE html> <html lang="en"> <head> <title>Stats</title> <link rel="stylesheet" href="stylesheets/style.css" /> <!--[if IE]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> </head> <body> <? echo $countryOptions; ?> </br></br></br></br></br></br></br></br> <!Later in the HTML for the page <form action="Ctrystats.php" method="post"> <option name="country" value=<? echo $countryOptions;?>Country</option></br></br> <input type="submit" value="Submit Choice"> </form></p> </body> </html>I think I am nearly there so I would appreciate some help to finish this coding. Note: If you make your questions easy to read, then you have better chances of a quality answer. Use [ code ] ] tags. Hi.. I need to save data from a while loop and data from select option, Now I encountered that using my query I only save is the last part of my while loop and also the data that I choose in select option did not save. here is my code: Code: [Select] <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); $sr_date =date('Y-m-d H:i:s'); $sr_date = $_POST['sr_date']; $sr_number = $_POST['sr_number']; $Items = $_POST['Items']; $SubItems = $_POST['SubItems']; $ItemCode = $_POST['ItemCode']; $DemandedQty = $_POST['DemandedQty']; $UoM = $_POST['UoM']; $Class = $_POST['Class']; $Description = $_POST['Description']; $BINLocation = $_POST['BINLocation']; $RequestedBy = $_POST['RequestedBy']; $ApprovedBy = $_POST['ApprovedBy']; $ReceivedBy = $_POST['ReceivedBy']; $IssuedBy = $_POST['IssuedBy']; $sql = "INSERT INTO stock_requisition (sr_date, sr_number, Items, SubItems, ItemCode, DemandedQty, UoM, Class, Description, BINLocation, RequestedBy, ApprovedBy, ReceivedBy, IssuedBy) VALUES ('$sr_date', '$sr_number', '$Items', '$SubItems', '$ItemCode', '$DemandedQty', '$UoM', '$Class', '$Description', '$BINLocation', '$RequestedBy', '$ApprovedBy', '$ReceivedBy', '$IssuedBy') ON DUPLICATE KEY UPDATE sr_date = '$sr_date', sr_number = '$sr_number', Items = '$Items', SubItems = '$SubItems', ItemCode = '$ItemCode', DemandedQty = '$DemandedQty', UoM = '$UoM', Class = '$Class', Description = '$Description', BINLocation = '$BINLocation', RequestedBy = '$RequestedBy', ApprovedBy = '$ApprovedBy', ReceivedBy = '$ReceivedBy', IssuedBy = '$IssuedBy'"; $result = mysql_query($sql, $con); $sql = "SELECT sr_number FROM stock_requisition ORDER BY sr_date DESC LIMIT 1"; $result = mysql_query($sql, $con); if (!$result) { echo 'failed'; die(); } $total = mysql_num_rows($result); if ($total <= 0) { $currentSRNum = 1; } else { //------------------------------------------------------------------------------------------------------------------ // Stock Number iteration.... $row = mysql_fetch_assoc($result); $currentSRNum = (int)(substr($row['sr_number'],0,3)); $currentSRYear = (int)(substr($row['sr_number'],2,2)); $currentSRMonth = (int)(substr($row['sr_number'],0,2)); $currentSRNum = (int)(substr($row['sr_number'],6,4)); $currentYear = (int)(date('y')); $currentMonth = (int)(date('m')); $currentDay = (int)(date('d')); $currentSRYMD = substr($row['sr_number'], 0, 6); $currentYMD = date("ymd"); if ($currentYMD > $currentSRYMD) { $currentSRNum = 1; } else { $currentSRNum += 1; } } //------------------------------------------------------------------------------------------------------------------ $yearMonth = date('ymd'); $currentSR = $currentYMD . sprintf("%04d", $currentSRNum); ?> <html> <title>Stock Requisition</title> <head> <style type="text/css"> #ddcolortabs{ margin-left: 2px; padding: 0; width: 100%; background: transparent; voice-family: "\"}\""; voice-family: inherit; padding-left: 2px; } #ddcolortabs ul{ font: bold 12px Arial, Verdana, sans-serif; margin:0; padding:0; list-style:none; } #ddcolortabs li{ display:inline; margin:0 2px 0 0; padding:0; text-transform:uppercase; } #ddcolortabs a{ float:left; color: white; background: #8cb85c url(layout_image/color_tabs_left.gif) no-repeat left top; margin:2px 2px 0 0; padding:0px 0 1px 3px; text-decoration:none; letter-spacing: 1px; } #ddcolortabs a span{ float:right; display:block; /*background: transparent url(layout_image/color_tabs_right.gif) no-repeat right top;*/ padding:6px 9px 2px 6px; } #ddcolortabs a span{ float:none; } #ddcolortabs a:hover{ background-color: #678b3f; } #ddcolortabs a:hover span{ background-color: #678b3f ; } #ddcolortabs #current a, #ddcolortabs #current span{ /*currently selected tab*/ background-color: #678b3f; } </style> <style type="text/css"> #ddcolortabs1{ position: relative; top: 10px; margin-left: 2px; padding: 0; width: 100%; background: transparent; voice-family: "\"}\""; voice-family: inherit; padding-left: 2px; } #ddcolortabs1 ul{ font: bold 12px Arial, Verdana, sans-serif; margin:0; padding:0; list-style:none; } #ddcolortabs1 li{ display:inline; margin:0 2px 0 0; padding:0; text-transform:uppercase; } #ddcolortabs1 a{ float:left; color: white; background: #8cb85c url(layout_image/color_tabs_left.gif) no-repeat left top; margin:2px 2px 0 0; padding:0px 0 1px 3px; text-decoration:none; letter-spacing: 1px; } #ddcolortabs1 a span{ float:right; display:block; /*background: transparent url(layout_image/color_tabs_right.gif) no-repeat right top;*/ padding:6px 9px 2px 6px; } #ddcolortabs1 a span{ float:none; } #ddcolortabs1 a:hover{ background-color: #678b3f; } #ddcolortabs1 a:hover span{ background-color: #678b3f ; } #ddcolortabs1 #current a, #ddcolortabs1 #current span{ /*currently selected tab*/ background-color: #678b3f; } </style> <style> #SR_date{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .9em; margin-left: 10px; width: auto; height: auto; float: left; top : 10px; } #SR_number{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .9em; margin-left: 270px; width: auto; height: auto; float: left; top : 10px; } table { margin: 10px; font-family: Arial, Helvetica, sans-serif; font-size: .9em; border: 1px solid #DDD; width: auto; } th { font-family: Arial, Helvetica, sans-serif; font-size: .7em; background: #694; color: #FFF; padding: 2px 6px; border-collapse: separate; border: 1px solid #000; } td { font-family: Arial, Helvetica, sans-serif; font-size: .7em; border: 1px solid #DDD; text-align: left; } #RequestedBy{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .8em; margin-left: 10px; width: auto; height: auto; float: left; top : 10px; } #ApprovedBy{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .8em; margin-left: 15px; width: auto; height: auto; float: left; top : 10px; } #ReceivedBy{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .8em; margin-left: 15px; width: auto; height: auto; float: left; top : 10px; } #IssuedBy{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .8em; margin-left: 15px; width: auto; height: auto; float: left; top : 10px; margin-right: 120px; } #save_btn{ position: relative;; font-family: Arial, Helvetica, sans-serif; font-size: .8em; margin-left: 10px; top: 10px; } </style> <script type="text/javascript"> function save_sr(){ var sr_date = document.getElementById("sr_date").value; var sr_number = document.getElementById("sr_number").value; var Items = document.getElementById("Items").value; var SubItems = document.getElementById("SubItems").value; var ItemCode = document.getElementById("ItemCode").value; var DemandedQty = document.getElementById("DemandedQty").value; var UoM = document.getElementById("UoM").value; var Class = document.getElementById("Class").value; var Description = document.getElementById("Description").value; var BINLocation = document.getElementById("BINLocation").value; var RequestedBy = document.getElementById("RequestedBy").value; var ApprovedBy = document.getElementById("ApprovedBy").value; var ReceivedBy = document.getElementById("ReceivedBy").value; var IssuedBy = document.getElementById("IssuedBy").value; document.stock_requisition.action="StockRequisitionSave.php?sr_date="+sr_date+"&sr_number="+sr_number+"&Items="+Items+ "&SubItems="+SubItems+"&ItemCode="+ItemCode+"&DemandedQty="+DemandedQty+"&UoM="+UoM+"&Class="+Class+"&Description="+ Description+"&BINLocation="+BINLocation+"&RequestedBy="+RequestedBy+"&ApprovedBy="+ApprovedBy+"&ReceivedBy="+ReceivedBy+ "&IssuedBy="+IssuedBy; document.stock_requisition.submit(); alert("Stock Requisition data save."); window.location = "StockRequisition.php"; } </script> </head> <body> <form name="stock_requisition" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <div id="ddcolortabs"> <ul> <li> <a href="ParameterSettings.php" title="Parameter Settings"><span>Parameter Settings</span></a></li> <li style="margin-left: 1px"><a href="kanban_report.php" title="WIP Report"><span>Wip Report</span></a></li> <li id="current"><a href="StockRequisition.php" title="WMS RM"><span>WMS RM</span></a></li> </ul> </div> <div id="ddcolortabs1"> <ul> <li><a href="ReceivingMaterials.php" title="Receiving Materials"><span>Receiving Materials</span></a></li> <li><a href="Shelving.php" title="Shelving"><span>Shelving</span></a></li> <li id="current"><a href="StockRequisition.php" title="Stock Requisition"><span>Stock Requisition</span></a></li> </ul> </div> <div id="SR_date"> <label>Date :</label> <input type="text" name="sr_date" value="<?php echo $sr_date; ?>" size="16" readonly="readonly" style="border: none;"> </div> <div id="SR_number"> <label>SR# :</label> <input type="text" name="sr_number" value="<?php echo $currentSR; ?>" size="10" readonly="readonly" style="font-weight: bold; border: none;"> <br/> </div> <div> <table> <thead> <th>Items</th> <th>Sub Items</th> <th>Item Code</th> <th>Demanded Qty</th> <th>UoM</th> <th>Class</th> <th>Description</th> <th>BIN Location</th> </thead> <?php $sql = "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items"; $res_bom = mysql_query($sql, $con); while($row = mysql_fetch_assoc($res_bom)){ $Items = $row['Items']; echo "<tr> <td style='border: none;font-weight: bold;'> <input type='name' value='$row[Items]' name='Items' id='Items' readonly = 'readonly' style = 'border:none;width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='5'></td> </tr>"; $sql = "SELECT SubItems, ItemCode, UoM, Class, Description, BINLocation FROM bom_subitems WHERE Items = '$row[Items]' ORDER BY Items"or die(mysql_error()); $res_sub = mysql_query($sql, $con); while($row_sub = mysql_fetch_assoc($res_sub)){ echo "<tr> <td style='border: none;'> </td> <td style='border: none;'> <input type='text' name='SubItems' value='$row_sub[SubItems]' id='SubItems' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'> <input type='text' name='ItemCode' value='$row_sub[ItemCode]' id='ItemCode' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'><center><input type='text' name='DemandedQty' id='DemandedQty' value='' size='7'></center></td> <td style='border: none;' size='3'> <input type='text' name='UoM' value='$row_sub[UoM]' id='UoM' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='3'></td> <td style='border: none;'> <input type='text' name='Class' value='$row_sub[Class]' id='Class' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'> <input type='text' name='Description' value='$row_sub[Description]' id='Description' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'> <input type='text' name='BINLocation' value='$row_sub[BINLocation]' id='BINLocation' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> </tr>"; } } ?> </table> </div> <div id='RequestedBy'> <label>Requested By:</label> <select name="Requested_By"> <option name='None'>Select</option> <option name='AAAAAAAAA'>AAAAAAAAA</option> <option name='BBBBBBBBB'>BBBBBBBBB</option> <option name='CCCCCCCCCC'>CCCCCCCCCC</option> </select> </div> <div id='ApprovedBy'> <label>Approved By:</label> <select name="Approved_By"> <option name='None'>Select</option> <option name='AAAAAAAAA'>AAAAAAAAA</option> <option name='BBBBBBBBB'>BBBBBBBBB</option> <option name='CCCCCCCCCC'>CCCCCCCCCC</option> </select> </div> <div id='ReceivedBy'> <label>Received By:</label> <select name="Received_By"> <option name='None'>Select</option> <option name='AAAAAAAAA'>AAAAAAAAA</option> <option name='BBBBBBBB'>BBBBBBBB</option> <option name='CCCCCCCC'>CCCCCCCC</option> </select> </div> <div id='IssuedBy'> <label>Issued By:</label> <select name="Issued BY"> <option name='None'>Select</option> <option name='AAAAAAAAA'>AAAAAAAAA</option> <option name='BBBBBBBB'>BBBBBBBB</option> <option name='CCCCCCCC'>CCCCCCCC</option> </select> </div> <div id="save_btn"> <input type="button" name="button" value="save" onclick="save_sr()"> </div> </body> </html> I also I attach the display data. Thank you I have two tables...one is scheduled_umps and one is games. Both tables have a column 'game_id'. I need to select how many games a person is scheduled for in a given time frame. Here's what I have for the select...and it's not working (You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE scheduled_umps.ump_id = '34' AND games.game_id = scheduled_umps.game_id AN' at line 1) Code: [Select] <?php $today_is_this_date = date('Y-m-d'); $four_months_ago = date('Y-m-d', strtotime('-4 months', strtotime($today_is_this_date))); $four_months_from_now = date('Y-m-d', strtotime('+4 months', strtotime($today_is_this_date))); /// How many games have you worked? //$query = "SELECT COUNT(ump_id) FROM scheduled_umps WHERE `ump_id` = '$_SESSION[ump_id]'"; ///this one selects how many games you've worked NO MATTER WHAT THE DATE $query = "SELECT scheduled_umps.game_id, games.game_id, COUNT(scheduled_umps.ump_id) WHERE scheduled_umps.ump_id = '$_SESSION[ump_id]' AND games.game_id = scheduled_umps.game_id AND games.game_id BETWEEN $four_months_ago AND $four_months_from_now"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "You have been scheduled on <b>". $row['COUNT(ump_id)'] ."</b> dates for the $_SESSION[association_name]."; } ?> [\code] Any ideas where I'm going wrong? Thanks for the help...I HATE multi-table selects! I have a Select statement that relies on two session variables to complete the statement. One variable, $egroup, supplies a column name. I cannot make the SELECT work. It works fine if I substitute the real name of one of the columns such as "egroup1", or "egroup6", but that's what the variable $egroup is for. Can anyone tell me where I'm wrong? I guess the answer is in the syntax, but I'm not very good at this and I've been on it for too long. Any help gratefully taken. Code: [Select] <?php $query1 = mysql_query("SELECT * FROM topics WHERE managerId='".$managerId."' AND "$egroup"= 1 ORDER BY title ASC"); ?> Hey guys, I'm trying to get this working... No errors right now, but I'm not returning any results :/ been messing with it for days. Code: [Select] <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" /> <label for="search_by">Search By</label> <select name="search_by"> <option value"player">Player</option> <option value"city">City</option> <option value"alliance">Alliance</option> <option value"browse">Browse</option> </select> <input type="text" name"search"> <input type="submit" value="search" name="search"> <?php $search_by = $_POST['search_by']; $search = $_POST['search']; echo "<table><tr><td>Player</td><td>city</td><td>alliance</td><td>x</td><td>y</td><td>other</td><td>porters</td><td>conscripts</td><td>Spies</td><td>HBD</td><td>Minos</td><td>LBM</td><td>SSD</td><td>BD</td><td>AT</td><td>Giants</td><td>Mirrors</td><td>Fangs</td><td>ogres</td><td>banshee</td></tr>" ; $dbc = mysqli_connect('xx', 'xx', 'xx', 'xx') or die ('Error connecting to MySQL server'); $sql = "SELECT * FROM players WHERE ('$search_by') LIKE ('$search') "; //problem is here^^?? $result = mysqli_query($dbc,$sql) or die("Error: " .mysqli_error($dbc)); Not sure, any help would be greatly appreciated. Hi All, I have the following Query: Code: [Select] $query = 'SELECT `BookingID`,`OfferID`, `name`, `OfferCount`,`OfferPrice` FROM `Offers_Finance` JOIN offers_details ON `OfferID` = `o_d_id` WHERE `BookingID` ="' .$bookerid. '"'; if ( !$result = $mysqli->query( $query ) ) { die( $mysqli->error ); } $field = $result->fetch_object(); This will return anywhere between 0 and 50 Rows of Data. For Each Row returned, I want to do the following: Quote echo '<tr>'; echo '<td>' . $field->name.'</td>'; echo '<td></td>'; echo '<td>£' . $field->OfferPrice.'</td>'; echo '<td></td>'; echo '<td>' . $field->OfferCount . '</td>'; echo '<td></td>'; echo '<td>£' . $field->OfferPrice * $field->OfferCount . '</td>'; echo '</td>'; echo '</tr>'; The problem I have is - how do I loop through the results returned from the query to output multiple rows? Sorry if this doesn't make much snese, I'm new to PHP and the whole web development world, but have been landed with finishing a project someone else started! If someone would be kind enough to turn this into a working example, it would help no end as I have about 20 of these things to figure out across the project! $sql=mysql_query("SELECT * FROM `buds` WHERE `level`<='$user_level' UNION SELECT * FROM `buds`, `unlocked_buds` WHERE buds.`id` = unlocked_buds.`bud_id` ORDER BY buds.`id` ASC") or die("A MySQL error has occurred.<br />Your Query: " . $sql . "<br /> Error: (" . mysql_errno() . ") " . mysql_error()); I have been trying to learn about UNION select statements. I ran the query above and got this response: Quote Error: (1222) The used SELECT statements have a different number of columns I think I know what the problem is, but not sure how to fix it. There is two columns, one is "buds" which holds the flowers seeds info. The seconds is "unlocked_buds" which just links the "id" from buds to "user_id" to the user table. Both buds and unlocked_buds are both 8 columns. What do I need to learn? Hi Guys I don't know if this is possible but can someone point me in the right direction. I have a php function which takes two inputs and returns an output. for simplicity's sake let's say it's an addition function. What I want to do is use a mysql select statement to show all the rows from a database where field1 and field2 equal '3'. Here's the sort of thing I mean. function addNumbers($one,$two) { return $one + $two; } mysql_query("SELECT * FROM table WHERE 'addNumbers(field1,field2)' = '3'"); What I actually want to do is a lot more complex than this but I am trying to understand how to make the syntax work in simple terms first. Can anybody help? Many Thanks Dan I need to convert the following select statement to a pdo->query but have no idea how to get it working: SELECT t.id FROM ( SELECT g.* FROM location AS g WHERE g.start <= 16785408 ORDER BY g.start DESC, g.end DESC LIMIT 1 ) AS t WHERE t.end >= 16785408; Here's the code I'm trying: <?php $php_scripts = '../../php/'; require $php_scripts . 'PDO_Connection_Select.php'; require $php_scripts . 'GetUserIpAddr.php'; function mydloader($l_filename=NULL) { $ip = GetUserIpAddr(); if (!$pdo = PDOConnect("foxclone_data")) { exit; } if( isset( $l_filename ) ) { $ext = pathinfo($l_filename, PATHINFO_EXTENSION); $stmt = $pdo->prepare("INSERT INTO download (address, filename,ip_address) VALUES (?, ?, inet_aton('$ip'))"); $stmt->execute([$ip, $ext]) ; $test = $pdo->prepare("SELECT t.id FROM ( SELECT g.id FROM lookup AS g WHERE g.start <= inet_aton($ip) ORDER BY g.start DESC, g.end DESC ) AS t WHERE t.end >=inet_aton($ip)"); $test ->execute() ; $ref = $test->fetchColumn(); $ref = intval($ref); $stmt = $pdo->prepare("UPDATE download SET ref = '$ref' WHERE address = '$ip'"); $stmt->execute() ; header('Content-Type: octet-stream'); header("Content-Disposition: attachment; filename={$l_filename}"); header('Pragma: no-cache'); header('Expires: 0'); readfile($l_filename); } else { echo "isset failed"; } } mydloader($_GET["f"]); exit; It gives the following error: QuoteFatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '.144.181) ORDER BY g.start DESC, g.end DESC ) AS t WHERE t.end >=inet_aton(7' at line 1 in /home/foxclone/test.foxclone.com/download/mydloader.php:19 Stack trace: #0 /home/foxclone/test.foxclone.com/download/mydloader.php(19): PDO->prepare('SELECT t.id FRO...') #1 /home/foxclone/test.foxclone.com/download/mydloader.php(38): mydloader('foxclone40a_amd...') #2 {main} thrown in /home/foxclone/test.foxclone.com/download/mydloader.php on line 19 How do I fix this? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=322930.0 What's the correct syntax for having a variable in a select statement? Here's an example of what I'm trying to do (after I'm already connected to the database). Code: [Select] $username = "thomas"; $query = mysql_query( "SELECT * from users WHERE username = $thomas" ); if( mysql_num_rows( $query ) > 0 ) { bla bla... It works if I don't put the WHERE part in, but I get an error if I use it, so I'm assuming I have the wrong syntax for using a variable in the select statement. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=327011.0 here is some simple code for getting and displaying fata from a database Code: [Select] $sql="SELECT * FROM messages WHERE m_id = '".$id."'"; $result = mysql_query($sql); <table border='0' cellspacing="4"> while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<th>Message</th>"; echo "</tr>"; echo "<tr>"; echo "<td>" . $row['message'] . "</td>"; echo "</tr>"; } now ive used that while loop to display those results how can i do that again without having a new SQL statement. i cant do 2 while loops because the first one has already got to the end of the amount of rows basically how can i have another while loop displaying those same results again? //DATABASE CONNECTION VARIABLES $myserver ="localhost"; $myname = "myname"; $mypassword = "mypassword"; $mydb ="mygamedb"; /*SQL CONNECTION*/ // Create connection $conn = new mysqli($myserver, $myname, $mypassword, $mydb); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } else { //variables $username = $_POST["username"]; $password = $_POST["password"]; $ip = $_SERVER['REMOTE_ADDR']; //INSERT USER //prepare and bind $stmt = $conn->prepare("INSERT INTO Players (Username, Password, IP) VALUES (?, ?, ?)"); //bind parameters $stmt->bind_param("sss", $username, $password, $ip); //set parameters and execute $stmt->execute(); //close $stmt->close(); //FETCH ID $resultnews = mysql_query("SELECT * FROM Players WHERE Username ='$username'"); $rownews = mysql_fetch_array($resultnews); $user_id = $rownews["ID"]; }After having suffered an SQL injection into one of my sites, I figured it was time to overhaul it and use prepared statements. I am new to this. I figured out how to an INSERT with an example, but now I need to fetch an ID and cannot get it to work. Any help much obliged. All I need is just one good example. Looked all over the place, but all I get are insert examples, which is NOT what i need. Really need one with a select and fetch. Hey guys I want to create a class containing a SELECT statment in order to make in re-usable though out my entire applicion. Any one no a good way to go about this? This is the native way i have done it. I want to be able to make this into a class becuase i have more than one database with the same tables. Code: [Select] $articles = "SELECT * FROM blog_posts INNER JOIN users ON blog_posts.aurthor_id=users.user_id INNER JOIN post_categories ON blog_posts.category_id=post_categories.id"; $articles_results = mysql_query($articles)or die(mysql_error());; |