zgkhoo Posted October 19, 2007 Share Posted October 19, 2007 <form action=placebet2.php method=post> <text>Please Select The Draw Date</text> <select name=drawnumber>"; //searching for the distinct drawdate $result=mysql_query("SELECT DISTINCT DrawDate FROM result") or die('Query failed: ' . mysql_error()); while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { echo "<option value=$row[DrawDate]>$row[DrawDate]</option>"; } //end of searching for distinct drawdate echo "</select> </br> <input type=submit name=Refresh value=Refresh></input> </form> "; html output source code. Fri 19th Oct,2007 01:06 am <h1>Place Bet2(Available Draw)</h1> <form action=placebet2.php method=post> <text>Please Select The Draw Date</text> <select name=drawnumber> <option value=2007-07-09>2007-07-09</option> <option value=2007-09-09>2007-09-09</option> <option value=2007-07-07>2007-07-07</option> <option value=2007-08-08>2007-08-08</option> <option value=2007-10-10>2007-10-10</option>< /select> </br> <input type=submit name=Refresh value=Refresh></input> </form> eg when i select second option 2007-09-09, after i click the refresh button, then this select box auto jump back to the default or first select option which is 2007-07-09,when i select 2007-07-07,2007-08-08, also same case happen, how to set that it just dun return to the first option..thanks.. Quote Link to comment https://forums.phpfreaks.com/topic/73894-keep-return-to-the-first-select-option-after-refresh-button-click/ Share on other sites More sharing options...
trq Posted October 19, 2007 Share Posted October 19, 2007 You can't. Refresh reloads the page, defaults and all. Quote Link to comment https://forums.phpfreaks.com/topic/73894-keep-return-to-the-first-select-option-after-refresh-button-click/#findComment-372872 Share on other sites More sharing options...
zgkhoo Posted October 19, 2007 Author Share Posted October 19, 2007 but the refresh just a keyword...i can change it to others word... Quote Link to comment https://forums.phpfreaks.com/topic/73894-keep-return-to-the-first-select-option-after-refresh-button-click/#findComment-372875 Share on other sites More sharing options...
trq Posted October 19, 2007 Share Posted October 19, 2007 I didn't even look at your code, just read your question. Try... <?php echo "<option value='{$row['DrawDate']}'" . (isset($_POST['drawnumber']) && $_POST['drawnumber'] == $row['DrawDate']) ? " selected='selected'" : "" . ">{$row['DrawDate']}</option>"; ?> ps: You are aware that html form values need be surrouned by quotes? Your html is invalid. Quote Link to comment https://forums.phpfreaks.com/topic/73894-keep-return-to-the-first-select-option-after-refresh-button-click/#findComment-372879 Share on other sites More sharing options...
zgkhoo Posted October 19, 2007 Author Share Posted October 19, 2007 cant work (isset($_POST['drawnumber']) wat this meant? Quote Link to comment https://forums.phpfreaks.com/topic/73894-keep-return-to-the-first-select-option-after-refresh-button-click/#findComment-372963 Share on other sites More sharing options...
zgkhoo Posted October 19, 2007 Author Share Posted October 19, 2007 echo "<option value='{$row['DrawDate']}'" . (isset($_POST['drawnumber']) && $_POST['drawnumber'] == $row['DrawDate']) ? " selected='selected'" : "" . ">{$row['DrawDate']}</option>"; wat is the ? meant in ur line? Quote Link to comment https://forums.phpfreaks.com/topic/73894-keep-return-to-the-first-select-option-after-refresh-button-click/#findComment-372964 Share on other sites More sharing options...
enoyhs Posted October 19, 2007 Share Posted October 19, 2007 I will try and explain: "?" is shorthand for "if .. else" (Can't find resource for it in net, but I know that that kind of syntax works in Javascript and few other languages) "isset($_POST['drawnumber'])" is function that determine whether a variable is set. Returns false if it isn't. More information here Quote Link to comment https://forums.phpfreaks.com/topic/73894-keep-return-to-the-first-select-option-after-refresh-button-click/#findComment-372969 Share on other sites More sharing options...
zgkhoo Posted October 19, 2007 Author Share Posted October 19, 2007 this line so confusing...so complex.. Quote Link to comment https://forums.phpfreaks.com/topic/73894-keep-return-to-the-first-select-option-after-refresh-button-click/#findComment-372981 Share on other sites More sharing options...
enoyhs Posted October 19, 2007 Share Posted October 19, 2007 I will write it down a bit easier version (a longer one). Orginal: <?php echo "<option value='{$row['DrawDate']}'" . (isset($_POST['drawnumber']) && $_POST['drawnumber'] == $row['DrawDate']) ? " selected='selected'" : "" . ">{$row['DrawDate']}</option>"; ?> <?php echo "<option value='" . $row['DrawDate'] . "'"; if (isset($_POST['drawnumber']) && ($_POST['drawnumber'] == $row['DrawDate'])) { echo " selected='selected'"; } echo ">" . $row['DrawDate'] . "</option>"; ?> I hope this code is a bit clearer. Quote Link to comment https://forums.phpfreaks.com/topic/73894-keep-return-to-the-first-select-option-after-refresh-button-click/#findComment-372994 Share on other sites More sharing options...
zgkhoo Posted October 19, 2007 Author Share Posted October 19, 2007 <? if (isset($_POST['drawnumber']) && ($_POST['drawnumber'] == $row['DrawDate'])) ?> can u explain y u use this? u compare drawnumber with DrawDate ??? ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/73894-keep-return-to-the-first-select-option-after-refresh-button-click/#findComment-373574 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 I would avoid using shorthand if possible. IT will confuse you later on. Quote Link to comment https://forums.phpfreaks.com/topic/73894-keep-return-to-the-first-select-option-after-refresh-button-click/#findComment-373626 Share on other sites More sharing options...
zgkhoo Posted October 20, 2007 Author Share Posted October 20, 2007 wat is shorthand? Quote Link to comment https://forums.phpfreaks.com/topic/73894-keep-return-to-the-first-select-option-after-refresh-button-click/#findComment-373859 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 Shorthand is the method you saw above. Well what you "saw" above the poster must have changed it back to normal code. SHorthand is alright it's just harder to read and confusing for new developers. It's a shortened way of writing php code to allow you to right it faster. However it's ugly to read and hard to newer programmers to understand. So it's not normally recommended. Quote Link to comment https://forums.phpfreaks.com/topic/73894-keep-return-to-the-first-select-option-after-refresh-button-click/#findComment-373937 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.