simpso Posted January 7, 2013 Share Posted January 7, 2013 Hi For whatever reason this dosent seem to be working. Basically im trying to pull the price of an item from the database based on the id number i give the sql. <?php $idno = "1"; $cost = 'select price from products where Id = "$idno"'; ?> Have i missed something? Quote Link to comment Share on other sites More sharing options...
trq Posted January 7, 2013 Share Posted January 7, 2013 Variables are not interpolated within single quotes. Quote Link to comment Share on other sites More sharing options...
scootstah Posted January 7, 2013 Share Posted January 7, 2013 dosent seem to be working. Eh, you're going to have to be a little more descriptive than that. "Doesn't work" isn't going to cut it, there are 100 results that might classify as "doesn't work". Quote Link to comment Share on other sites More sharing options...
dpiearcy Posted January 7, 2013 Share Posted January 7, 2013 What trq is saying is write it like this: $idno = "1"; $cost = "select price from products where Id = $idno"; If you place a echo $cost; beneath that it will display "select price where id=1" Quote Link to comment Share on other sites More sharing options...
dpiearcy Posted January 7, 2013 Share Posted January 7, 2013 What trq is saying is write it like this: $idno = "1"; $cost = "select price from products where Id = $idno"; If you place a echo $cost; beneath that it will display "select price where id=1" But not sure what you're trying to do with this. Seems like you're trying to do a MySql query. Only reason I can think of for a statement like that. You're a long way from doing that with the above. Quote Link to comment Share on other sites More sharing options...
haku Posted January 8, 2013 Share Posted January 8, 2013 (edited) To elaborate: $something = 'hello'; $single_quote_string = 'Look at this: $something'; $double_quote_string = "Look at this: $something"; echo $single_quote_string . '<br />' . $double_quote_string; The output will be as follows: Look at this: $something Look at this: hello Edited January 8, 2013 by haku Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.