/    Sign up×
Community /Pin to ProfileBookmark

Drop downs that sum together?

Ok, first off this is my first post and I am a TOTAL noob when it comes to php. with that said I am trying to write a site and have stole various snippets online and have gotten certain things to work but the code probably looks hideous.

Basically what I want from this site is the ability to connect to amazon and get pricing updates (I am grabbing computer parts pricing)*this part I have done*

Next, instead of the way that I current have the information shown in tables I would rather have the information in numerous drop down boxes with somebody able to select items from those boxes. After the items are selected I would like to add the totals together on the fly or with a submit button. (I have a feeling I might need Javascript to do this?)

Also I need each drop down to have different items (like 1 drop down would have video card names and prices, the 2nd would have sound card names and prices, etc.) My question here is how do I do this with mysql table? do I need multiple tables to accomplish this?

Anyway thats enough for now and hopefully I was as clear as I could be on what I am looking to do. Here is what I currently have

[CODE]<?php

include “connect.php”;

$getitems=”SELECT itemid,ibsn from amz”;

$getitems2=mysql_query($getitems) or die(“Could not get items”);

while($getitems3=mysql_fetch_array($getitems2))

{

$url=”http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=$acckey&Operation=ItemLookup&ItemId=$getitems3[ibsn]&ResponseGroup=Medium,Offers&Condition=All&MerchantID=Amazon”;

$var=file_get_contents($url);

$pricing=explode(“$”,$var);

$lastindex=sizeof($pricing)-1;

$newprice=$pricing[$lastindex];

$theprice=explode(“.”,$newprice);

$deci=substr($theprice[1],0,2);

$realprice=”$theprice[0].$deci”;

//print “$realprice<br>”;

$updatecron=”Update amz set price=’$realprice’ where itemid=’$getitems3[itemid]'”;

mysql_query($updatecron) or die(“Could not update cron”);

mysql_query(“Delete from bgook”);

}

?>

<?php

$connect = mysql_connect(“localhost”, “games45”, “3000gtgt”) or

die (“Hey, check your server connection.”);

mysql_select_db(“games45_test2″);

$quey1=”select * from amz”;

$result=mysql_query($quey1) or die(mysql_error());

?>

<table border=1 style=”background-color:#F0F8FF;” >

<caption><EM>Current Prices</EM></caption>

<tr>

<th>Item</th>

<th>Price</th>

</tr>

<?php

while($row=mysql_fetch_array($result)){

echo “</td><td>”;

echo $row[‘productname’];

echo “</td><td>”;

echo $row[‘price’];

echo “</td>”;

echo “</tr>”;

}

echo “</table>”;

?>
[/CODE]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@timgtauthorMay 18.2009 — wow, I thought this was gonna be an easy one for the PHP guru's. I guess what I'm asking isn't possible then?
Copy linkTweet thisAlerts:
@timgtauthorMay 18.2009 — let me try to start with something easier.

If i have this code below


[code=php]while ($row=mysql_fetch_array($result)) {

$Price=$row["price"];
$Productname=$row["productname"];
$options.="<OPTION>".$Productname.'</option>';

}
?>
<SELECT NAME=price><?=$options?></SELECT>[/code]




What is the proper syntax to get both $Productname and $Price on the same line in the drop down box? I seem to only be able to show 1 or the other.
Copy linkTweet thisAlerts:
@CharlesMay 18.2009 — Try $options .= "&lt;OPTION&gt;$Productname @ Price&lt;/OPTION&gt;" and like Java, php naming conventions don't capitolize variable names.
Copy linkTweet thisAlerts:
@timgtauthorMay 18.2009 — NICE! that worked, thanks.

Now I just have to figure out how to parse the $price part out of each line that is selected by the user, so they can be added together :mad:
×

Success!

Help @timgt spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...