-
Posts
885 -
Joined
-
Last visited
-
Days Won
1
Posts posted by phppup
-
-
I've been refreshing ALL day.
I have a dropdwon menu coded as follows"
echo "<tr><td>";
echo "<select name='roastturkey'>";
echo "<option value='0.00' " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">0</option>";
echo "<option value='1.00' " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">1</option>";
echo "<option value='2.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">2</option>";
echo "<option value='3.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">3</option>";
echo "<option value='4.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">4</option>";
echo "<option value='5.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">5</option>";
echo "<option value='6.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">6</option>";
echo "<option value='7.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">7</option>";
echo "<option value='8.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">8</option>";
echo "<option value='9.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">9</option>";
echo "<option value='10.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">10</option>";
echo " </select></td><td rowspan='2'>ROAST TURKEY</span></td><td rowspan='2'>7.00 LB</span></td> ";
And a database quierie after connecting is:
$result = mysql_query("SELECT * FROM pass WHERE id = '4' ")
I want it to get the info from the database so that the option that is saved in the database will be new default when the form page is loaded, and will SHOW in the form.
If I don't change it to the previous info it will update the database with the default option rather then the actual option when re-submitted.
Record 4 has 10 as the value for the 'roastturkey'.
I've changed it to record 5 which has a value of 5, but the dropdown does NOT change.
-
-
OKAY, the dropdown is now populated with number from 0 thru 10.
The database quierie after connecting is:
$result = mysql_query("SELECT * FROM pass WHERE id = '4' ")
Record 4 has 10 as the value for the 'roastturkey'.
I've changed it to record 5 which has a value of 5,
Yet the dropdown STILL does NOT change to reflect the stored value in the database :-(
-
That was the first thinig I did. I mean, I'm not totally ignorant. I switched a few numbers and this is what I have now:
echo "<tr><td>";
echo "<select name='roastturkey'>";
echo "<option value='0.00' " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">0</option>";
echo "<option value='1.00' " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">1</option>";
echo "<option value='2.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">2</option>";
echo "<option value='3.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">3</option>";
echo "<option value='4.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">4</option>";
echo "<option value='5.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">5</option>";
echo "<option value='6.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">6</option>";
echo "<option value='7.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">7</option>";
echo "<option value='8.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">8</option>";
echo "<option value='9.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">9</option>";
echo "<option value='10.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">10</option>";
echo " </select></td><td rowspan='2'>ROAST TURKEY</span></td><td rowspan='2'>7.00 LB</span></td> ";
The drop down shows as follows:
0
1
selected="selected">2
selected="selected">3
selected="selected">4... etc.
And the database quierie after connecting is:
$result = mysql_query("SELECT * FROM pass WHERE id = '4' ")
Record 4 has 10 as the value for the 'roastturkey'.
I've changed it to record 5 which has a value of 5, but the dropdown does NOT change.
-
Nope!
It's populating the dropdown with 10 lines of: selected="selected">0
Not the value that the table has.
-
oops! maybe not.
But I think I may be able to fix it... keep you posted.
-
EUREEEEEEKAH!!!! IT WORKED!!!! *hugs & kisses* JUMPS for JOY!!!!!
-
I'm plugging it in now.
-
So am I abandoning Pikachu??
I modified:
echo " <option value='1.00'>1 <?php echo $array['roastturkey'] == 0 ? 'selected="selected"' : ''>0</option>";
To this
echo "<option value='1.00' $array['roastturkey'] == 0 ? 'selected="selected"' : ''>0</option>";
BUT NOT WORKING!
-
Pasted it in with my code from Reply #4. I have a feeling I'm duplicating ECHOs because I received error message for first line of modified code.
Also, I need to ensure that unselected items maintain their default. Is there a way to incorporate that?
-
Now I'm BEGINNING to see it!
And UNDERSTAND what you mean.
Is the code that Scootstah offered earlier applicable as a simpler means?
Meanwhile, let me hardcode ONE selection just to see that it works.
-
Beginning to see where this might work.
But if my INITIAL default is ZERO, do i change the code to: $selected=0
Or does =1 get the code moving?
-
There are MANY, but let's work with CUTLETS. (i'd list them all but it's lunchtime and we'd all get hungry.. LOL)
By the way, I want to thank you all for your patience. I do appreciate it.
[Can you comment on MargateSteve's code. It seems short and concise, but seems to have an unknown variable.]
-
Not sure WHERE TO PLACE the code now.
-
ALSO, with the above code, how would I select MY default value, so that an item that had no selection would be recorded as the default.
-
OKAY! Now I'm beginning to understand how PHP could have made my life easier. However, I am WAY beyond that. All the code has already been handwritten and the form has already submitted data INTO the DB.
Now I have generated the identical form that comes up when I make a request for data FROM the DB.
My difficulty at this point is that no VALUES are being placed in the form.
ALL the data is generated INTo the database with HTML dropdown menus.
I want it to get the info from the database so that the option that is saved in the database will be new default when the page is loaded, and will SHOW in the form.
If I don't change it to the previous info it will update the database with the default option rather then the actual option.
-
This looks like it's establishing a PHP dropdown menu, not takiing the data from my DB, or placing it in my HTML dropdown (the same one that submitted it) from my HTML form.
I can change the form to PHP, but I prefer the HTML dropdown for design purposes.
-
I'll do it manually (as long as it works) but I don't know what to write.
How can I do it dynamically if every item has a different field name and I need the SUBMITTED value for EVERY item to become the NEW DEFAULT with the intention of the form being used to update data.
example: customer ordered 1 chicken cutlet and now wants 3 instead. I want to view the original order, verify that ONE was ordered, change the selection to 3, and UPDATe the record.
If this cannot be handled in one page, I will gladly do it it two steps to avoid complications
-
I've got this in my query:
$result = mysql_query("SELECT * FROM pass WHERE id = 4 ")
or die(mysql_error());
$row = mysql_fetch_array( $result );
And inside my form:
echo "cutlets <select name='chixcutlet' value=''> ";
echo " <option value='0.00' selected> --- </option>";
echo " <option value='1.00'> 1 </option>";
echo " <option value='2.00'> 2 </option>";
echo " <option value='3.00'> 3 </option>";
echo " </select>";
My form comes up fine, but no values are extracted from the DB.
I want it to get the info from the database so that the option that is saved in the database will be new default when the page is loaded.
If I don't change it to the previous info it will update the database with the default option rather then the actual option.
-
I'm trying to pull up an identical form after submission by using its "id" and ECHO for the form lines.
Question: What is the correct approach for ECHOing an HTML dropdown that is written as:
<select name='chixcutlet' value='' >
<option value='0.00' selected> --- </option>
<option value='1.00'> 1 </option>
<option value='2.00'> 2 </option>
<option value='3.00'> 3 </option>
</select>
I want it to get the info from the database so that the option that is saved in the database will be new default when the page is loaded.
If I don't change it to the previous info it will update the database with the default option rather then the actual option.
-
THANKS.... i'll keep this open and let you know how it works out.
-
So I would have:
$record_id = (isset($_POST['record_id'])) ? $_POST['record_id'] : '';
//check for $record_id emptiness
if(!empty($record_id))
{
"SELECT * FROM mytable WHERE id = $record_id "
}
Is that correct?? Am I missing any brackets or braces??
-
Just storing simple numbers, nothing >20 and only some are in intervals of .5
(ie: for certain items 1.0, 1.5, 2.0, 2.5 etc., and others just whole numbers: 1,2,3,4,5,etc)
-
I am able to view record numbers 22, 84, and 203 by exectuing my PHP script with the correct record ID.
However, what I really want to do is have a simple form whereby I can input the desired record number and have it upload the data for me.
I imagine it would look something like this:
"SELECT * FROM mytable WHERE id = specified_record"
but need a bit of guidance to get the HTML input fields 'name' into the PHP request.
retrieving an HTML dropdown select
in PHP Coding Help
Posted
OKAY, so I managed to get a 5 in as the dropdown default for record number 4.
Now I changed my quiery to record number 5, but the dropdown seems STUCK on 10.
The value for record 4 for 'roastturkey' is FIVE.
Any ideas???