Jump to content

MA06

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

MA06's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi Guys, I think this is a complex discount. I have 2 tables in mysql say product1 and product2, with the following characteristics: [b]product1 table[/b] p1id......price 1............20 2............30 3............40 [b]product2 table[/b] p2id.......price........p1id 101.........10............1 102.........20............1 103.........70............1 201.........80............2 202.........6..............2 203.........4..............2 301.........10............3 302.........40............3 303.........30............3 where p1id is a foreign key in product2 table. [b]Problem[/b] [b]1)[/b] I have a calculate price function in php, what i want to do is if a person purchases any 2 items from product2 table with the same p1id key e.g. 101 + 102 or 101 +103 not 101 + 201, reduce the price of each of the 2 items by 10%. [b]2)[/b] Also if they purchase 3 items with the same p1id then reduce the price of each of the 3 items by 15%. Here is the calculate function i have, WHERE $IDS is a variable with the id of the purchased item. Th code just calculates the prices at the moment: [code] function calculate_price($cart) {   // sum total price for all items in shopping cart   $price = 0.0;   if(is_array($cart))   {     $conn = db_connect();     foreach($cart as $IDS => $qty)     {         $query = "select Price from Product1 where p1id='$IDS' union select Price from Product2 where p2id='$IDS'";       $result = mysql_query($query);       if ($result)       {         $item_price = mysql_result($result, 0, 'price');         $price +=$item_price*$qty;       }     }   }   return $price; } [/code] I am not sure how to apply these 2 discounts to the code, any help would be very much appreciated. Thanks in advance, MA.
  2. Thanks for the help Poirot, managed to solve problem. MA.
  3. Hi Guys, I get the error call to a member function on a non-object in...line 106. It seems to give me the error everytime i use the symbol:[b] ->[/b] for instance on line 106 its: [b]$item = $result->fetch_object();[/b] and in another line:[b]$result = $conn->query($query);[/b] which i took out it gave me the same error, so i assume its something to do with the symbol: [b]->[/b]. Any ideas what the problem is, thanks in advance for any help. MA.
  4. Result! Thanks guys the problem was it was not reading the id field from the table, iviewedthe source on the html page and the there was a blank before the .jpg. So i defined a variable $Field1 to equal the id and then placed the variable in the previous code: while($newArray=mysql_fetch_array($result)) $Field1=$newArray['ID']; $img = "<img src='images/". $Field1. ".jpg' border='0'/>"; echo $Field1; MA.
  5. Hi Andy, Thanks for the reply the thing is i could not figure out how to put the image code within the table as when i try to place the code [b]echo "$Name = '<img src=\'images/'.($result['ID']).'.jpg\' border=0 />'"; [/b] i get an error. So i tried to get a variable[b] $Name[/b] to equal getting the image and then displaying that variable within the table as [b]$Field1.[/b] How can i write it within an echo statement, thank you MA.
  6. Hi guys, The problem seems to be with this line:[b] $Name = '<img src=\'images/'.($result['ID']).'.jpg\' border=0 />';[/b] The thing is it displays the table with the details i.e. name, price and description but not the associated image, also no error is given. The images are all JPEG's and each name of an image is the same as the id field in a mysql table which is the primary key of the table. Any ideas in what i may be doing wrong, or any solutions, Thanks, MA.
  7. Hi all, I have some images in an images folder, which i have titled the same as primary keys in a products table. e.g. image name= "001". ID in a mySQL table = 001. What i want to do is display all images with their related fields in a table. I have not managed to do this so far, here is what i got. Everything else displays except the images. [code] echo "<TABLE border=1 cellpadding=5>"; echo "<TR><TD></TD><TD>Name</TD><TD>Price</TD><TD>Description</TD></TR>"; //Loop and format the data in a HTML table while($newArray=mysql_fetch_array($result))     {         $Name = '<img src=\'images/'.($result['ID']).'.jpg\' border=0 />';     $Field1=$newArray[$Name ];     $Field2=$newArray['Name'];     $Field3=$newArray['Price'];     $Field4=$newArray['Description'];     echo "<TR><TD> $Field1 </TD><TD> $Field2 </TD><TD> $Field3 </TD><TD> $Field4 </TD></TR>";     } [/code] Thanks in advance for any help. MA.
×
×
  • 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.