Jump to content

get field by column name?


Nothadoth

Recommended Posts

Hi,

 

I have set up my database so that there are 3 sizes (A5, A4, A3). There is a price and quantity for each - so the column names are:

a5_price, a5_qty, a4_price, a4_qty, a3_price, a3_qty

 

In a form the user submits the size they want and it returns $size and $qty to add it to the cart. I want to query the database and get the quantity field which contains $size (so a3_qty for example) and then retrieves the current stock. How can I do this?

 

At the moment I tried

$sql = "SELECT pd.pd_id, pr.a3_qty, pr.a4_qty, pr.a5_qty, pr.postcard_qty
        FROM tbl_product pd, tbl_print pr
		WHERE pd.pd_id = $productId AND pr.pd_id = $productId";
$result = dbQuery($sql);
extract($row);
if (strstr($a3_qty, $ct_pd_size)) {
	$currentStock = $a3_qty;
	} elseif (strstr('$a4_qty', '$ct_pd_size')) {
	$currentStock = $a4_qty;
	} elseif (strstr('$a5_qty', '$ct_pd_size')) {
	$currentStock = $a5_qty;
	}

 

Obviously that doesnt work as it is searching the contents of the field. How can I make it search the field name and then return the contents?

 

Thank you.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.