PHP Variable in mySQl Statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SYLVESTER
Forum Newbie
Posts: 2
Joined: Fri Apr 27, 2007 5:34 pm

PHP Variable in mySQl Statement

Post by SYLVESTER »

Hi

Can anyone tell me if its possible to combine a php variable & an sql statement

I have a standard SQl selct statement such as "Select * from table"
the following lines of code then results in a php variable such as
$totalnumber_rows table blah blah

how can I select the primary key from a table that corresponds to the row number returned above.

cheers folks

Tim
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

Unless I'm simply not understanding you, your SQL statement needs to be altered a bit, e.g.

Code: Select all

SELECT column1, column2 FROM table WHERE ID= {PHP_VARIABLE}
The `ID` field mentioned is your PRIMARY KEY.

Is that what you're looking for?
SYLVESTER
Forum Newbie
Posts: 2
Joined: Fri Apr 27, 2007 5:34 pm

PHP Variable in mySQl Statement

Post by SYLVESTER »

Thats almost what I'm aiming at,

based in what u said I have now got my SQL statement as follows

Code: Select all

$query_rstruehighestID = "select itineraryID From itinerary where rownumber ="{$totalRows_rshighestID}
cheers again

Tim
Post Reply