Closed Thread
Results 1 to 9 of 9

Thread: View sql data in html tables

  1. #1
    azamkandy is offline x10Hosting Member azamkandy is an unknown quantity at this point
    Join Date
    Sep 2009
    Posts
    32

    Post View sql data in html tables

    I have created a sql database and also a webpage to view the data's on a table everything works well.
    But my problem is I just wanted to show only last 10 rows of the sql data not all the rows

    Cheers!!!!


    php at the moment i use is:
    <?
    $username='1111';
    $password='11111';
    $database='data_base';

    mysql_connect(localhost,$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");
    $query="SELECT * FROM dedications";
    $result=mysql_query($query);

    $num=mysql_numrows($result);

    mysql_close();

    ?>

    <?php
    $i=0;
    while ($i < $num) {

    $f1=mysql_result($result,$i,"name");
    $f2=mysql_result($result,$i,"song");
    $f3=mysql_result($result,$i,"ded_for");

    ?>
    <table width="596" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="14" height="60">&nbsp;</td>
    <td width="20" bgcolor="#FFFFFF" class="style30" style="BORDER-bottom: #333333 1px solid">&nbsp;</td>
    <td width="146" bgcolor="#FFFFFF" class="style30" style="BORDER-bottom: #333333 1px solid"><span class="style30" style="BORDER-bottom: #333333 1px solid"><?php echo $f1; ?></span></td>
    <td width="147" bgcolor="#FFFFFF" class="style30" style="BORDER-bottom: #333333 1px solid"><span class="style30" ><?php echo $f2; ?></span></td>
    <td width="269" bgcolor="#FFFFFF" class="style30" style="BORDER-bottom: #333333 1px solid"><span class="style30" ><?php echo $f3; ?></span></td>


    <?php
    $i++;
    }
    ?>

  2. #2
    Anna's Avatar
    Anna is offline I am just me Anna is a name known to allAnna is a name known to all
    Join Date
    Aug 2007
    Location
    Sweden
    Posts
    6,569

    Re: View sql data in html tables

    I think that if you change this: $query="SELECT * FROM dedications";
    into this: $query="SELECT * FROM dedications LIMIT=10"; you should get only the 10 last rows from the database.
    Do you have trouble reaching your site?
    Check here first: News and Announcements


    Don't forget that x10hosting has an irc server as well. Come and join the fun
    server: irc.x10hosting.com, main channel: #x10hosting
    There's a lot helpful users there if need help building your site

  3. #3
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,227

    Re: View sql data in html tables

    Or do

    $query="SELECT * FROM dedications LIMIT 10 ASC";
    $result=mysql_query($query);
    Neil Hanlon | x10Hosting Support Representative
    Neil[at]x10hosting.com
    █ I'm always happy to help. Just ask a question in Free Hosting
    Terms of Service IRC

  4. #4
    galaxyAbstractor's Avatar
    galaxyAbstractor is offline Community Advocate galaxyAbstractor is on a distinguished road
    Join Date
    Oct 2007
    Location
    Land of Null and Insanity
    Posts
    5,495

    Re: View sql data in html tables

    Also

    PHP Code:
    $username='1111';
    $password='11111';
    $database='data_base'
    should be

    PHP Code:
    $username='*cpanelusername*_*databaseusername*';
    $password='*databasepassword*';
    $database='*cpanelusername*_*databasename*'
    (unless you are already using it but censored it out)

  5. #5
    azamkandy is offline x10Hosting Member azamkandy is an unknown quantity at this point
    Join Date
    Sep 2009
    Posts
    32

    Thumbs down Re: View sql data in html tables

    Quote Originally Posted by LadyAnna View Post
    I think that if you change this: $query="SELECT * FROM dedications";
    into this: $query="SELECT * FROM dedications LIMIT=10"; you should get only the 10 last rows from the database.
    thanks ladyanna but it didnt work

    Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in
    Edit:
    Quote Originally Posted by leafypiggy View Post
    Or do

    $query="SELECT * FROM dedications LIMIT 10 ASC";
    $result=mysql_query($query);

    Cheers leafpiggy !!

    getting an error::

    Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/username/public_html/req_upd1.php on line 258

    line 258 on php is:
    $num=mysql_numrows($result);
    Edit:
    Quote Originally Posted by vigge_sWe View Post
    Also

    PHP Code:
    $username='1111';
    $password='11111';
    $database='data_base'
    should be

    PHP Code:
    $username='*cpanelusername*_*databaseusername*';
    $password='*databasepassword*';
    $database='*cpanelusername*_*databasename*'
    (unless you are already using it but censored it out)
    Cheers Vigge!!

    my webpage is showing up the database so no probs with that everything works fine , and also I tried the way you said it's coming up with,

    Warning: mysql_connect() [function.mysql-connect]: Access denied for user '*username*_*abc*'@'starka.x10hosting.com' (using password: YES) in /home/username/public_html/req_upd1.php on line 252
    Unable to select database
    Last edited by azamkandy; 10-13-2009 at 09:35 AM. Reason: Automerged Doublepost

  6. #6
    Jarryd's Avatar
    Jarryd is offline Community Advocate Jarryd has a spectacular aura about
    Join Date
    Nov 2007
    Location
    Darwin, Australia
    Posts
    5,531

    Re: View sql data in html tables

    Hello, don't put * * around the username etc... it should be this:

    Code:
    $username='cpanelusername_databaseusername';
    $password='databasepassword';
    $database='cpanelusername_databasename';
    Jarryd Sullivan
    █ 888-X10-9668 - Jarryd[@]x10hosting.com
    x10Hosting - Giving Away Hosting Since 2004

  7. #7
    azamkandy is offline x10Hosting Member azamkandy is an unknown quantity at this point
    Join Date
    Sep 2009
    Posts
    32

    Re: View sql data in html tables

    Quote Originally Posted by Hellsheep View Post
    Hello, don't put * * around the username etc... it should be this:

    Code:
    $username='cpanelusername_databaseusername';
    $password='databasepassword';
    $database='cpanelusername_databasename';
    Cheers!!

    But how to get the last 10 rows ???

  8. #8
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,633

    Re: View sql data in html tables

    Quote Originally Posted by azamkandy

    But how to get the last 10 rows ???


    I answered your other post.
    Nothing is always absolutely so.

  9. #9
    azamkandy is offline x10Hosting Member azamkandy is an unknown quantity at this point
    Join Date
    Sep 2009
    Posts
    32

    Thumbs up Re: View sql data in html tables

    Quote Originally Posted by descalzo View Post
    I answered your other post.

    cheers!!! descalzo

    problem solved here:::

    http://forums.x10hosting.com/program...tml#post586725

    ;)
    Last edited by azamkandy; 10-13-2009 at 11:34 AM.

Closed Thread

Similar Threads

  1. Hybrid's HTML Lessons
    By Hybrid in forum Tutorials
    Replies: 18
    Last Post: 11-28-2009, 02:12 PM
  2. [IPB] Contiguous Board Index
    By phenetic in forum Tutorials
    Replies: 5
    Last Post: 09-18-2005, 10:31 AM
  3. What is XML!
    By wizeman in forum Tutorials
    Replies: 6
    Last Post: 08-27-2005, 12:05 PM
  4. Catch data from HTML page
    By sizzla in forum Scripts & 3rd Party Apps
    Replies: 2
    Last Post: 06-15-2005, 04:48 AM

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
x10hosting free hosting for the masses
dedicated servers