FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


pulling data out of a database and putting it on main page





nclemale
i want to pull some data out of my database and put it on my main page of my site as a link.
ie i have forums and i want to pull the latest post data for example the subject and the user who posted it and create it as a link to get that post .

i have been told to select data from the max forum and id but i dont know how to do it
help lol
vinx_18
You may edit this to fit in your field name and table name:

Code:


<?php
include 'config.php';
include 'opendb.php';

$query  = "SELECT name, subject, message,max(date) FROM topic GROUP by date";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
    echo "Name :{$row['name']} <br>" .
         "Subject : {$row['subject']} <br>" .
         "Message : {$row['message']} <br><br>";
}

include 'closedb.php';
?>
nclemale
cant get that to work . i edited it fine . but putting it in with a script that has sql code in already beats me. i get an error on my last line with is <?php lmao .

cheers anyway
coeus
<?php is the beginning tag of some php code. In order to put php code on a webpage it has to be between '<?php' and '?>'

You need some sort of language between the database and your website. Something like PHP. Seeing that you arn't familure with php, I don't think messing with databases would be a good idea for you yet. If you are just looking for someone to code something for you then you will need to be more descriptive then 'I want to place a link to stuff on my webpage from a database' We don't know where your site is hosted and whether it is on php or .net or anything else, also what kind of database are you connecting to?
Fire Boar
Try this:
Code:
<?php
$user = 'myname'; // CHANGE THIS TO YOUR MYSQL USERNAME
$pass = 'mypass'; // CHANGE THIS TO YOUR MYSQL PASSWORD
$dbn = 'somedatabase'; // CHANGE THIS TO YOUR MYSQL DATABASE NAME
$host = 'localhost'; // Chances are you won't need to change this.

mysql_connect($host, $user, $pass) or
die('Unable to connect to the MySQL server.');
mysql_select_database($dbn);

$query  = 'SELECT name, subject, message,max(date) FROM topic GROUP by date';
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
    echo 'Name :'.$row['name'].' <br>' .
         'Subject : '.$row['subject'].' <br>' .
         'Message : '.$row['message'].' <br><br>';
}

mysql_close();
?>


That should do.
manum
both of them work quiet well cheers...
Related topics
Text color of main page
Broken link on main page
Can I install Coppermine in DirectAdmin?
Better Browser Support for Main Page
question : how to display random image in main page?
My main page doesnt load
Changed my main page....not showing
a script to modify data through a web page with php
xoops main page
JScript Sliding Text Areas ( Adobe's main page sample)
Login link in the main page itself
vBulletin installation: Files upload, Database setup
Pagination of data from an UNION query
[Bug | Improvment ] FriHOST Main Page | Game Development S.
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.