Jump to content


Photo

Query Restructure


  • This topic is locked This topic is locked
2 replies to this topic

#1 tomato

tomato
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 10 May 2006 - 08:32 PM

I'm "TRYING" utilizing the following code and can't seem to get a valid resource.

$result = mysql_query('SELECT sum(product.itemprice * cart.quantity) as price FROM ".TABLE_PREFIX."p827_shop_product product, ".TABLE_PREFIX."p827_shop_cart cart WHERE cart.session=\''.$this->get_sess().'\' AND product.pid = cart.pid');


My table names have a prefix and are named differently

".TABLE_PREFIX."p827_shop_product
".TABLE_PREFIX."p827_shop_cart

I've been messing with this for hours would one of you re-write the query or point me to my failure please.
This is beyond my understanding.

Thanks for looking guys.

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 10 May 2006 - 08:51 PM

No need to [a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=93235&st=0&gopid=373090&#entry373090\" target=\"_blank\"]double-post[/a]; an edit would have sufficed.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 tomato

tomato
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 10 May 2006 - 08:56 PM

[!--quoteo(post=373091:date=May 10 2006, 03:51 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ May 10 2006, 03:51 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
No need to [a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=93235&st=0&gopid=373090&#entry373090\" target=\"_blank\"]double-post[/a]; an edit would have sufficed.
[/quote]

Sorry fenway, It was a quick double click, hit stop to add the whole function in the post manuver. I wasn't trying to be a pest ;)


function total()
{
   global $DB;//         Price from the product table and the quntity from the carts table
$query = "SELECT sum(".TABLE_PREFIX."p827_shop_product.itemprice * ".TABLE_PREFIX."p827_shop_cart.quantity) as price FROM ".TABLE_PREFIX."p827_shop_product, ".TABLE_PREFIX."p827_shop_cart WHERE ".TABLE_PREFIX."p827_shop_cart.session=\''.$this->get_sess().'\' AND ".TABLE_PREFIX."p827_shop_product.pid = ".TABLE_PREFIX."p827_shop_cart.pid";

$result = mysql_query($query);
$row = mysql_fetch_array($result);
return $row['price'];
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users