How to use php variables (arrays) in mysql select statements?

Posted by davidconn on Stack Overflow See other posts from Stack Overflow or by davidconn
Published on 2010-04-25T12:57:05Z Indexed on 2010/04/25 13:03 UTC
Read the original article Hit count: 160

Filed under:
|
|
|
|

Hi everybody,

How do you use a php variable (array) inside a mysql select statement?

I am designing an auction site and currently working on a page that lets people view a list of all the current bids for an item. I want to display 3 columns:

  1. amountbid - the amount each bidder has bid for the item (held in tblbid)

  2. bidderid - the id of each bidder who has bid (found in tbluser)

  3. total_positivity_feedback - how many users have left positive feedback for the bidder (calculated from tblfeedback)

To find the 'amount' and the 'bidderid' columns i pass the essayid URL parameter from the previous page. This works fine.

Despite this, i can't display the total_positivity_feedback column for the various users who have made each bid.

My mysql query looks like this:

select
tblbid.bidderid, 
tblbid.amount,
(select count(tblfeedback.feedbackid) from tblfeedback WHERE tblfeedback.writerid = "ARRAY VARIABLE GOES HERE") AS total_positivity_feedback FROM tblbid WHERE tblbid.essayid = $essayid_bids

I assume that the only way to accomplish this is to make the variable contain the bidderid's of those people who bid for that particular essay? I can't seem to work out how to do this tho?!?

Many thanks for your help

© Stack Overflow or respective owner

Related posts about sql

Related posts about php