FireFox! The PHP Forum Loans and Credit
Panama Web Design for Hire Free Insurance Quotes!
Web Hosting Advertise Here $10 a Month Designer Children
Never Pay Taxes Again HGH Domain name registration
Web Hosting and Dedicated Servers Insurance Affordable web-hosting


HomeWatched TopicsRegisterSearchDirectory
FAQMemberlistUsergroupsLog inStoresItemsBank
Google

Reply to topic Page 1 of 1
Inserting more than one value from a row in a drop down menu
Message  

Reply with quote
Post Inserting more than one value from a row in a drop down menu 
I would like to also retrieve manufacturer and serial number when I submit the form showing the computer model in a FAVORITES pulldown list:

<select name="model" style="width: 300px;">
<?

$query=mysql_query("SELECT * FROM laptop WHERE model='$model' and

favorite='favorite'") or die(mysql_error());

while ($row = mysql_fetch_array($query)) {
$j = mysql_num_fields($query);
        for($i=0;$i<$j;$i++) {
            $k = mysql_field_name($query,$i);
            $$k = $row[$k];

        }
echo "<option value =\"$row[model]\">$row[model] </option>\n";


}
?>
</select>

When I submit this form, I want to also insert, the $make and $serial of the laptop from the $row[$k] and use only one drop down, currently I am using 3 menus to get the 3 pieces of data from the same row. This is to reduce entering repetitve data on frequently used laptop models, thanks.

View user's profile Send private message

Reply with quote
Post  
You could do
Code:

<select name="model" style="width: 300px;">
<?

$query=mysql_query("SELECT * FROM laptop WHERE model='$model' and

favorite='favorite'") or die(mysql_error());

while ($row = mysql_fetch_array($query)) {
echo "<option value =\"".$row[model]."_".$row[manufacturer]."_".$row[serial]."\">$row[model] $row[manufacturer] $row[serial]</option>\n";
}
?>
</select>


And then you could retreive that information on the next page by doing

$row = explode("_", $model);

Model is $row[0]
Manufacturer is $row[1]
Serial is $row[2]

View user's profile Send private message

Reply with quote
Post Still doesn't work 
This code displays all of the values in the drop down, but when I echo on the next page I only get data back from row[o] which is model, maker and serial. row[1] and row[2] are empty, this code is how I first attempted to pull data, but had to abandon due to no data in the 2 values, thanks.

View user's profile Send private message

Reply with quote
Post  
Can you show me your database structure please?

View user's profile Send private message

Reply with quote
Post I sent you a private message in response 
Check your email

View user's profile Send private message

Reply with quote
Post Maloid is "THE MAN" 
Thanks Maloid, I decided to open up one of the many books I have on PHP and SQL ("MyPHP, SQL, Apache - All in One") and found the EXPLODE () function. I replaced your undescores with dashes as shown in the book example and it works PERFECTLY - Now by choosing "Laptops" I can store the "serial number" and "Manufacturer" without actually displaying the information in the drop-down menu, only the laptop name. Even if the row had much more information, I can collect that info by making the value as many string values I like and have the user only see what's display between the brackets!!! > < ...

echo "<option value =\"".$row[laptop]."-".$row[manufacturer]."-".$row[serial]."-".$row[model number]."\">$row[laptop] <option>\n";

THANK YOU MALOID!

View user's profile Send private message
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
  



Google

FireFox! The PHP Forum Loans and Credit
Panama Web Design for Hire Free Insurance Quotes!
Web Hosting Advertise Here $10 a Month Designer Children
Never Pay Taxes Again HGH Domain name registration
Web Hosting and Dedicated Servers Insurance Affordable web-hosting


Web Design by PlatinumShore.com & Web Hosting by TradeWebHosting.com