Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2007

    Unanswered: PHP Variable in mySQl Statement


    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


  2. #2
    Join Date
    Mar 2007
    The total rows might not correspond to a primary key that exists. I would advise against doing this.
    e.g. you have 20 rows in your table, but the first id in your set is 27 (because you deleted records up to that point previously).
    So, you could be attempting to get the primary key (id) 20 which doesn't match any of the records you have.

    Maybe you need to explain better what you are attemping to do...

    Please post ALL of your PHP code.

  3. #3
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    if you want the numbe rof rows affected then theres a real handy MySQL function or MySQLi method which can return the correct value. There are two variants, one I think is called mysql_num_rows which works for select statements, there is another one for other statements insert, update, replace & delete.. have a look at the reference and then trawl through the functions on the side panel to get a flavour of what MySQl can do for you. if you are using MySQLi then do a search for that on the site
    Last edited by healdem; 04-30-07 at 06:46.
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts