Jump to content

[SOLVED] Fetching mySql data


ivatanako

Recommended Posts

do it the other way around. If you want people to see, say, the 1st article you wrote, link them to mysite.com/viewarticle.php?id=1. On viewarticle.php, put at the top:

 

<?php
$article = $_GET['id'];
?>

 

Now, PHP has the article number you want. Then, write:

 

<?php
// Get the article from the table. Change 'tablename' to your table's name.
$sql = 'SELECT * FROM `tablename` WHERE id = "'. $id .'"';
// Query the database
$sqlresult = mysql_query($sql);
while ($row = mysql_fetch_assoc($sqlresult)) {
// Write the code to format your page here.
echo '<b>'. $row['article'] .'</b><br><br>'
}
?>

 

The above code will output in the following:

 

This is article number 1. In here is some article information which I hope you will read, etc. etc.

 

*REST OF PAGE*

Link to comment
Share on other sites

of course, you'll need to connect to the database first (if you don't know how to):

 

<?php
$dbHost = "yourhost";          //Your database host
$dbUser = "username";         //Username for DataBase
$dbPass = "password";         //Password
$dbDatabase = "database";   //Database Name in which you keep articles.

$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");
mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");
?>

Link to comment
Share on other sites

Actually he also asked how to get them.

In order to generate url's of id's of items from a db it's

something like

<?php
$select * from users;";
$query = mysql_query($select);
while ($row = mysql_fetch_array($query) {
echo $row['firstname'] . '<a href="profileview.php?' . $row['id'] . '" title="user">User</a>';
}
?>

That's just a quick example.

Link to comment
Share on other sites

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.