Jump to content

keep return to the first select option after refresh button click


zgkhoo

Recommended Posts

<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..

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.