Dynadot

Display database contents within HTML

Spaceship Spaceship
Watch
Impact
3
Alright so I've been trying to get PHP to display some data from a table in my database. I want it to look like this: http://i53.tinypic.com/2hzjo5i.png

but all im getting is this: http://i56.tinypic.com/1znoc45.jpg

and this is the PHP portion of my code
Code:
<?php

$queryTitle = mysql_query("SELECT title FROM posts");
$queryDate = mysql_query("SELECT date FROM posts");
$queryBody = mysql_query("SELECT body FROM posts");

while($rowTitle = mysql_fetch_array($queryTitle)){
  echo "<h2>" . $rowTitle['title'] . "</h2>";
  echo "<br />";
  }
while($rowDate = mysql_fetch_array($queryDate)){
	echo "<h4>" . $rowDate['date'] . "<h4>";
	echo "<br />";
}

?>

Thanks,
Archey
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Try this.

PHP:
<?php

$query = mysql_query("SELECT * FROM posts");

while($row = mysql_fetch_array($query)){
  echo "<h2>" . $row['title'] . "</h2>";
  echo "<br />";
  echo "<h4>" . $row['date'] . "<h4>";
  echo "<br />";
  }

?>

PHP processes code from top to bottom unless a class or function is called thus creating a block effect for your code. Also the way you were requesting to pull info from the database is by calling specific information, or in other words ordered data. Using the * denote allows you to pull any information at request without the need for extra coding. if you need more help with this pm me
 
0
•••
nice, that worked, but they are displaying Ascending from 1-## i want them to descend from ##-0. Anyone know what i have to do?

EDIT: nvm, i found it, just had to add
Code:
ORDER BY id DESC
to my query
 
Last edited:
0
•••
Not a problem.. if you need help with anything else just hit me up
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back