dcsimg
www.webdeveloper.com
Results 1 to 2 of 2

Thread: How to echo table php+mysql

Hybrid View

  1. #1
    Join Date
    Apr 2014
    Posts
    5

    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!

    <?php
    $host='xxx';
    $user='xxx';
    $password='xxx';
    $database='xxx';
    // 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');
    $table='culture';
    $query='SELECT * FROM '.$table;/* */
    $result=mysql_query($query) or die(mysql_error($db));



    //tabulka
    echo "<table class='table'>
    <tr>

    <th>názov</th>
    <th>Obrázok</th>
    </tr>";


    /*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:
    $i=0;
    while ($record=mysql_fetch_array($result)
    echo "<tr>";
    echo "<td>".record['name']."</td>";
    echo "<td><img src=".$record['img']."></td>";
    echo "</tr>";
    $i++;
    $i==2;
    break;
    };

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