Jump to content

Thauwa

Members
  • Posts

    142
  • Joined

  • Last visited

Everything posted by Thauwa

  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!
  14. Hi again. Do you have any idea as to how I could do this here? http://www.phpfreaks.com/forums/index.php?topic=352570.msg1664759#msg1664759 ? Thanks in advance. .....
  15. hi I am a total newb in this... I'm working on a code someone created (for a countdown timer) and want a button to appear (or the page to redirect) once the timer has reached 0. I tried some stuff from w3schools but ended in a mitigated disaster. <!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> <script> function countdown_clock(year, month, day, hour, minute, format) { //I chose a div as the container for the timer, but //it can be an input tag inside a form, or anything //who's displayed content can be changed through //client-side scripting. html_code = '<div id="countdown"></div>'; document.write(html_code); Today = new Date(); Todays_Year = Today.getFullYear() - 2000; Todays_Month = Today.getMonth(); <?php $date = getdate(); $second = $date["seconds"]; $minute = $date["minutes"]; $hour = $date["hours"]; $day = $date["mday"]; $month = $date["mon"]; $month_name = $date["month"]; $year = $date["year"]; ?> //Computes the time difference between the client computer and the server. Server_Date = (new Date(<?= $year - 2000 ?>, <?= $month ?>, <?= $day ?>, <?= $hour ?>, <?= $minute ?>, <?= $second ?>)).getTime(); Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime(); countdown(year, month, day, hour, minute, (Todays_Date - Server_Date), format); } function countdown(year, month, day, hour, minute, time_difference, format) { Today = new Date(); Todays_Year = Today.getFullYear() - 2000; Todays_Month = Today.getMonth(); //Convert today's date and the target date into miliseconds. Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime(); Target_Date = (new Date(year, month, day, hour, minute, 00)).getTime(); //Find their difference, and convert that into seconds. //Taking into account the time differential between the client computer and the server. Time_Left = Math.round((Target_Date - Todays_Date + time_difference) / 1000); if(Time_Left < 0) Time_Left = 0 switch(format) { case 0: //The simplest way to display the time left. document.all.countdown.innerHTML = Time_Left + ' seconds'; break; case 1: //More datailed. days = Math.floor(Time_Left / (60 * 60 * 24)); Time_Left %= (60 * 60 * 24); hours = Math.floor(Time_Left / (60 * 60)); Time_Left %= (60 * 60); minutes = Math.floor(Time_Left / 60); Time_Left %= 60; seconds = Time_Left; dps = 's'; hps = 's'; mps = 's'; sps = 's'; //ps is short for plural suffix. if(days == 1) dps =''; if(hours == 1) hps =''; if(minutes == 1) mps =''; if(seconds == 1) sps =''; document.all.countdown.innerHTML = days + ' day' + dps + ' '; document.all.countdown.innerHTML += hours + ' hour' + hps + ' '; document.all.countdown.innerHTML += minutes + ' minute' + mps + ' and '; document.all.countdown.innerHTML += seconds + ' second' + sps; break; default: document.all.countdown.innerHTML = Time_Left + ' seconds'; } //Recursive call, keeps the clock ticking. setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + time_difference + ', ' + format + ');', 1000); } </script> </head> <body> <script> countdown_clock(12, 01, 26, 06, 00, 1); </script> </body> </html> I inserted a window.location = ("redirect.php"); right after Time_Left = 0 . Then the page tries to keep on reloading, but never does. That I believe is because the 'day' and 'hour' were 0 but the 'minutes' were not. Can anyone pull me out....?
  16. All I can say is OMG....! Thank you so much....
  17. Hi again people! I found this code that codes for a countdown timer. My problem is, how do I implement it? I've found similar codes that leave me dazzled as I try to get them to work. The URL from which I found this is: http://scripts.franciscocharrua.com/server-side-countdown-clock.php The code is: function countdown_clock(year, month, day, hour, minute, format) { //I chose a div as the container for the timer, but //it can be an input tag inside a form, or anything //who's displayed content can be changed through //client-side scripting. html_code = '<div id="countdown"></div>'; document.write(html_code); Today = new Date(); Todays_Year = Today.getFullYear() - 2000; Todays_Month = Today.getMonth(); <? $date = getDate(); $second = $date["seconds"]; $minute = $date["minutes"]; $hour = $date["hours"]; $day = $date["mday"]; $month = $date["mon"]; $month_name = $date["month"]; $year = $date["year"]; ?> //Computes the time difference between the client computer and the server. Server_Date = (new Date(<?= $year - 2000 ?>, <?= $month ?>, <?= $day ?>, <?= $hour ?>, <?= $minute ?>, <?= $second ?>)).getTime(); Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime(); countdown(year, month, day, hour, minute, (Todays_Date - Server_Date), format); } function countdown(year, month, day, hour, minute, time_difference, format) { Today = new Date(); Todays_Year = Today.getFullYear() - 2000; Todays_Month = Today.getMonth(); //Convert today's date and the target date into miliseconds. Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime(); Target_Date = (new Date(year, month, day, hour, minute, 00)).getTime(); //Find their difference, and convert that into seconds. //Taking into account the time differential between the client computer and the server. Time_Left = Math.round((Target_Date - Todays_Date + time_difference) / 1000); if(Time_Left < 0) Time_Left = 0; switch(format) { case 0: //The simplest way to display the time left. document.all.countdown.innerHTML = Time_Left + ' seconds'; break; case 1: //More datailed. days = Math.floor(Time_Left / (60 * 60 * 24)); Time_Left %= (60 * 60 * 24); hours = Math.floor(Time_Left / (60 * 60)); Time_Left %= (60 * 60); minutes = Math.floor(Time_Left / 60); Time_Left %= 60; seconds = Time_Left; dps = 's'; hps = 's'; mps = 's'; sps = 's'; //ps is short for plural suffix. if(days == 1) dps =''; if(hours == 1) hps =''; if(minutes == 1) mps =''; if(seconds == 1) sps =''; document.all.countdown.innerHTML = days + ' day' + dps + ' '; document.all.countdown.innerHTML += hours + ' hour' + hps + ' '; document.all.countdown.innerHTML += minutes + ' minute' + mps + ' and '; document.all.countdown.innerHTML += seconds + ' second' + sps; break; default: document.all.countdown.innerHTML = Time_Left + ' seconds'; } //Recursive call, keeps the clock ticking. setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + time_difference + ', ' + format + ');', 1000); } I've tried saving the file as a php file and html file, but to no avail...
  18. Heya! Just replace your <td>'s with <tr>'s and vice versa. <td> <tr> </tr> <tr> </tr> <tr> </tr> <tr> </tr> </td> I hope that that's what you wanted with your previous question. Regards, Thauwa
  19. Oh WOW! Sorry for the confusion people! The javascript had nothing to do with the error, only the php headers. Thank you everyone, for contributing and helping me to solve my problem.
  20. Thanks, blueskyis and blew. But the page won't refresh with die("<metta http-equiv='refresh' content='$sec;url=$page'>"); :/ I believe that it is because I am not using that code in the <head> section of my page. Do correct me if I am wrong. What I really want to achieve is to reload the page once a form submits data to itself. All worked well with header(); , but after I inserted the javascript its been showing the error I mentioned above. Someone please help me. :'( . I've been working on this script for weeks and I don't won't all of it to go to waste. :-/ . I'll really appreciate more help. Thank you for now, and in advance.
  21. Thanks PaulRyan. Very. I found that out in the php.net manual. But.... How could I proceed? It it the javascript that is the problem? ahh...... :'(
  22. It seems that the javascript is reloading the page too. :/ . Does it count with php? Oh and is there any other way to have the page refreshed without using header(); and the HTML Meta Refresh? That would solve most of my problems too. Thanks.
  23. :'( Hey guys! Merry Christmas!!!! Here's my problem. I have a script where I use the code include("pagerefresh.php"); where pagerefresh.php is <?php $page = $_SERVER['PHP_SELF']; $sec = "0"; header("Refresh: $sec; url=$page"); ?> I use the include function several times on the page and everything's cool with it. But once I put this: <html> <head> <title>Title</title> <script type="text/javascript"> <?php some mysql function include("timecounter.js"); ?> </script> </head> in the page, the following error pops out whenever I use some of the form functions in the page. I read the php.net manuals and discovered that the include part should come before Warning: Cannot modify header information - headers already sent by (output started at D:\Hosting\rrr\html\rrr\rrr\rrr.php:191) in D:\Hosting\rrr\html\rrr\rrr\pagerefresh.php on line 4 Oh, and I also put the javascript code directly into the page, without the include function, the same results pop out. :/ . Though I suspect that it is immaterial here, the javascript code is: var month = '<?php echo "$cmonth"; ?>'; // 1 through 12 or '*' within the next month, '0' for the current month m var day = '<?php echo "$cday"; ?>'; // day of month or + day offset d var dow = 0; // day of week sun=1 sat=7 or 0 for whatever day it falls on var hour = '<?php echo "$chour"; ?>'; // 0 through 23 for the hour of the day H var min = '<?php echo "$cminute"; ?>'; // 0 through 59 for minutes after the hour i var tz = -7; // offset in hours from UTC to your timezone var lab = 'cd'; // id of the entry on the page where the counter is to be inserted function start() {displayCountdown(setCountdown(month,day,hour,min,tz),lab);} loaded(lab,start); // Countdown Javascript // copyright 20th April 2005, 1st November 2009 by Stephen Chapman // permission to use this Javascript on your web page is granted // provided that all of the code in this script (including these // comments) is used without any alteration // you may change the start function if required var pageLoaded = 0; window.onload = function() {pageLoaded = 1;} function loaded(i,f) {if (document.getElementById && document.getElementById(i) != null) f(); else if (!pageLoaded) setTimeout('loaded(\''+i+'\','+f+')',100); } function setCountdown(month,day,hour,min,tz) {var m = month; if (month=='*') m = 0; var c = setC(m,day,hour,tz); if (month == '*' && c < 0) c = setC('*',day,hour,tz); return c;} function setC(month,day,hour,tz) {var toDate = new Date();if (day.substr(0,1) == '+') {var day1 = parseInt(day.substr(1));toDate.setDate(toDate.getDate()+day1);} else{toDate.setDate(day);}if (month == '*')toDate.setMonth(toDate.getMonth() + 1);else if (month > 0) { if (month <= toDate.getMonth())toDate.setFullYear(toDate.getFullYear() + 1);toDate.setMonth(month-1);} if (dow >0) toDate.setDate(toDate.getDate()+(dow-1-toDate.getDay())%7); toDate.setHours(hour);toDate.setMinutes(min-(tz*60));toDate.setSeconds(0);var fromDate = new Date();fromDate.setMinutes(fromDate.getMinutes() + fromDate.getTimezoneOffset());var diffDate = new Date(0);diffDate.setMilliseconds(toDate - fromDate);return Math.floor(diffDate.valueOf()/1000);} function displayCountdown(countdn,cd) {if (countdn < 0) document.getElementById(cd).innerHTML = "Building Completed"; else {var secs = countdn % 60; if (secs < 10) secs = '0'+secs;var countdn1 = (countdn - secs) / 60;var mins = countdn1 % 60; if (mins < 10) mins = '0'+mins;countdn1 = (countdn1 - mins) / 60;var hours = countdn1 % 24;var days = (countdn1 - hours) / 24;document.getElementById(cd).innerHTML = days+' days and '+hours+' : '+mins+' : '+secs;setTimeout('displayCountdown('+(countdn-1)+',\''+cd+'\');',999);}} Thanks in advance. And Merry Christmas!!!!! Thauwa
×
×
  • 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.