Jump to content

How to grab data and display by using a php link


ger_mac74

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...
Link to comment
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 :)
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.