muddy9494 Posted June 8, 2009 Share Posted June 8, 2009 Ok... Well here is the code first of all. <?php include("mysql.php"); $query = "SELECT * FROM website"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['liveblog']. "-" .$row['liveblog_name'] ; echo "<br />"; } ?> Now, it shows the oldest entry first. I want it to show the newest entry first and only show 15 of them. Also here is the code for when i submit it to the database <?php include("mysql.php"); $liveblog = $_POST['liveblog']; $name = $_POST['liveblog_name']; mysql_query("INSERT INTO website (liveblog, liveblog_name) VALUES('$liveblog', '$name' ) ") or die(mysql_error()); include ("addliveblog.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/161321-solved-i-need-to-have-it-show-the-database-entries-in-reverse/ Share on other sites More sharing options...
gevans Posted June 8, 2009 Share Posted June 8, 2009 to limit it to 15 you do the following; SELECT * FROM website LIMIT 15 To get everything in reverse order you need to `ORDER` your query by one of the field values. This is where an id field would come into play. Your only options at the moment are to order by liveblog or liblog_name, but these wont give you the desired effect. I'd recommend adding a third field to the table `id` of type INT which is a primary key, and auto increments. Quote Link to comment https://forums.phpfreaks.com/topic/161321-solved-i-need-to-have-it-show-the-database-entries-in-reverse/#findComment-851273 Share on other sites More sharing options...
muddy9494 Posted June 8, 2009 Author Share Posted June 8, 2009 Ok, i got the limit part, but the auto incriment. how can i do that? can you give me some sample code to use? heres my form code <form id="form1" name="form1" method="post" action="postblog.php"> <label>liveblog_name <input type="text" name="liveblog_name" /> </label> <p> <label>liveblog <input type="text" name="liveblog" /> </label> </p> <p> <label>Post <input type="submit" name="Submit" value="Submit" /> </label> </p> </form> Quote Link to comment https://forums.phpfreaks.com/topic/161321-solved-i-need-to-have-it-show-the-database-entries-in-reverse/#findComment-851276 Share on other sites More sharing options...
gevans Posted June 8, 2009 Share Posted June 8, 2009 I was refering to you mysql table. You've already made a table with 2 fields; liveblog and liveblog_name. You want to make a third, try this if you like; ALTER TABLE `website` ADD `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY If you use phpmyadmin, use it to run an sql query with the above code. Quote Link to comment https://forums.phpfreaks.com/topic/161321-solved-i-need-to-have-it-show-the-database-entries-in-reverse/#findComment-851279 Share on other sites More sharing options...
radi8 Posted June 8, 2009 Share Posted June 8, 2009 put a button to fetch the next set of 15, and the sql code can be researched here: http://dev.mysql.com/doc/refman/5.1/en/select.html Quote Link to comment https://forums.phpfreaks.com/topic/161321-solved-i-need-to-have-it-show-the-database-entries-in-reverse/#findComment-851280 Share on other sites More sharing options...
gevans Posted June 8, 2009 Share Posted June 8, 2009 put a button to fetch the next set of 15, and the sql code can be researched here: http://dev.mysql.com/doc/refman/5.1/en/select.html He didn't ask for pagination, read the OP Quote Link to comment https://forums.phpfreaks.com/topic/161321-solved-i-need-to-have-it-show-the-database-entries-in-reverse/#findComment-851282 Share on other sites More sharing options...
radi8 Posted June 8, 2009 Share Posted June 8, 2009 Well, that's how I interpreted it, sorry. Maybe he should be more explicit. Quote Link to comment https://forums.phpfreaks.com/topic/161321-solved-i-need-to-have-it-show-the-database-entries-in-reverse/#findComment-851283 Share on other sites More sharing options...
gevans Posted June 8, 2009 Share Posted June 8, 2009 Now, it shows the oldest entry first. I want it to show the newest entry first and only show 15 of them. Plenty clear enough for me Quote Link to comment https://forums.phpfreaks.com/topic/161321-solved-i-need-to-have-it-show-the-database-entries-in-reverse/#findComment-851285 Share on other sites More sharing options...
muddy9494 Posted June 8, 2009 Author Share Posted June 8, 2009 Ok, what is wrong with this: <?php //showing live blog include("mysql.php"); $query = "SELECT * FROM website limit 15 ORDER BY id"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['liveblog']. "-" .$row['liveblog_name'] ; echo "<br />"; } ?> error code is: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY id' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/161321-solved-i-need-to-have-it-show-the-database-entries-in-reverse/#findComment-851290 Share on other sites More sharing options...
gevans Posted June 8, 2009 Share Posted June 8, 2009 You have to do things in the correct order SELECT * FROM website ORDER BY `id` LIMIT 15 Also, to get it in the correct direction you'll have to order it descending SELECT * FROM website ORDER BY `id` DESC LIMIT 15 Quote Link to comment https://forums.phpfreaks.com/topic/161321-solved-i-need-to-have-it-show-the-database-entries-in-reverse/#findComment-851291 Share on other sites More sharing options...
muddy9494 Posted June 8, 2009 Author Share Posted June 8, 2009 Yay! Thanks alot guys! Finally! :D:D:D:D:D Quote Link to comment https://forums.phpfreaks.com/topic/161321-solved-i-need-to-have-it-show-the-database-entries-in-reverse/#findComment-851292 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.