Results 1 to 2 of 2

Thread: How to echo table php+mysql

Hybrid View

  1. #1
    Join Date
    Apr 2014

    How to echo table php+mysql

    Hi guys,
    i need echo first 2 rows of my table with connect to mysql database and get it to html table.
    This code echo all items of my table but i need just 2 rows. Please rewrite my code . Or send to me condition which i can use. THX!

    // Connects to your Database

    mysql_connect($host, $user, $password) or die(mysql_error());
    mysql_select_db("$database") or die(mysql_error());
    mysql_query('SET NAMES UTF8');
    mysql_query('SET COLLATION_CONNECTION=uft8_slovak_ci');
    $query='SELECT * FROM '.$table;/* */
    $result=mysql_query($query) or die(mysql_error($db));

    echo "<table class='table'>


    /*while ($record=mysql_fetch_array($result)
    echo "<tr>";
    echo "<td>".record['name']."</td>";
    echo "<td><img src=".$record['img']."></td>";
    echo "</tr>";

    echo "</table>";
    /* Mysql_close($query);*/

  2. #2
    You can do this by two ways:
    1. You can use LIMIT 0,2 in your query 'SELECT * FROM '.$table.' LIMIT 0,2'
    2. You can also use like this:
    while ($record=mysql_fetch_array($result)
    echo "<tr>";
    echo "<td>".record['name']."</td>";
    echo "<td><img src=".$record['img']."></td>";
    echo "</tr>";

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Recent Articles