SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist cturner01's Avatar
    Join Date
    Jun 2006
    Location
    My computer
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Display a selected row?

    I need to display a selected id row from a query string in a textbox and just displayed by printing that row. The row originately comes from a database. Can someone please tell me how I can do this? Thanks in advance.
    Here is the code that I am working with:
    PHP Code:
    require "config.php";

    // one SQL statement
    $query'SELECT * FROM diary_contents WHERE `id` >=1 ORDER BY id LIMIT 0,1';

    // one call to mysql_query
    $rmysql_query($query) OR die('Query error: ' .mysql_error());

    // one call to fetch the resultset
    $rowmysql_fetch_assoc($r);

    // display the date info
    echo $row['selectDay'].'-'.$row['selectMonth'].'-'.$row['selectYear'].'<br />';

    // display the record data
    echo '<textarea name="diary_entry" cols="30" rows="5" id="diary_entry">'.$row['diary_entry'].'</textarea>';

    mysql_close(); 

  2. #2
    SitePoint Guru aamonkey's Avatar
    Join Date
    Sep 2004
    Location
    kansas
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
      require "config.php";
      
      
    // find id (this assumes that the query string variable is named 'id':
      
    $id $_GET['id'];
      
      
    // make sure id is a number, and safeguard against an sql injection
      
    if (!preg_match("#^\d+$#"$id)) {
          
    // maybe die here with an error
      
    }
      
      
    // one SQL statement
      
    $query"SELECT * FROM diary_contents WHERE id = '$id'";
      
      
    // one call to mysql_query
      
    $rmysql_query($query) OR die('Query error: ' .mysql_error());
      
      
    // make sure the entry was found
      
    if (mysql_num_rows($r) == 0) {
        
    // no entry with this id found, maybe die here with an error
      
    }
      
      
    // one call to fetch the resultset
      
    $rowmysql_fetch_assoc($r);
      
      
    // display the date info
      
    echo $row['selectDay'].'-'.$row['selectMonth'].'-'.$row['selectYear'].'<br />';
      
      
    // display the record data
      
    echo '<textarea name="diary_entry" cols="30" rows="5" id="diary_entry">'.$row['diary_entry'].'</textarea>';
      
      
    mysql_close(); 


Bookmarks

Posting Permissions

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