MySQL+PHP select one row

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert Chares

    MySQL+PHP select one row

    Hello,

    I'm sure it has been asked a thousand times before, but still:

    How can I access a particular row in my MySQL table via PHP?
    The background is just to update the values of one row in the table via
    a html form with the old values already filled in.
    What I tried so far ist sth like this:

    $row=mysql_quer y('SELECT * FROM names WHERE ID=$entry');
    for ($i = 0; $i < mysql_num_field s($row); $i++)
    {
    echo("<td>$row[$i]</td>\n");
    }

    The mistake should be that mysql_query does not return a vector, but
    still a table...

    Does anybody have a good idea how to solve that problem?

    Thx
    Robert

  • Karl Heinz Marbaise

    #2
    Re: MySQL+PHP select one row

    Hi Robert,
    [color=blue]
    > I'm sure it has been asked a thousand times before, but still:[/color]
    That's correct ;-)[color=blue]
    > How can I access a particular row in my MySQL table via PHP?
    > The background is just to update the values of one row in the table via
    > a html form with the old values already filled in.
    > What I tried so far ist sth like this:
    >
    > $row=mysql_quer y('SELECT * FROM names WHERE ID=$entry');
    > for ($i = 0; $i < mysql_num_field s($row); $i++)
    > {
    > echo("<td>$row[$i]</td>\n");
    > }
    >
    > The mistake should be that mysql_query does not return a vector, but
    > still a table...
    >[/color]
    You should use:

    $h = mysql_query ('...') or die ('SQL Failed!')
    $aRow = mysql_fetch_ass oc ($h);

    Take a deeper look into


    Kind Regards.
    Karl-Heinz

    --
    Dipl.Ing.(FH) Karl Heinz Marbaise | www.marbaise.org
    Jabba Dabba Dooh ;-) | ICQ# 135949029

    Comment

    • Matthias Esken

      #3
      Re: MySQL+PHP select one row

      Robert Chares <robert.chares@ s1999.tu-chemnitz.de> wrote:
      [color=blue]
      > $row=mysql_quer y('SELECT * FROM names WHERE ID=$entry');[/color]

      This won't work. Use

      $row=mysql_quer y("SELECT * FROM names WHERE ID=$entry");

      Have a look at the difference of "single quoted" and "double quoted" at
      http://www.php.net/manual/en/language.types.string.php.

      Regards,
      Matthias

      Comment

      Working...