how can i display the datas from the mysql table except last one row? i need to display all the records except last one. can u guys please help me out!!!
Here's some example code: $query = mysql_query("SELECT * FROM tbl"); // our query $num = mysql_num_rows($query); // see how many there are $exlast = $num - 1; // take one away from total $query = mysql_query("SELECT * FROM tbl LIMIT ".$exlast.""); // this is our query.. now you can display the data however you want! PHP: Hope this helps.
$query = mysql_query("SELECT * FROM tbl"); // our query for($i=1;$i<mysql_num_rows($query);$i++) { $thisResult = mysql_fetch_array($query); echo $thisResult['date_or_whatever_fieldname_you_need']; } PHP:
<? $link = mysql_connect("localhost", "mysql_user", "mysql_password"); mysql_select_db("database", $link); $result = mysql_query("SELECT * FROM table1", $link); $num_rows = mysql_num_rows($result); if ($numrows) { $result2 = mysql_query("SELECT * FROM table1 limit 0,$numrows-2", $link); ......//print all in loop } ?> Regards Alex
i dont want to display the last one and i want the datas to be shorted in descending order except last one...
$query = mysql_query("SELECT * FROM tbl"); // our query $num = mysql_num_rows($query); // see how many there are $exlast = $num - 1; // take one away from total $query = mysql_query("SELECT * FROM tbl ORDER BY something DESC LIMIT ".$exlast.""); // this is our query.. now you can display the data however you want! while($row = mysql_fetch_array($query)) { print $row['table_column_name_here']; } PHP:
THIS CODE DISPLAYS THE LAST DATA ALSO, i dont wanna show the last one. Can you please help me out?? mY code is this : <? include 'connect.php'; $query = mysql_query("SELECT * FROM articles"); $num = mysql_num_rows($query); $exlast = $num - 1; $query = mysql_query("SELECT * FROM articles ORDER BY a_id DESC LIMIT ".$exlast.""); while($row = mysql_fetch_array($query)) { $id = $row["a_id"]; $header = ucwords($row["header"]); $short = $row["short"]; $full = $row["full"]; $pic = $row["pic"]; $date = $row["a_date"]; echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td width=\"1%\"><img src=\"images/bull_dot.gif\" border=\"0\"></td> <td width=\"99%\" style=\"padding-left:5px;\"><a href=\"morearticles.php?id=$id\" class=\"ln\">$header<br></td> </tr> </table>"; } mysql_free_result($query); ?> PHP:
<? include 'connect.php'; $rowsquery = "select count(*) as count from articles"); $rowsresult = mysql_query($rowsquery); $rowscount = mysql_fetch_array($rowsresult); $rows = $rowscount["count"]; $row--; $query = "select * from articles order by a_id desc limit $rows"; while($row = mysql_fetch_array($query)) { $id = $row["a_id"]; $header = ucwords($row["header"]); $short = $row["short"]; $full = $row["full"]; $pic = $row["pic"]; $date = $row["a_date"]; echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td width=\"1%\"><img src=\"images/bull_dot.gif\" border=\"0\"></td> <td width=\"99%\" style=\"padding-left:5px;\"><a href=\"morearticles.php?id=$id\" class=\"ln\">$header<br></td> </tr> </table>"; } mysql_free_result($query); ?> PHP: You've got alot of really redundant code in there though, you should clean it up.
Minor correct to the code I posted: change $row--; PHP: to $rows--; PHP: How many rows are in your table? What's the URL that this is running on? It might help if we actually see it.
well it again shows the last one also.. there are 4 rows but this code exclude the first row i.e id=1 and displays the last row i.e row =4
Actually it should be showing the last row, I just looked over the logic here. The query is pulling the articles in order of their ID from greatest to least and leaving out the last one. But I'm betting the table is lined up in the opposite order like this: 1 2 3 4 5 So our query is telling it to output it in this order 5 4 3 2 1 And since we're telling it to drop the last record, it should be dispalying: 5 4 3 2 Try this: <? include 'connect.php'; $firstquery = "select a_id from articles order by a_id desc limit 1"); $firstresult = mysql_query($firstquery); $lastrow = mysql_fetch_array($firstresult); $lastrowid = $lastrow[0] $query = "select * from articles where a_id != $lastrowid order by a_id desc"; while($row = mysql_fetch_array($query)) { $id = $row["a_id"]; $header = ucwords($row["header"]); $short = $row["short"]; $full = $row["full"]; $pic = $row["pic"]; $date = $row["a_date"]; echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td width=\"1%\"><img src=\"images/bull_dot.gif\" border=\"0\"></td> <td width=\"99%\" style=\"padding-left:5px;\"><a href=\"morearticles.php?id=$id\" class=\"ln\">$header<br></td> </tr> </table>"; } mysql_free_result($query); ?> PHP:
shows this errror: Parse error: parse error, unexpected T_VARIABLE in a.php in this LINE $query = "select * from articles where a_id != $lastrowid order by a_id desc";
Oops, minor error. It's actually a few lines above it. T_VAR errors occur when a character is out of place. Go up to $firstquery = and delete the ) at the end of the line.
NO NEED TO SHOUT! Perhaps you can explain your point more precise and more clearly. After all, this isnt paid work. This is me volunteering to help you - it's not compulsory - I think you've forgotten that.
i already deleted that ) but the problem occured due to lost of ; in $lastrowid = $lastrow[0] i corrected it and also added mysql_query in front of $query = "select * from articles where a_id != $lastrowid order by a_id desc"; i think i m getting lil bit of php codes now...LOL if i got any problem then will contact you later... ANYWAYS, THANKS A LOT BRO... TAKE CARE
yeah bro i have that in mind.. i didnt mean to say like that but u think like that.. SORRY for INCONVINIENCE THANKS A LOT FOR YOUR HELP