Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/88630-getting-db-info-problem/
Share on other sites

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...

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?

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))
?>

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>";
		  ?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.