Closed Thread
Results 1 to 5 of 5

Thread: Php

  1. #1
    Ultra Techie murdocsvan is on a distinguished road murdocsvan's Avatar
    Join Date
    Jun 2007
    Location
    Surrey, UK
    Posts
    853

    Default Php

    Hey, all i need to do is show all the information in an MySQL table in an HTML table, regardless of the number of rows. How would i code this?

    Thanks in advance.


  2. #2

  3. #3
    Ultra Techie murdocsvan is on a distinguished road murdocsvan's Avatar
    Join Date
    Jun 2007
    Location
    Surrey, UK
    Posts
    853

    Default Re: Php

    Okay here is my code:

    PHP Code:
    <?php

    session_start
    ();

    //Check user is logged in in first place
    if(!isset($_SESSION['user']))
        {
        
    header("location:******");
        }

    //Stores mysql login details
    $host="localhost"// Host name 
    $sql_username="*****"// Mysql username 
    $sql_password="*****"// Mysql password 
    $db_name="*****"// Database name 
    $tbl_name="admin"// Table name 

    //mysql Connect variable
    $con mysql_connect("$host","$sql_username","$sql_password");

    //Query to retrieve information
    $query "SELECT * FROM admin";
    $result mysql_query($query,$con);

    echo 
    "<table border='1'>";
    echo 
    "<td><th>Username</th></tr>";
    echo 
    '<form action="user_delete.php" method="post">';
    // keeps getting the next row until there are no more to get
    while($row mysql_fetch_array($result))
        {
        
    // Print out the contents of each row into a table
        
    echo "<tr><td>";
        echo 
    $row['id'];
        echo 
    "</td></tr>";
        echo 
    "<tr><td>"
        echo 
    $row['username'];
        echo 
    "</td><td>";
        echo 
    '<input type="button" value="" />';
        echo 
    "</tr></td>";
        } 

    echo 
    "</form></table>";
    ?>
    But for some reason it returns an error on the line:

    PHP Code:
    while($row mysql_fetch_array($result)) 
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/vmrgjdq/public_html/test/users.php on line 29
    Can anyone help?

    Thanks.
    Last edited by murdocsvan; 05-13-2009 at 12:23 PM.

  4. #4
    Wizard Techie CrazeD will become famous soon enough CrazeD will become famous soon enough CrazeD's Avatar
    Join Date
    Feb 2006
    Location
    Maine
    Posts
    3,733

    Default Re: Php

    PHP Code:
    $result mysql_query($query,$con); 
    Change this line to

    PHP Code:
    $result mysql_query($query,$con) or die (mysql_error()); 
    And post back the message.

    Intel Q9400 | Gigabyte EP45-UD3P | G.Skill 2x2GB DDR2 1000 | XFX HD5870

    Need website help? PM me!

  5. #5
    Ultra Techie murdocsvan is on a distinguished road murdocsvan's Avatar
    Join Date
    Jun 2007
    Location
    Surrey, UK
    Posts
    853

    Default Re: Php

    It said "No Database selected", because i forgot to put in:

    PHP Code:
    //Database select
    mysql_select_db($db_name$con); 
    So i put it in and it works. Thanks a lot!


Closed Thread

Similar Threads

  1. A Guide to Installing Apache, PHP, MySQL, and PHPMyAdmin on Windows
    By CrazeD in forum Programming Discussions
    Replies: 25
    Last Post: 05-10-2010, 12:31 PM
  2. How echo works in PHP
    By Osiris in forum Programming Discussions
    Replies: 0
    Last Post: 03-04-2009, 07:34 AM
  3. PHP - what it does and what it doesn’t
    By Osiris in forum Programming Discussions
    Replies: 1
    Last Post: 02-16-2009, 03:09 PM
  4. Wev Development: How does PHP work?
    By Osiris in forum Programming Discussions
    Replies: 1
    Last Post: 01-08-2009, 03:31 PM
  5. Removing PHP For Increased Download Speed
    By Rex100 in forum Programming Discussions
    Replies: 4
    Last Post: 07-21-2008, 02:49 PM

Posting Permissions

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