skbanta Posted January 30, 2008 Share Posted January 30, 2008 I have my php and I know it's getting to the table, but I need to select it and have it appear in a table in reverse chronological order (newest first) with a date and timestamp at the top (very unsure how I'd code the last part). Here's the code I have: <?php $con=mysql_connect("***","***","***") if($con) { die('Problem connecting to the database:'.mysyql_error()); } mysql_select_db("kylban5_banta",$con); $result=mysql_query("SELECT entry FROM politics"); echo "<table border='1'> while($row=mysql_fetch_array($result)); { echo "<tr>"; echo "<td>".$row['entry']."</td>"; echo "</tr> } echo "</table>"; mysql_close($con); ?> I would also like to be able to delete data after a certain amount of time or so, but I can worry about that later. Quote Link to comment https://forums.phpfreaks.com/topic/88630-getting-db-info-problem/ Share on other sites More sharing options...
lilbadger25 Posted January 30, 2008 Share Posted January 30, 2008 I may be misreading what you're asking, but if you're wanting to display your results in reverse order, you'd do this: SELECT entry FROM politics ORDER BY id DESC You'd change the "id" to whatever it is you are basing your order on. Desc is descending. Hope that was what you were asking... Quote Link to comment https://forums.phpfreaks.com/topic/88630-getting-db-info-problem/#findComment-453848 Share on other sites More sharing options...
skbanta Posted January 30, 2008 Author Share Posted January 30, 2008 Thanks, that was one of my problems, but I can't get the data to show up in my page at all much less in a table. It shows up blank where I have that code. Since I am using dreamweaver Templates does it have to be a php template or can I use an html template and just put the php code into the html? Quote Link to comment https://forums.phpfreaks.com/topic/88630-getting-db-info-problem/#findComment-453852 Share on other sites More sharing options...
kts Posted January 30, 2008 Share Posted January 30, 2008 mysql_select_db("kylban5_banta",$con) or die(mysql_error()); make sure its connecting, if so do or die(mysql_error()); after the query as well.... make sure its working Quote Link to comment https://forums.phpfreaks.com/topic/88630-getting-db-info-problem/#findComment-453856 Share on other sites More sharing options...
rlindauer Posted January 30, 2008 Share Posted January 30, 2008 Did you copy/paste that code exactly? You have some syntax errors: <?php $con=mysql_connect("***","***","***") if($con) { die('Problem connecting to the database:'.mysyql_error()); } mysql_select_db("kylban5_banta",$con); $result=mysql_query("SELECT entry FROM politics"); echo "<table border='1'> while($row=mysql_fetch_array($result)); { echo "<tr>"; echo "<td>".$row['entry']."</td>"; echo "</tr> } echo "</table>"; mysql_close($con); ?> You aren't closing your echo statement. And you have a semi-colon after while... <?php echo "<table border='1'>"; while($row=mysql_fetch_array($result)) ?> Quote Link to comment https://forums.phpfreaks.com/topic/88630-getting-db-info-problem/#findComment-453860 Share on other sites More sharing options...
skbanta Posted January 30, 2008 Author Share Posted January 30, 2008 I changed those and now this "; echo " } echo " "; mysql_close($con); ?> shows up in my browser when I open it Quote Link to comment https://forums.phpfreaks.com/topic/88630-getting-db-info-problem/#findComment-453868 Share on other sites More sharing options...
rlindauer Posted January 30, 2008 Share Posted January 30, 2008 There are more syntax errors. Are you using a decent editor? It will highlight your code and you can see the problem. You are missing a closing quote and semi-colon after an echo <?php echo "<td>".$row['entry']."</td>"; echo "</tr>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/88630-getting-db-info-problem/#findComment-453872 Share on other sites More sharing options...
skbanta Posted January 30, 2008 Author Share Posted January 30, 2008 im using dreamweaver, i couldn't even select anything from my db without tables Quote Link to comment https://forums.phpfreaks.com/topic/88630-getting-db-info-problem/#findComment-453876 Share on other sites More sharing options...
skbanta Posted January 30, 2008 Author Share Posted January 30, 2008 any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/88630-getting-db-info-problem/#findComment-453932 Share on other sites More sharing options...
skbanta Posted January 30, 2008 Author Share Posted January 30, 2008 is this bad code? <?php $con=mysql_connect("*********") if($con) { die('Problem connecting to the database:'.mysyql_error()); } mysql_select_db("kylban5_banta",$con); $result=mysql_query("SELECT entry FROM politics ORDER BY id DESC"); $num=mysql_numrows($result); mysql_close(); $1=0; while($i<$num) { $entry=mysql_result($result,$i,"entry"); }?> <table> <tr> <td><? echo $entry; ?></td> </tr> </table> <? $i++; } echo "</table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/88630-getting-db-info-problem/#findComment-453968 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.