Jump to content

retrieving an HTML dropdown select


phppup

Recommended Posts

  • Replies 73
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Took out the single quote:

echo        "<option value='0.00'  " . ($array['roastturkey'] == 0.00 ? 'selected="selected"' : '') . ">0</option>";

echo        "<option value='1.00'  " . ($array['roastturkey'] == 1.00 ? 'selected="selected"' : '') . ">1</option>";

echo        "<option value='2.00' " . ($array['roastturkey'] == 2.00 ? 'selected="selected"' : '') . ">2</option>";

echo        "<option value='3.00' " . ($array['roastturkey'] == 3.00 ? 'selected="selected"' : '') . ">3</option>";

echo        "<option value='4.00' " . ($array['roastturkey'] == 4.00 ? 'selected="selected"' : '') . ">4</option>";

echo        "<option value='5.00' " . ($array['roastturkey'] == 5.00 ? 'selected="selected"' : '') . ">5</option>";

echo        "<option value='6.00' " . ($array['roastturkey'] == 6.00 ? 'selected="selected"' : '') . ">6</option>";

echo        "<option value='7.00' " . ($array['roastturkey'] == 7.00 ? 'selected="selected"' : '') . ">7</option>";

echo        "<option value='8.00' " . ($array['roastturkey'] == 8.00 ? 'selected="selected"' : '') . ">8</option>";

echo        "<option value='9.00' " . ($array['roastturkey'] == 9.00 ? 'selected="selected"' : '') . ">9</option>";

echo        "<option value='10.00'  " . ($array['roastturkey'] == 10.00 ? 'selected="selected"' : '') . ">10</option>";

 

result in dropdown still at zero  :-(

 

What else would you test.  AT this point, I'll give you the whole damn thing.. LOL

Link to comment
Share on other sites

What do you see if you just echo out the query (not in selection area)?

echo "{$array['roastturkey'] }";

Are you seeing expected value?

 

//Edit

Here's a little "stand-alone" script.

<?php
$values = range('0.00', '10.00'); 
//for testing//
$array=array('roastturkey' => '5.00');
//
echo "<select name=\"my_field\">\n";
foreach($values as $v) {
echo  "<option value=\"$v\"  " . ($array['roastturkey'] == $v ? 'selected="selected"' : '') . ">$v</option>";
}
echo "</select>\n";
?>

Link to comment
Share on other sites

$result = mysql_query("SELECT * FROM mytest WHERE id = '4' ")

 

and I change the ID accordingly, hoping for a different and accurate result, which hasn't happened.

 

Note: everything is connecting etc, as I have an alternate page WITHOUT the dropdown scenario and it runs fine, echoing all accurate data.

 

I thought this would be an easy way to update info, can you think of a better method in case this issue is unresolveable.  Although I don't think I'm the first to attempt this method.

Link to comment
Share on other sites

$result = mysql_query("SELECT * FROM pass WHERE id = '4' ")

or die(mysql_error());

 

$row = mysql_fetch_array( $result );

 

echo "There are " . $row['roastturkey'] ." servings";  // this verifies that i CAN get the data

 

echo "<table border='1'>";

echo "<tr> <th>Name</th> <th>Comment</th> <th>Email Address</th></tr>";  //took from another table just to get headings and columns

 

 

echo "<tr><td>";

echo "<select name='roastturkey'>";

echo        "<option value='0.00'  " . ($row['roastturkey'] == 0.00 ? 'selected="selected"' : '') . ">0</option>";

echo        "<option value='1.00'  " . ($row['roastturkey'] == 1.00 ? 'selected="selected"' : '') . ">1</option>";

echo        "<option value='2.00' " . ($row['roastturkey'] == 2.00 ? 'selected="selected"' : '') . ">2</option>";

echo        "<option value='3.00' " . ($row['roastturkey'] == 3.00 ? 'selected="selected"' : '') . ">3</option>";

echo        "<option value='4.00' " . ($row['roastturkey'] == 4.00 ? 'selected="selected"' : '') . ">4</option>";

echo        "<option value='5.00' " . ($row['roastturkey'] == 5.00 ? 'selected="selected"' : '') . ">5</option>";

echo        "<option value='6.00' " . ($row['roastturkey'] == 6.00 ? 'selected="selected"' : '') . ">6</option>";

echo        "<option value='7.00' " . ($row['roastturkey'] == 7.00 ? 'selected="selected"' : '') . ">7</option>";

echo        "<option value='8.00' " . ($row['roastturkey'] == 8.00 ? 'selected="selected"' : '') . ">8</option>";

echo        "<option value='9.00' " . ($row['roastturkey'] == 9.00 ? 'selected="selected"' : '') . ">9</option>";

echo        "<option value='10.00'  " . ($array['roastturkey'] == 10.00 ? 'selected="selected"' : '') . ">10</option>";

Link to comment
Share on other sites

I GOT IT!!!!!

 

Noticed that i missed the array in option 10, called it $row, and SUCCESS!

 

Thank you EVERYONE for persevering.

 

If there are any tweaks to my code, please let me know.

 

And if someone can let me know whether I would be BETTER off using arrays, please guide me to the difference of $row versus $array.

 

Thanks sooo much again!

Link to comment
Share on other sites

Normally you would use mysql_fetch_row for grabbing info from one "row" of the table.

$row = mysql_fetch_row( $result );

 

If you are listing a group of rows you would use

while ($row =mysql_fetch_array( $result )){
//and result will loop for each record
}

 

There are other options as well.

Change to use mysql_fetch_row.

Link to comment
Share on other sites

ie:  $meat.... yes, i played with that early on in my PHP endeavors.  everything was so structured, and then I scratched my head and started naming items with names like sasperilla and heebeeegeeebeees.

 

It was confusinig, but it DID work... LOL

 

So in actuality, DB fatigue not withstanding, fetch_array is just a bit more generic, and kinda ensures that it'll locate what the fuction is looking for by casting a wider net, so to speak.

Link to comment
Share on other sites

So, $row = mysql_fetch_array is forcing the DB to do more work than it needs to by scanning the entire DB?

And fetch_row directs it more definitively??

 

Nope. That's not what is different between the different mysql_fetch_xxxxx functions. You need to read the php.net documentation for the functions.

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.