Jump to content

Variable in mysql


simpso

Recommended Posts

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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by haku
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.