Jump to content

Thauwa

Members
  • Posts

    142
  • Joined

  • Last visited

About Thauwa

  • Birthday 11/04/1994

Contact Methods

  • Website URL
    http://www.tHaUwA.com

Profile Information

  • Gender
    Male
  • Location
    Sri Lanka

Thauwa's Achievements

Member

Member (2/5)

0

Reputation

  1. Thank you so much for putting me on the right track! I found a sample code here: http://anthonygthomas.com/2010/03/14/display-form-fields-based-on-selection-using-jquery/ Once again, I thank you for your time and reply.
  2. Hey folks! I hope that I posted this in the right section. For some time now, I've been wanting to know how to have HTML form fields of the same form appear/disappear depending on the value of one of the fields in that form itself. Will this require JavaScript? Am I trying to step into something too complex? Here's an example of what I'm trying to learn about: There is a form, which at first displays only a drop-down box with values from "1-5". If the user selects "2", two text fields will appear below the drop-down box. If the user then selects "1", the two fields become one. If "5" is selected, the total number of fields visible will be five. The five fields available will belong to the same form, and overall, there will be only five text fields present (not 1+2+3+4+5=15). Does anyone know how I could achieve this? I just want to get an idea of how to get this done. I hope that I didn't sound confusing. I will appreciate any help offered, and I thank you for reading! Thanks and Regards, Thauwa.
  3. Hello.. Thanks for your replies. I went through my code and found out that I had put a page refresh line before this code. So I swapped places and the code worked out fine. I really appreciate your time and input. Regards, Thauwa P.S. Hopefully this topic would be of use to a coder out there some day!
  4. Hi all! I'm stuck in the midst of some code. In it I have an if function which operates based on whether a variable (a word) is the same as another variable. Here is my code: <? $var1 = "chicago"; if($table_name === $var1){ $result = mysql_query("SELECT * FROM another_table WHERE username='$usernamee'"); while($row = mysql_fetch_array($result) ) { $var2 = $row['var2']; $var2_new = $var2 * 2; mysql_query("UPDATE another_table SET var2 = '$var2_new' WHERE username = '$usernamee'"); } } ?> I tried using =, == and ===, but did not get any of the results I expected. Could anyone advice me on the situation? Thanks in advance. Regards, Thauwa
  5. Hi all! I got the code to work. mysql_query ("SELECT * FROM users ORDER BY (SQRT(POW('$x_coordinate' - x_coordinate, 2) + POW('$y_coordinate' - y_coordinate, 2) ) ) ASC"); I verified the math by manually calculating the entries in my database and checking them against the list generated by the php. I thank all for helping me out of this. I sincerely do. Thanks and Regards, Thauwa
  6. Thanks batwimp and psycho, for your replies. @batwimp - Thank you for the code suggestion. I tried that. Still am getting the error. This is the first time I'm considering math within a mysql_query... any tips? @psycho - Thanks for your advice. I will try out the generating-and-discarding-if-taken method. Anyone got any hints as to how I could make the query work? The error I get is: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in Thanks and Regards, Thauwa
  7. Thank you so much for your reply. I got the hang of it, and I used your code and tried some changes on it, but to no avail. I am really grateful for putting me on the right track though... I get a 'not valid MySQL' source error. Here is the code I used: $result2 = mysql_query("SELECT * FROM users WHERE username='$usernamee'"); $row = mysql_fetch_assoc($result2) ; $x_coordinate = $row['x_coordinate'] ; $y_coordinate = $row['y_coordinate'] ; $result3 = mysql_query ("SELECT ABS( SQRT( POW($x_coordinate - x_coordinate, 2) + POW($y_coordinate - y_coordinate, 2) ) ) AS distance FROM users SORT BY distance ASC"); while ($riw = mysql_fetch_assoc($result3)) { echo $riw['username'];; } The random number inserting part goes fine. I even tried switching the ends of the AS part (so that 'distance' comes in front of AS and the math part after). And I understand the logic behind what you gave me (and I am grateful for that). I guess I need more advice... Thanks in advance, Thauwa
  8. Hey all! In the code in question I echo out individual records of data from MySQL successfully. For each record there is a number which is used as a var in the javascript that does the count-down-timer part. However when I view the resulting page the timer works dynamically only with the first record. With the rest, the timer is static. <? $result0 = mysql_query("SELECT * FROM table WHERE field='$value'"); while ($riw0 = mysql_fetch_assoc($result0)) { $seconds1 = $riw0['seconds'] ; //// echo out data and set variable for the number of seconds to count down ?> <script language="JavaScript"> var countDownInterval=<?=$seconds1?>; var c_reloadwidth=200 </script> <ilayer id="c_reload" width=&{c_reloadwidth}; ><layer id="c_reload2" width=&{c_reloadwidth}; left=0 top=0></layer></ilayer> <script> var countDownTime=countDownInterval+1; function countDown(){ countDownTime--; if (countDownTime <=0){ countDownTime=countDownInterval; clearTimeout(counter) window.location.href="military3.php" //Redirection URL return } var mins = Math.floor(countDownTime/60) var secs = countDownTime-(mins*60) if (document.all) //if IE 4+ document.all.countDownText.innerText = mins+" minutes "+secs+ " "; else if (document.getElementById) //else if NS6+ document.getElementById("countDownText").innerHTML=mins+" minutes "+secs+ " " else if (document.layers){ document.c_reload.document.c_reload2.document.write('Soldiers will be ready in... <span id="countDownText">'+countDownTime+' </span> seconds') document.c_reload.document.c_reload2.document.close() } counter=setTimeout("countDown()", 1000); } function startit(){ if (document.all||document.getElementById) document.write('Soldiers will be ready in <span id="countDownText">'+countDownTime+' </span> seconds') countDown() } if (document.all||document.getElementById) startit() else window.onload=startit </script> <? } ?> I tried replacing the javascript vars with PHP echoes for unique variables, but then no timer shows up, even static. So could anyone advice me on how I could use this code to apply for all MySQL records? Thanks in advance, Thauwa P.S. If I am unclear with my quandary, do let me know. Thank you.
  9. Hi all! I hope that you are all having a great time with PHP. Well I am too. Problem: I want all users who register to a mock site to have a unique, yet random ID. This ID is used to give the user virtual coordinates. So what I thought was to give the users a 'coordinate' like x=123, y=123 . i.e. (123,123) One of my goals is to calculate the virtual distance between two users. I figured out the real-world solution to this problem (I hope that it is correct!). It is as follows: User 1: (123,123), User 2: (111,111). Distance: (((123-111)^2)+((123-111)^2)))^1/2 Now to my problem... Is it possible for me to arrange a list of user-records for each user in order of the 'closest' (shortest distance) users to those farthest? Without having my databases ruined with too much entries, that is... My other problem is as to how to make the 'coordinates' unique to each user. All I know about that is about assigning random numbers for each, and this is not that efficient. If you think that my entire approach to the situation is bonkers , do let me know. I thank you for any help in advance! Regards, Thauwa
  10. I thank everyone for their replies. I tried all the solutions you offered and found out that it was the header() that I wanted. Thanks again!
  11. Hi I once found out how to do this 4 years ago but I lost my backups and memory on the matter. I want this xml to be echoed? out as it is. When I try the standard echo and print, I get the first two lines of the code in gray when I view the page's source. I get no xml at all. <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE blah [ <!ELEMENT cart (title, items)> <!ELEMENT title (#PCDATA)> <!ELEMENT items (item)+> <!ELEMENT item (prive, deprive, onprive+)> <!ELEMENT security (#PCDATA)> <!ELEMENT answer (#PCDATA)> <!ATTLIST answer correct (yeah) #IMPLIED> ]> this is followed by the standard displaying of xml items could anyone help me over here? thanks in advance...
  12. I found the solution... Time_Left = document.write("txt")
  13. I found the solution. Time_Left = document.write("txt") My thanks 30 viewers!
×
×
  • 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.