Jump to content

GET method help


ryeman98

Recommended Posts

I don't think I completely understand the GET method...but here is what I want to do.

 

I will be inserting multiple news articles into a database that will display on my website. On the index it'll only show a few sentences and then the rest, people will have to click on a link to get the full story. How can I make it so that they can click and I can just use the GET method to call up the id for the article?

 

(Each article will have an id and a title and I want to display them by the id)

 

Thanks in advance,

Rye

Link to comment
Share on other sites

Are you asking how to create the link and pass the data or get the data from the url on the resulting page?

 

#1 The link should be in the format:

 


<a href="tageturl.php?variable_name1=value1&variable_name2=value2">Link</a>

 

#2 To reference the values passed to the resulting page:

 


SELECT * FROM table_name WHERE field_name = $_GET['variable_name']

Link to comment
Share on other sites

Assuming that www.somesite.com is your site, in the page index.php you will call the full article from your database using the following:

 


$qry = "SELECT * FROM table_name WHERE field_name = ".$_GET['id'];
$rst = mysql_query($qry);

$data = mysql_fetch_array($rst);
echo $data['article_field_name'];

Link to comment
Share on other sites

Well...that kind of answers half...what would the link be to display the full article?

 

I'm sorry if I'm getting annoying but I get frustrated when I try to figure it out for days and have to start over completely. Yes, my own fault I know but I'm learning... :-\

Link to comment
Share on other sites

I just got an idea but...

 

Would this work for for the link?

 

<?php
$id = ("SELECT id FROM articles WHERE id")

echo "<a href=\"/index.php?article=". $id ."\">Full Story</a>";
?>

Just a shortened version but would that work?

Link to comment
Share on other sites

ok......

 

 

what i would do is:

 

database tables: ID, Title, Text:

 

query etc, and result is:

 

while($article_array = mysqli_fetch_array) {

 

 

}

 

 

 

then in that while would go:

 

$article = explode(" ", $article_array['Article']);

 

 

 

then i would display the first eg 3 sentances:

 

echo $article[0], $article[1], $article[2];

 

then

echo "<a href = 'article.php?article_id=".$article_array['id']."'>Read Article</a>";

 

then in article.php go:

 

if(isset($_GET['article_id'] && !empty[$_GET['article_id']))  {

 

questio database for the article of $_GET['article_id'] eg SELECT * FROM Table WHERE ID = $_GET['article_id'];

 

then simply format as you like:

 

 

 

i hope that helps.

 

 

}

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.