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
https://forums.phpfreaks.com/topic/51013-get-method-help/
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
https://forums.phpfreaks.com/topic/51013-get-method-help/#findComment-251032
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
https://forums.phpfreaks.com/topic/51013-get-method-help/#findComment-251052
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
https://forums.phpfreaks.com/topic/51013-get-method-help/#findComment-251061
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
https://forums.phpfreaks.com/topic/51013-get-method-help/#findComment-251118
Share on other sites

Archived

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

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