Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2011
    Posts
    24
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Unhappy PHP MYSQL SELECT Handling problems

    Hi,

    I have been trying to display my data from two columns onto a table in html. I am using myhosting.com and I am new to their system. I had just started thinking I had gotten a grasp on how to use their PHPMyAdmin and MYSQL system but then I got an odd error. Can you please tell me if this is their system's fault or the result of my bad coding?

    Thanks and offered solutions will result in many thanks!

    Here is the code:

    PHP Code:
    <?php
                
            $Server
    ="xxxx";
            
    $User="xxxx";
            
    $Password="xxxx";
            
    $Database="xxxx";

    $connection mysql_connect($Server$User$Password);
    if(!
    $connection){
        die(
    "Couldn't Connect" mysql_error());
    }
    echo 
    "Connection Working";

    mysql_select_db($Database$connection);

    $query "SELECT * FROM Test";

    $table mysql_query($query,$connection);

    echo 
    "<table border='1'>";
    echo 
    "<tr> <th>id</th> <th>name</th> </tr>";
    // keeps getting the next row until there are no more to get
    while($row mysql_fetch_array$query )) {
        
    // Print out the contents of each row into a table
        
    echo "<tr><td>"
        echo 
    $row['id'];
        echo 
    "</td><td>"
        echo 
    $row['name'];
        echo 
    "</td></tr>"
    }  

    echo 
    "</table>";
                
    ?>
    and here is the error:

    Connection Working Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /usr/local/pem/vhosts/113282/webspace/httpdocs/show.php on line 23
    id name
    Resource id #3

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,862
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Change
    PHP Code:
    $table mysql_query($query,$connection); 
    to
    PHP Code:
    $table mysql_query($query,$connection) or die(mysql_error()); 
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Tags for this Thread

    Posting Permissions

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