Jump to content

dungpt29

Members
  • Posts

    29
  • Joined

  • Last visited

dungpt29's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have read carefully your PHP script. In my opinion, the solution used in the script is too bad and it cannot help you display product data as desired. Therefore, you are to develop a new one. Currently, I am not sure what exactly your structure of the grid is. Can you describe it more detailedly using a drawing? How many columns does it have? What is name of each column if existed? If so, I will be ready to help you work out another solution to display the product list on your webpage.
  2. Note that: x = exp(log(x)); So, 1/5 = 5-1 = exp(log(5-1)) = exp(-log(5)); The PHP code to solve the equation should be: $x = log(sqrt(5),exp(-log(5)));
  3. <script type="text/javascript" language="javascript"> //<![CDATA[ $(document).ready(function(){ $("#seGolfer").change(function(){ document.getElementById("frmGolfer").submit(); }); }); //]]> </script> I am sorry for forgetting putting JavaScript code in script tags
  4. Something like this: <form id="frmGolfer" name="frmGolfer" action="" method="post"> <select id="seGolfer" name="seGolfer" size="1"> <option value="golfer_1">Golfer 1</option> <option value="golfer_2">Golfer 2</option> <option value="golfer_3">Golfer 3</option> </select> </form> $(document).ready(function(){ $("#seGolfer").change(function(){ document.getElementById("frmGolfer").submit(); }); }); In your PHP page, switch...case syntax should be used to process the case of which golfer being selected, as follows: <?php $golfer = $_POST["seGolfer"]; switch ($golfer) { case 'golfer_1': // Code to process the case of golfer_1 being selected break; case 'golfer_2': // Code to process the case of golfer_2 being selected break; case 'golfer_3': // Code to process the case of golfer_3 being selected break; } ?>
  5. The best way to solve your problem is testing email address at client side using a JavaScript function as the following: function checkemail(emailStr) { var emailPat = /^([A-Za-z0-9]+[_\-\.]?[A-Za-z0-9]+)+\@([A-Za-z0-9]+[\-\.]?[A-Za-z0-9]+)+(\.[A-Za-z]+)$/; if (!emailPat.test(emailStr)) { return false; } return true; }
  6. requinix's hint is good but obviously it is not enough to solve your problem. That is because JavaScript is a case-sensitive programming language and the output string must be in its original format after processing and the replacement must be case-insensitive. This is also the most difficult obstacles needed to overcome. Here, I put forward some directions that can actualize an effective solution: Convert the input string to uppercase (or lowercase). Convert the keywords in the array to uppercase (or lowercase). Specify the position of the first occurrence of the converted keyword in the converted input string. Based on the located position, split the original string into two substrings (called s1 and s2) with the keyword used as separator. Clearly, it is not simple to use String.split to achieve this. Create a new input string using concat method: the input string = concat(s1, "NOPE", s2); The pseudo-code to describe the solution should be as the following: Loop through the keyword array while (possible to locate the position of the keyword) Split the input string into two substrings s1 and s2 using keyword as separator; the new input string = concat(s1, "NOPE", s2); end while End Loop The result string = the final input string; If you cannot write the effective code, I will be ready to help you further.
  7. I will work out a solution but I do not know if it is the best way to solve your problem. I think its only shortcoming is that it will make your code longer. First, you should edit your code in buynow.php so that when users click the link to navigate to your coupon code page, this link will submit the form containing data such as name, address, email, etc. This means that this link has the role as a button instead of a normal link. To achieve this, Javascript or JQuery is recommended. In your coupon code page, your get user data using $_POST as normal. For example: $address= $_POST["txtAddress"]; Next, you should complement the hidden fields to the form in your coupon code page that are specialized in containing user data temporarily. For example: <input type="hidden" id="hdAddress" name="hdAddress" value="<?php echo $address?>" /> You get the temporary user data when turning back to your buynow.php as the following: $hdAddress= $_POST["hdAddress"]; You repopulate user data in buynow.php as the following: <input type="text" name="txtAddress" id="txtAddress" size="100" maxlength="100" value="<?php echo $hdAddress?>"/>
  8. Thanks for your remarks. I am striving to write the neater code in the future. And I have a question for your solution. Assuming that the input string contains the negative numbers. For example: $string = "<214.27080, -204.88100, 2500.51300>"; Based on your code, I guess the output string will be: $newstring = "214/-205/2500"; Based on OP's requirement, the output string must be: $newstring = "214/-204/2500"; What do you think of this case, Psycho?
  9. Another solution to solve your problem could be as follows: $a1 = array(); $a2 = array(); $a3 = array(); // $txtInput contains your input data that is <214.27080, 204.10100, 2500.51300> $a1 = explode(",", $txtInput); $a1_length = count($a1); for ($i=0; $i < $a1_length; $i++) { $a2 = explode(".", trim($a1[$i])); array_push($a3, $a2[0]); array_pop($a2); array_pop($a2); } $str = implode("/",$a3); $str = trim($str, "<");
  10. Hi sparkynerd, Because you are new to PHP so I will work out a solution that is most suitable to you and is just based on your own code. First, you need to create a new text file named LED_Status.txt that is in the same folder containing your graphic.txt. This file, just as its name, is specialized in containing the status of your LED that is either ON or OFF. The initial status filled in file should be OFF. The code to solve your problem should be as the following: <?php ///////////////////////////////////////////////////////////////////////////////////////////// // Check of LED2 is set. If it is, then use it if (isset($_POST["LED2"])) { $LED2= $_POST["LED2"]; //echo "<b>$LED2</b>"; } else { //$LED2 =""; // Reading the data from text file $LED_Status_Temp = file_get_contents('LED_Status.txt'); $LED2 = $LED_Status_Temp; // $LED2 is assigned the current status of your LED } if ($LED2 == "ON") { // Set led2 ON by calling the Arduino using fopen $h = @fopen("http://192.168.5.21/?LED=T", "rb"); $image = "/Graphics/LED_red.bmp"; // set and write data to text file $fp = fopen('LED_Status.txt','w'); fwrite($fp,$LED2); // update current LED status } else if ($LED2 == "OFF") { // Set led2 OFF by calling the Arduino using fopen $h= @fopen("http://192.168.5.21/?LED=F", "rb"); $image = "/Graphics/LED_green.bmp"; // set and write data to text file $fp = fopen('LED_Status.txt','w'); fwrite($fp,$LED2); // update current LED status } ///////////////////////////////////////////////////////////////////////////////////////////// // set and write data to text file { $fp = fopen('graphic.txt','w'); fwrite($fp,$image); } ///////////////////////////////////////////////////////////////////////////////////////////// // Reading the data from text file $graphictemp = file_get_contents('graphic.txt'); $graphic = ($graphictemp); ?>
  11. I reckon the cause is that you have not processed the case of none of your buttons is pressed yet. In that case $LED2 is an empty string and thereby $image is not defined.
  12. SQL syntax: INSERT INTO table_name (column1,column2,column3,...)VALUES (value1,value2,value3,...); only allows inserting one record per time.
  13. You should replace your last loop with the following: foreach ($candy as $type => $specific) { if ($type == 'chocolate') { echo $specific . "<br />"; } else { echo $type . ' ' . $specific; } }
  14. Hi prolife, I guess that you are trying to save the formatted text from a text editor into your database. Then you want to display it on your webpage as plain text. You should try the following PHP function and it worked for me: <?php echo html_entity_decode("data pulled out from database")?>
  15. Try the following code: <input type="radio" name="colour" value="male" <?php if ($mal == "checked") { ?> checked <?php } ?> /> <input type="radio" name="colour" value="female" <?php if ($fem == "checked") { ?> checked <?php } ?>/>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.