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)

    Unhappy Displaying the second row only???

    My code is only displaying the second row and not the selected row after selecting the need to be modified row.

    Here is the code for displaying the need to be modified rows:
    PHP Code:
    require "config.php";

        
    $query 'SELECT * FROM diary_contents LIMIT 1';
        
        if (
    $r mysql_query ($query)) {
            
            while (
    $row mysql_fetch_array ($r)) {
                print 
    "{$row['selectDay']}
                
    {$row['selectMonth']}
                
    {$row['selectYear']}<br />\n";
            }
            
        } else {
            die (
    '<p>Could not retrieve the data because: <b>' mysql_error() . "</b>.
            The query was 
    $query.</p>");
        }
        
    $txtquery 'SELECT diary_entry FROM diary_contents LIMIT 1';
    print 
    "Diary entry: ";

        if (
    $r mysql_query ($txtquery)) {
            
            while (
    $row mysql_fetch_array ($r)) {
                print 
    '<textarea name="diary_entry" cols="30" rows="5" id="diary_entry">'.$row['diary_entry'].'</textarea>';
            }
            
        } else {
            die (
    '<p>Could not retrieve the data
            because: <b>' 
    mysql_error() . "</b>.
            The query was 
    $query.</p>");
        }
    mysql_close(); 
    Here is the code for modifing a entry:
    PHP Code:
    require "config.php";

    $query 'UPDATE diary_contents SET diary_entry = '" . mysql_real_escape_string($_POST['diary_entry']) . "' WHERE `diary_entry`='" . $diary_entry . "'';
        
    if (
    mysql_query ($query)) {
        print 
    '<p>The diary entry has been modified. <a href=view.php>Click here</a> to continue.</p>';
    } else {
        print 
    "<p>Could not add the entry because: <b>" mysql_error() .
        
    "</b>. The query was $query.</p>";
    }

    mysql_close(); 
    Thanks in advance.

  2. #2
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,751
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    If you're using LIMIT 1, you will always get one result, so no need to loop through with mysql_fetch_assoc. Also, it seems that your SQL isn't using anything to uniquely identify the particular row you're after.


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
  •