Jump to content

Display Database


minik_07

Recommended Posts

I am making a fan fic section on my website and i want to know if it is possible to display information from a database.e.g. i have 6 tables in my database:ID, AUTHOR, DESCRIPTION, AGERANGE, EMAIL, TITLE, CONTENThow to i make it so that the page is viewfanfic.php?id=1and it will display

<div id="middle"><div class="post"><div class="postheader">  <h1>TITLE</h1></div>  <div class="postcontent"><p>Written by <a href="EMAIL">AUTHOR</a></p><center><hr width="400"></center><p>CONTENT</p>  </div><div class="postfooter"></div></div>

Link to comment
Share on other sites

<?php$con = mysql_connect("localhost","username","password");if (!$con)  {  die('Could not connect: ' . mysql_error());  }mysql_select_db("db_name", $con);$result = mysql_query("SELECT * FROM table_name ORDER BY id");echo "<table>";while($row = mysql_fetch_array($result))  {echo "<tr>";echo "<td>";echo " ";echo "</td>";echo "<td>";echo "<h1>" . $row['title'] . "</h1>";echo "</td>";echo "</tr>";echo "<tr>";echo "<td>";echo "Published by";echo "</td>";echo "<td>";echo "<a href=\"mailto:" . $row['email'] . "\">" . $row['author'] . "</a>";echo "</td>";echo "</tr>";echo "<tr>";echo "<td>";echo " ";echo "</td>";echo "<td>";echo "" . $row['content'] . "";echo "</td>";echo "</tr>";  }echo "</table>";mysql_close($con);?>

Pretty simple really :)Hope you get it. For each thing you wanna display you write:echo "Hello! " . $row['name_on_thing_in_table'] . "";

Link to comment
Share on other sites

<div id="middle"><div class="post"><div class="postheader">  <h1>TITLE</h1></div>  <div class="postcontent"><p>Written by <a href="EMAIL">AUTHOR</a></p><center><hr width="400"></center><p>CONTENT</p>  </div><div class="postfooter"></div></div>

sorry to bother you but is there any way it could be used in the DIV tags like above?

Link to comment
Share on other sites

certainly...

// connect to database ..// submit query ..while($row = mysql_fetch_array($result)) {print '<div id="middle"><div class="post"><div class="postheader">  <h1>' .$row['title']. '</h1></div>  <div class="postcontent"><p>Written by <a href="mailto:' .$row['email']. '">' .$row['author']. '</a></p><center><hr width="400"></center><p>' .$row['content']. '</p>  </div><div class="postfooter"></div></div>';}

Link to comment
Share on other sites

sorry to bother you but is there any way it could be used in the DIV tags like above?
Yes, you can use div's instead, but one thing: when you take something out of a database it's tabular data (td) which is gonna be placed in tables.
Link to comment
Share on other sites

You can place data wherever you want. If I get a picture out of the database, I'll put it smack next to a div, and maybe even throw in a little <hr> action. It's just data.. the terminology in a database calls it a table but that doesn't mean you must display the data in a table format.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...