Jump to content


Photo

How to grab data and display by using a php link


  • Please log in to reply
1 reply to this topic

#1 ger_mac74

ger_mac74
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 06 March 2006 - 08:11 PM

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...

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 07 March 2006 - 09:57 AM

Try this:

<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>


Think that should do the job your looking for :)
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users