SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    Brasil
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post PHP database management

    I'm having a problem with something in the batadase I think with this code I'm not being able to show all the authors in my database:
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>JMS</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <B>Manage Authors</B>
    <P align="center"><a href="mngnewauthor.php">Create new author</a></P>
    <UL>
    <?PHP
        $cnx 
    mysql_connect('localhost','root','');
        
    mysql_select_db('Jokes');
        
    $authors mysql_query("SELECT ID, Name FROM Authors");
        if(!
    $authors){
            echo(
    "<P>Error retrieving authors from database!</P><BR>".
            
    "Error:" mysql_error());
            exit();
        }
        while(
    $authors mysql_fetch_array($authors)){  #This is Line 21#
            
    $id $authors["ID"];
            
    $name $authors["Name"];
            echo(
    "<LI>$name ".
                 
    "[<a href='mngeditauthors.php?id=$id'> Edit </a> | 
                   <a href='mngdeleteauthors.php?id=
    $id'> Delete </a>]");
        }
    ?>
    </UL>
    <P align="center"><a href="indexmngsys.php">Return to front page</a></P>
    </body>
    </html>
    it only show 1 author them the other ones don't apear and there is the message i get in the browser is:Warning: Supplied argument is not a valid MySQL result resource in c:\estudar\seguindo livro\indexmngsys.php on line 21.

  2. #2
    SitePoint Addict devil cat's Avatar
    Join Date
    Apr 2003
    Location
    Reno
    Posts
    344
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have the line written as

    Code:
    while($authors = mysql_fetch_array($authors)) {
    You need to change the name of the variable that is supposed to hold the array to something like:

    Code:
    while($authors2 = mysql_fetch_array($authors)) {
    By using the same name, you are losing your query.

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    Brasil
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok thanks that was it !!!


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
  •