thefunkman Posted November 2, 2007 Share Posted November 2, 2007 Hey, let me start by saying my knowledge of php is exactly = 0 so if anything i state is extremely noobish please forgive me, the guy who usually writes my scripts cant do it atm. Im looking to get a script that will show one of 2 status' in text form on a page (most likely in an iframe). I want the status to be able to be changed by hitting a button located directly below it. eg: This orange text will be displayed and below it, the button. (-BUTTON-) And when i press the button, it changes to: This green text will be displayed and below it, the button. (-BUTTON-) NOW! This i have been told is really easy, BUT! i want it to be able to stay on the current specified status even after the page is refreshed or accessed at a different time. Now if this requires sql stuff then it will suck, but im hoping theres some php that can be split into 2 files and one can be updated by the other based on the current status it contains. Is this possible??? Heres a better example: It starts as this... Then when the button is clicked: And it stays like that whether refreshed or revisited later... Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 2, 2007 Share Posted November 2, 2007 you can use sessions http://php.net/manual/en/ref.session.php Quote Link to comment Share on other sites More sharing options...
thefunkman Posted November 2, 2007 Author Share Posted November 2, 2007 um.. wat are sessions? Like i said i dont know anything about php, so names of functions are gonna confuse me lol Is it easy to do something like this? OH also! It has to be able to show that status specified for anyone else viewing it. If it simply stored in a cookie then itll be only for my computer, when i want anyone that sees it to be able to know the status... Quote Link to comment Share on other sites More sharing options...
thefunkman Posted November 2, 2007 Author Share Posted November 2, 2007 please anyone? Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 2, 2007 Share Posted November 2, 2007 This looked easy but is not, anyway I got this one <?php $done = FALSE ; $text = "This is default"; if(isset($_REQUEST['check'])) { $text = "This is green"; $done = TRUE ; $mycss = "css_green"; } if(isset($_REQUEST['check2'])) { $text = "This is orange"; $done = FALSE ; $mycss = "css_orange"; } ?> <style type="text/css"> <!-- .css_green { font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; color: #66CC33; } .css_orange { font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; color: #FF9933; } --> </style> <table width="261" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <form name="check" method="post"> <tr> <td width="261" height="112" valign="top" class="<?=$mycss?>"><?=$text?></td> </tr> <tr> <? if ($done != TRUE) { ?> <td height="76" valign="top"> <input name="check" type="submit" id="check" value="Change Status" /> <input type="hidden" name="hide" value="1" /> </td> <? } else { ?> <td height="76" valign="top"> <input name="check2" type="submit" id="check" value="Change Status" /> <input type="hidden" name="hide" value="2" /> </td> <? } ?> </tr> </form> </table> Quote Link to comment Share on other sites More sharing options...
thefunkman Posted November 2, 2007 Author Share Posted November 2, 2007 dude this is great, and exactly how i pictured it, its just it doesnt keep the status if i look at in a diff browser or close and reopen it... It only shows the defualt then i have to set the status again... How can i make it so when i set the status no matter where i view it from, diff comp, tab or browser, it stays the same until i change it again...?? Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 2, 2007 Share Posted November 2, 2007 Then you will have to use Sql to stored the value if you want it available on multiple computers Quote Link to comment Share on other sites More sharing options...
ignace Posted November 2, 2007 Share Posted November 2, 2007 yep, like rajiv said you need sql + you would like to use accounts, so that the colors are unique to every account, so you won't be fighting over the internet about what color the webpage should have Quote Link to comment Share on other sites More sharing options...
thefunkman Posted November 2, 2007 Author Share Posted November 2, 2007 can anyone here help me? im not a coder, i usually get someone else to do my codes for me, im more of a graphics artist. If anyone can help me ith this id be really thankful Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 3, 2007 Share Posted November 3, 2007 Why not use an AJAX call to a php script that writes to a flat file? Then, call up the flat-file, read it to determine current status.. Works on all browsers, no cookies, no sql, just basic php knowledge and a little AJAX on the side. (AJAX calls to a php script without going to a new page, imagine the process of submitting a form without actually doing so). Quote Link to comment Share on other sites More sharing options...
thefunkman Posted November 3, 2007 Author Share Posted November 3, 2007 ...can anyone write that for me ? Itd be awesome if so Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 3, 2007 Share Posted November 3, 2007 Of the top of my head... O_o ajax_button.js //Global XMLHttpObject variable function request() { var req = null; if (typeof XMLHttpRequest != "undefined") req = new XMLHttpRequest(); if (!req && typeof ActiveXObject != "undefined") { try { req=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { try { req=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e2) { try { req=new ActiveXObject("Msxml2.XMLHTTP.4.0"); } catch (e3) { req=null; } } } } return req; } var span = document.getElementById("status_span"); function update_status() { req1 = request(); if (req1==null) { alert ("Your browser does not support AJAX!"); return; } req1.onreadystatechange=change_status; currtime = new Date().getTime(); req1.open("GET","update.php?time="+currtime,true);//you may want to most likely put this file above the public_html so script can still access, but people can't req1.send(null); } function change_status(){ if(req1.readyState==4) { if(req1.responseText){//returned true, so we update, else we alert an error if(span.style.color == "orange"){//orange text to green text span.innerHTML = "show green text"; span.style.color = "green"; } else {//green text to orange text span.innerHTML = "show orange text"; span.style.color = "orange"; } } else { window.alert("I'm sorry, we encountered an error with the processing, please try again later."); } } } This code above will handle the AJAX. update.php <?php if($_GET['update']){//it's true, else it's false $file=fopen("status.txt",'r'); while($line = fgets($file)){//while we can still read the file $line=trim($line);//remove the line endings list($color,$message) = explode(':',$line);//$string[0] = $user, etc... } if($color == "orange"){$color = "green";$message = "green text here";} else {$color = "orange";$message="orange text here";} $file=fopen("status.txt",'w'); $contents[] = "$color:$message\n"; foreach($contents as $data){ fwrite($file,$data); } fclose($file); return true; ?> php page that has the html <script type='text/javascript' src='ajax_button.js'> <?php //use php to get the current span status echo '<span id="status_span" style="color:orange;">this is orange text</span>'; ?> <input type="button" onclick="update_span();" value="Change Button"> Quote Link to comment Share on other sites More sharing options...
thefunkman Posted November 4, 2007 Author Share Posted November 4, 2007 I pasted all of those codes into notepad and saved them as the right file (except the last which i placed in dreamweaver), but when i visit status.html that was made with the last thing and nothing shows up... is there a special way i have to view it or set it up? Thanks alot btw, i really appreciate your help Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 4, 2007 Share Posted November 4, 2007 You should see the span showing up with dreamweaver, must mean something's wrong with dreamweaver, if it can't handle a simple php echo? o_o Quote Link to comment Share on other sites More sharing options...
thefunkman Posted November 4, 2007 Author Share Posted November 4, 2007 i tried putting the last code into notepad and saving it as php and html, aswell as in dreamweaver, neither show up, i uploaded it to my webserver and ran both, neither show up... i dont know why :S Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 4, 2007 Share Posted November 4, 2007 Upload all three onto your webserver. ajax_button.js - 1st update.php - 2nd status.php - 3rd status.txt - 4th green:green text here Run status.php and see if you see ANYTHING at all. Quote Link to comment Share on other sites More sharing options...
thefunkman Posted November 4, 2007 Author Share Posted November 4, 2007 nope just a blank page, nothing at all... Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 4, 2007 Share Posted November 4, 2007 Can I see it? So I can figure out what's happening? :-o Quote Link to comment Share on other sites More sharing options...
thefunkman Posted November 4, 2007 Author Share Posted November 4, 2007 see wat? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.