minik_07 Posted February 9, 2007 Share Posted February 9, 2007 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 More sharing options...
Anders Moen Posted February 9, 2007 Share Posted February 9, 2007 <?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 More sharing options...
minik_07 Posted February 9, 2007 Author Share Posted February 9, 2007 thanks mate. it works prefect! Link to comment Share on other sites More sharing options...
MrAdam Posted February 9, 2007 Share Posted February 9, 2007 by the way ... e.g. i have 6 tables in my database:ID, AUTHOR, DESCRIPTION, AGERANGE, EMAIL, TITLE, CONTENTthey are called "fields", not "tables". Link to comment Share on other sites More sharing options...
Anders Moen Posted February 9, 2007 Share Posted February 9, 2007 thanks mate. it works prefect!No problem :)And as MrAdam said, you don't have 6 tables to display that. You have 1 table, with 6 fields.Good luck further Link to comment Share on other sites More sharing options...
minik_07 Posted February 9, 2007 Author Share Posted February 9, 2007 <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 More sharing options...
MrAdam Posted February 9, 2007 Share Posted February 9, 2007 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 More sharing options...
Anders Moen Posted February 10, 2007 Share Posted February 10, 2007 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 More sharing options...
justsomeguy Posted February 14, 2007 Share Posted February 14, 2007 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now