Using a variable in a select statement

Hi I am trying to select a row of data in my database using a select statement but want to use a where clause to select a row that matches a pre-defined variable. the code I am using looks like this:

$counter = 1;

$result = mysqli_query($link, ‘SELECT txtBagName FROM tblBag where lngBagID = $counter’);

while ($row =mysqli_fetch_array($result))
{
$names=$row[‘txtBagName’];
}

the problem I get is that when I run this I get a message saying something like unknown column $counter.

My aim with this is so that I can display different rows of information in a database when a user clicks a next button.
I am guessing that there is a very simple way to do this and I am barking up the wrong tree with what I am doing so any help would be appreciated. (I am completely new to php and have just started reading Kevin Yank’s book!)

many thanks
Hayden

double quotes around the query not single quotes.

thanks that worked! thought it might be something simple! a question - can I increment a variable from within an HTML anchor tag using php?


// create nos 1-10, say..
$range = range(1,10);

foreach( $range as $r ) // for each of those numbers, n
  echo "<p id = 'my_P_$r'>paragrah text</p>" ; //append to my_P_n


NB dont start variable names with numbers, true in JS too.

be careful making assumptions about “id” values for the next row

if a row has been deleted, its id value does not get re-used, there will be a “gap” in the numbers

thanks for the advise! I know there will need to be something more added to check that the record exists - just not sure how to write it yet!