View sql data in html tables

Status
Not open for further replies.

azamkandy

New Member
Messages
32
Reaction score
0
Points
0
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++;
}
?>
 

Anna

I am just me
Staff member
Messages
11,751
Reaction score
581
Points
113
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.
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
Or do

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

galaxyAbstractor

Community Advocate
Community Support
Messages
5,508
Reaction score
35
Points
48
Also

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

should be

PHP:
$username='*cpanelusername*_*databaseusername*';
$password='*databasepassword*';
$database='*cpanelusername*_*databasename*';

(unless you are already using it but censored it out)
 

azamkandy

New Member
Messages
32
Reaction score
0
Points
0
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:
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:
Also

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

PHP:
$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:

Jarryd

Community Advocate
Community Support
Messages
5,534
Reaction score
43
Points
48
Hello, don't put * * around the username etc... it should be this:

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

azamkandy

New Member
Messages
32
Reaction score
0
Points
0
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 ???
 
Status
Not open for further replies.
Top