Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
Depends on your definition of "great drawbacks" and your future needs. Having the data "normalized" such as pocobueno1388 explained you will have much greater flexibility. Without knowing your current or future needs I can't say how much of a benefit, if any, it would be. But, let's say you needed a report of how many users are taking each medication. The only way to do it with the current structure would be to query the entire database and then create a post-processing script in PHP to analyze the data. Which would create a lot of unnecessary overhead. With a child table like pocobueno1388 showed you could get the numebr of users taking each medication with the following query: SELECT count(*) FROM medications JOIN users on medications.user_id = users.id GROUP BY medications
-
Well, it would really help if you gave us an idea of the data you are using. But, here's one possibility" JS Code <script type="text/javascript"> function setVal(fieldID, inputValue) { document.getElementById(fieldID).value = inputValue; } </script> HTML Code <select name="thelist" onchange="setVal('thetext', this.value);"> <option value="One">1</option> <option value="Two">2</option> <option value="Three">3</option> </select> <br /> <input type="text" name="thetext" id="thetext" />
-
Doing that is bad practice. I fyou have a many to one relationship you should have a child table for those records. But, I will answer your question nonetheless. The great thing about checkboxes is that if they are not checked their value is not posted. So, concatenating the values with commas is very simple: $meds = implode(',', $_POST['medication']);
-
I had to put a value in there because as I stated before I don't have access to your database. That field was not used in the function so I just put a placeholder in there. Just change it back to what you need it to be.
-
OK, a few comments 1. The function is trying to update the total for each row whenever it is run - this is inefficient. You only need to update the total on the current row the user is working on. 2. Also, the function is only being run on an onclick of the total field. The user shouldn't need to click on the result field. You can simply do it on on onchange/onblur of the input fields. 3. I don't see a way to pass the function an index number such that you can use getElementsByName() in an efficinet manner. I would use an index in the id field when generated in the PHP. 4. It will help the usability to either remove the border from the readonly fields or use a div. This gives the user a visual cue that they cannot enter anything in them Change the PHP script that creates the rows to this: <?php $indx = 1; while ($row_test = mysql_fetch_assoc($test)) { ?> <tr> <td height="20" scope="col"><input name="matric_no[]" type="text" id="matric_no[]" value="<?php echo $row_test['matric_no']; ?>" size="10" readonly="true" /></td> <td scope="col"><input name="cam" type="int" id="cam<?php echo $indx; ?>" size="8" onblur="calculate(this); /></td> <td scope="col" ><input name="final_exam" type="int" id="final_exam<?php echo $indx; ?>" size="8" onblur="calculate(this); /></td> <td scope="col"><input name="total" type="int" id="total<?php echo $indx; ?>" size="8" /></td> <td scope="col"><input name="grade" type="text" id="grade<?php echo $indx; ?>" size="8" /></td> </tr> <?php $indx++; } ?> Change your function to this function calculate(fldObj) { var indx = fldObj.id.replace(/[^\d]/g, ''); var fldName = fldObj.id.replace(/[^\D]/g, ''); var camsObj = document.getElementById('cam'+indx); var camsVal = parseInt(camsObj.value); var finalObj = document.getElementById('final_exam'+indx); var finalVal = parseInt(finalObj.value); //Verify both number are positive integers if (fldName=='cam' && camsVal<0) { alert('You may not enter negative numbers!'); camsObj.focus(); camsObj.select(); return false; } else if (fldName=='final_exam' && finalVal<0) { alert('You may not enter negative numbers!'); finalObj.focus(); finalObj.select(); return false; } //Ensure both values are entered if (!camsObj.value || !finalObj.value) { return false; } //Create the total var totalVal = (camsVal + finalVal); //Validate total is not greater than 100 if (totalVal>100) { alert('Total cannot be more than 100!'); camsObj.select(); camsObj.focus(); return false; } //Populate the total document.getElementById('total'+indx).value = totalVal; //Determine the grade var gradeVal; if (totalVal>=80) { gradeVal = 'A'; } else if (totalVal>=70) { gradeVal = 'B'; } else if (totalVal>=60) { gradeVal = 'C'; } else if (totalVal>=50) { gradeVal = 'D'; } else if (totalVal>=40) { gradeVal = 'E'; } else { gradeVal = 'F'; } //Populate the grade document.getElementById('grade'+indx).value = gradeVal; return; } Just in case i have some typos, here is a complete working example: <html> <head> <script> function calculate(fldObj) { var indx = fldObj.id.replace(/[^\d]/g, ''); var fldName = fldObj.id.replace(/[^\D]/g, ''); var camsObj = document.getElementById('cam'+indx); var camsVal = parseInt(camsObj.value); var finalObj = document.getElementById('final_exam'+indx); var finalVal = parseInt(finalObj.value); //Verify both number are positive integers if (fldName=='cam' && camsVal<0) { alert('You may not enter negative numbers!'); camsObj.focus(); camsObj.select(); return false; } else if (fldName=='final_exam' && finalVal<0) { alert('You may not enter negative numbers!'); finalObj.focus(); finalObj.select(); return false; } //Ensure both values are entered if (!camsObj.value || !finalObj.value) { return false; } //Create the total var totalVal = (camsVal + finalVal); //Validate total is not greater than 100 if (totalVal>100) { alert('Total cannot be more than 100!'); camsObj.select(); camsObj.focus(); return false; } //Populate the total document.getElementById('total'+indx).value = totalVal; //Determine the grade var gradeVal; if (totalVal>=80) { gradeVal = 'A'; } else if (totalVal>=70) { gradeVal = 'B'; } else if (totalVal>=60) { gradeVal = 'C'; } else if (totalVal>=50) { gradeVal = 'D'; } else if (totalVal>=40) { gradeVal = 'E'; } else { gradeVal = 'F'; } //Populate the grade document.getElementById('grade'+indx).value = gradeVal; return; } </script> </head> <body> <table border=1> <tr> <td height="39" scope="col"><input name="matric_no[]" type="text" id="matric_no" value="50" size="10" readonly /></td> <td scope="col"><input name="cam" type="int" id="cam1" size="8" onBlur="calculate(this);" /></td> <td scope="col"><input name="final_exam" type="int" id="final_exam1" size="8" onBlur="calculate(this);" /></td> <td scope="col"><input name="total" type="int" id="total1" size="8" readonly /></td> <td scope="col"><input name="grade" type="text" id="grade1" size="8" readonly /></td> </tr> <tr> <td height="39" scope="col"><input name="matric_no[]" type="text" id="matric_no" value="50" size="10" readonly /></td> <td scope="col"><input name="cam" type="int" id="cam2" size="8" onBlur="calculate(this);" /></td> <td scope="col"><input name="final_exam" type="int" id="final_exam2" size="8" onBlur="calculate(this);" /></td> <td scope="col"><input name="total" type="int" id="total2" size="8" readonly /></td> <td scope="col"><input name="grade" type="text" id="grade2" size="8" readonly /></td> </tr> </table> </body> </html>
-
Did you see the link I posted?
-
foreach (glob('directory/*SM.gif') as $file) { unlink($file); }
-
discomatt is correct - this will not be easy. You will want to search for 3rd party tools to read the data in the documents. PDF and Word Docs include a lot of "unseen" code that describes haw the content is to be dislayed - sort of like HTML. But, it's more complex in that the "codes" and format changes. A PDF created in an older format may look very different under the hood than a new version. And with Word, the document format has completely changed with Office 2007. Trying to create your own utility to read the content from these documents would be a huge undertaking. There should be some utiliies available - however probably at a cost. http://www.snowbound.com/solutions/text_extraction.html
-
function confirmSelect() { var prodSelObj = document.getElementById('product'); var lvlSelObj = document.getElementById('level'); var prodText = prodSelObj.options[prodSelObj.selectedIndex].text; var lvlText = lvlSelObj.options[lvlSelObj.selectedIndex].text; var confirmMsg = "Please confirm your selection.\n" + "Secondary Rating Product: " + prodText + "\n" + "Priority Level: " + lvlText return confirm(confirmMsg); }
-
To get assistance with JavaScript problems you should ONLY post the HTML that would be generated - not the PHP code. Your code is doing several database queries and I would not want to take the time & energy to try and reproduce your database to find a solution. Simply access the page from your browser and then extract the generated HTML. If this is your PHP file: <?php echo "The current date is " . date('F j, Y'); ?> The HTML would be: The current date is September 1, 2008
-
because I was bored I mocked up a quick AJAX example for dynamic select lists. This does not include a lot of validation, but will work. I leave it to you to optimize: The user page: <html> <head> <script type="text/javascript"> var xmlHttp function updateModels(makeVal) { //Disable the dependant list until it is updated document.getElementById('model').disabled = true; xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } var url="get_models.php"; url=url+"?make="+makeVal; url=url+"&sid="+Math.random(); xmlHttp.onreadystatechange=populateModels; xmlHttp.open("GET",url,true); xmlHttp.send(null); } function GetXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } function populateModels() { if (xmlHttp.readyState==4) { //Create obj ref to the select list var selectObj = document.getElementById('model'); //Clear values from select list selectObj.options.length = 0 //Get the response from the server-side page var modelListStr=xmlHttp.responseText; //Split the results into an array var modelListAry = modelListStr.split(','); //Repopulate the list for ($i=0; $i<modelListAry.length; $i++) { var modelVals = modelListAry[$i].split('-'); selectObj.options[selectObj.length] = new Option(modelVals[1], modelVals[0]); } //re-enable the select list selectObj.disabled = false; } } </script> </head> <body onload=""> <form name="test" method="POST" action="processingpage.php"> Make: <select name="make" id="make" onchange="updateModels(this.value);"> <option value="Dodge">Dodge</option> <option value="Ford">Ford</option> <option value="Honda">Honda</option> <option value="Toyota">Toyota</option> </select> <br> Model: <select name="model" id="model"> <option value="">Not Applicable</option> </select> <br> </form> </body> </html> The server-side page <?php $returnAry = array(); //Get the make from the query string $make = $_GET['make']; //Find the models for the selected make $query = "SELECT model FROM cars WHERE make='$make'"; $result = mysql_query($query); //Create the return data while($model = mysql_fetch_assoc($result)) { $returnAry[] = $model['id'] . '-' . $model['name']; } echo implode(',', $returnAry); //The return string will be inthis format // "id1-value1,id2-value2,id3-value3, etc" ?>
-
Changing the Var Delay Hide (JavaScript Code)
Psycho replied to Xtremer360's topic in Javascript Help
No, you do not want to make the delay infinite. That will waste resources by the users computer to process that. Simply rewrite the code so there is NO delay and have the hide code take effect on an onclock event for another menu. -
Well, it's difficult to know exactly what is supposed to happen without seeing the accompanying HTML, but there is a lot wriong with that code. 1. The function code should be enclosed in curly braces 2. There is no getElementByName, it is getElementsByName 3. The while loop makes no sense because it is overwriting the value of total on each iterration - because youare reinitiating the variable using var and because you are setting it to a new value Without seeing the HTML that this goes with I can't decide how it should be corrected. Here is a guess <script type="text/javascript"> function calculate() { var cams = document.getElementsByName("cam"); var finals = document.getElementById("final_exam"); var total = 0; for (i=0; i<cams.length; i++) { total += parseInt(cams[i].value) + parseInt(finals[i].value); } document.getElementById("total").value = total; } </script>
-
OK, it's not a bug guys. It looks like the code is trying to determine the month number by creating a date object using todays date and only changing the month. This post was submitted yesterday on Aug. 31, 2008. If you only tried to change the month value you get Feb. 31, 2008 - no such date exists! It would actually evaluate to March 3, 2008! Which is why the select list shows 03-2. I think that code is way over complicated. It doesn't look like you need to do all the date evaluations. All you need to know is the month number of the current month. echo "</SELECT>- <SELECT name=\"ETA_month$ii\">"; $current_month = date('m'); for($month=1; $month<=12; $month) { $selected = ($month == $current_month) ? ' selected="selected"' : ''; echo "<OPTION value=\"$month\"$selected></option>"; } echo "</SELECT>- <SELECT name=\"ETA_year$ii\">";
-
That onchange was only there for debugging purposes.
-
Simply add the code to send the email after the code to insert the record into the database (or vice versa). //Insert into database $sql = "INSERT INTO tbl_referral (fname, lname, phone, phonetype, email $addl_insert_crit) VALUES ( '$fname', '$lname', '$phone', '$phonetype', '$email' $addl_insert_values )"; if ($sql_debug_mode==1) { echo "<BR>SQL: $sql<BR>"; } $result = mysql_query($sql,db()); //Send email //....Code for email goes here
-
Look at my post in this thread http://www.phpfreaks.com/forums/index.php/topic,201892.0.html
-
You don't need that - there is a built-in function to always round up (and there is one for rounding down as well) result.value = Math.ceil(x);
-
As I said, you don't need a 2nd table. Simply use the gallery table. Since you will probably need to query the top four photos for all photographers at the same time, I would probably include an 'timestamp' AND a 'credit' column. The credit column would be a simple true/false value and the last four for each photographer would be set to true. You would first want a procedure to follow when new photos are uploaded to ensure only the last four photos are set to true. Here is one example: //Insert new photo $query = "INSERT INTO gallery (photo_name, timestamp, user_id) VALUES ('$name', $timestamp; $u_id)"; $result = mysql_query($query); //Reset all current 'credit' values $query = "UPDATE gallery SET credit=false WHERE user_id=$u_id AND credit=true"; $result = mysql_query($query); //Get the top 4 for the user $query = "SELECT id FROM gallery WHERE user_id=$u_id ORDER BY timestamp LIMIT 4"; $result = mysql_query($query); while($record = mysql_fetch_assoc($result)} { $photo_ids[] = $record['id']; } //Set the top 4 for the user to true for the credit column $query = "UPDATE gallery SET credit=true WHERE id IN (" . implode(',', $photo_ids) . ")"; $result = mysql_query($query); You can then get all ofthe top four photos for all photographers with this SELECT * FROM gallery WHERE credit=true
-
[SOLVED] PHP Session-variables lose their values between subdomains
Psycho replied to alexville's topic in PHP Coding Help
Add this before session_start() [usiong your parameters]: ini_set("session.cookie_domain", ".mydomain.com"); http://www.madcarrot.co.uk/2005/08/pass_sessions_b.html -
I still don't see the need for 2 tables. Are the four photos for the credit page supposed to be the last four that have been uploaded? If so, then just create a query that selects the last four from the gallery table. If not, then just create a new column in the gallery table called 'credit' (or something similar) and set the value to true for the four photos from each contributer that will be used for their credit display.
-
[SOLVED] Convert the value of bool to string without conditional?
Psycho replied to DssTrainer's topic in PHP Coding Help
I know you said you don't want an if statement, but I'd go with the ternary operator: $var=($var):'true':'false'; -
substr($cc_number, -4);
-
You should really post the source text in it's original form to get a proper solution. There might be line break characters or other data that may make the solution easier or more difficult. But, yes you can do it by extracting the data between two known values: $text = "194 WTNT32 KNHC 290231 TCPAT2 BULLETIN TROPICAL STORM GUSTAV ADVISORY NUMBER 17 NWS TPC/NATIONAL HURRICANE CENTER MIAMI FL AL072008 1100 PM EDT THU AUG 28 2008"; preg_match('/BULLETIN(.*)NWS/', $text, $matches); $advisory = trim($matches[1]); echo "Advisory: $advisory"; //Output: "Advisory: TROPICAL STORM GUSTAV ADVISORY NUMBER 17"
-
First thing you need to decide is what to do IF both are submitted. You can use JavaScript to try and limit the user, but that is not foolproof. So you can either 1) Not accept the input and redisplay the form or 2) Consider one as the primary and eaccept that. I will assume that if the user submitted both that the user really meant to submit a new value if (isset($_POST['new_category']) && trim($_POST['new_category'])!='') { $category = mysql_real_escape_string(trim($_POST['new_category'])); } else if (isset($_POST['category']) && trim($_POST['category'])!='') { $category = mysql_real_escape_string(trim($_POST['category'])); } else { $category = false; } if (!$category) { echo "No category submitted!"; } else { $query = "INSERT INTO dw_items (item_category) VALUES ('$category')"; //Run query }