Jump to content

Archived

This topic is now archived and is closed to further replies.

ger_mac74

How to grab data and display by using a php link

Recommended Posts

Hi i am new to php.
Can anyone help me finish off this? Here is what I have put together so far. When someone clicks on say the '10th century articles' link my webpage I want to connect to the database and then grab whatever articles are from the tenth century. The database will have a column called century and in this column I will have tenth, eleventh and so on...depending on what century the article url is about.

<html>
<head><title>List of articles</title></head>
<body>
<h1>List of articles about 10th Century</h1>
<?php
$db = mysql_connect(“localhost”, “username”, “password”);
mysql_select_db(“databasename”, $db);


/// How do I use $_GET method to check if the century in my table states for example“tenth” or “eleventh”
/// etc.


$result = mysql_query(“SELECT * FROM SELECT `articles` WHERE `century` = '".$_GET['century'],"databasename");

?>

<table rules=all>
<thead>
<tr><th>Column1</th><th>Column2</th><th>Column3</th></tr>
</thead>
<tbody>

<?php
While ($myrow = mysql_fetch_row($result))
{printf (“<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n,
$myrow[0], $myrow[1], $myrow[2]);
?>
</tbody>
<.table>
</body>
</html>


On my main page I have an <a href="index.php?century=tenth">10 Century Articles</a>

I have been told I need to name link like this. Can you explain why? Basically what I want to happen is as follows:

Someone visits my page. Click on a link called 'view all articiles that are about the tenth century'. The site will connect to database. select all tenth century articles and then display on website. It will, for example, display in 3 columns ...one for article name one for article url and one for whatever. These columns will also be in database.

Maybe someone could help me out with a snippet of code that I may have wrong or am missing??

Thanks in advance...

Share this post


Link to post
Share on other sites
Try this:

[code]
<html>
<head><title>List of articles</title></head>
<body>
<h1>List of articles about 10th Century</h1>
<?php
$db = mysql_connect(“localhost”, “username”, “password”);
mysql_select_db(“databasename”, $db);


/// How do I use $_GET method to check if the century in my table states for example“tenth” or “eleventh”
/// etc.

$century=$_GET['century'];
$result = mysql_query(“SELECT * FROM `articles` WHERE `century` = '$century'");
?>

<table rules=all>
<thead>
<tr><th>Column1</th><th>Column2</th><th>Column3</th></tr>
</thead>
<tbody>

<?php
While ($myrow = mysql_fetch_row($result))
{printf (“<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n,
$myrow[0], $myrow[1], $myrow[2]);
?>
</tbody>
<.table>
</body>
</html>
[/code]


Think that should do the job your looking for :)

Share this post


Link to post
Share on other sites

×

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.