ryeman98 Posted May 12, 2007 Share Posted May 12, 2007 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 Quote Link to comment Share on other sites More sharing options...
chiprivers Posted May 12, 2007 Share Posted May 12, 2007 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'] Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted May 12, 2007 Author Share Posted May 12, 2007 I mean like... example: A blog has a few sentences of the article, then you have to click on a link to get to the full article. the url would be like: http://www.somesite.com/index.php?id=546187 Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted May 12, 2007 Author Share Posted May 12, 2007 I can't edit my post... I wanted to say that I know how to display the article previews but I just don't know how to use the GET method to call the entire article from the database. Quote Link to comment Share on other sites More sharing options...
chiprivers Posted May 12, 2007 Share Posted May 12, 2007 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']; Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted May 12, 2007 Author Share Posted May 12, 2007 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... :-\ Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted May 12, 2007 Author Share Posted May 12, 2007 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? Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted May 12, 2007 Author Share Posted May 12, 2007 I just noticed PCNerd was on...maybe he could lend his helping hand? Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted May 12, 2007 Share Posted May 12, 2007 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. } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.