SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Struggling With Get on Receiving Page

    Hi,

    I am trying to try echo an article column on a page called article.php based on the ID of an item which is inserted into a link from the previous page. However, I am struggling to show the article. I can only echo the ID.

    Previous page:

    <a href="article.php?ID=<?php echo $row['ID']; ?>"><?php echo $row['title']; ?></a>

    Article Page:

    Code:
    <?php echo $_GET['ID'];?>
    - This works as it shows the ID

    Code:
    <?php echo $_GET['article'];?>
    - This does not work as it does not show the article.

  2. #2
    SitePoint Addict
    Join Date
    Apr 2011
    Posts
    266
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    The variable $_GET['article'] to return someting, you should have " article.php?ID=id&article=something " in URL address.
    Free: Web Programming Courses HTML, CSS, Flash
    Web Programming: AJAX Course and PHP-MySQL Course video Lessons
    Good JavaScript and jQuery course for beginners

  3. #3
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I have done that so I have echoed all the columns into the link.

    Is there code I can use to just echo the ID into the link? This is what I am trying to do.

  4. #4
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Your previous page link did not include the value for article so you would get nothing when you echo it.

    Do what MarPlo suggested then you should get the value if that is what you want.

    For example, if $row['title'] is your article then you could do something like this:

    <?php echo '<a href="article.php?ID='.$row['ID'].'&amp;article='.$row['title'].'">'.$row['title'].'</a>'; ?>

  5. #5
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tom8 View Post
    Your previous page link did not include the value for article so you would get nothing when you echo it.

    Do what MarPlo suggested then you should get the value if that is what you want.

    For example, if $row['title'] is your article then you could do something like this:

    <?php echo '<a href="article.php?ID='.$row['ID'].'&article='.$row['title'].'">'.$row['title'].'</a>'; ?>
    Thanks, I have done this but is there a way of echoing the information by just inserting the ID into the link?

  6. #6
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I’m not quite sure what you have in mind. Is the information store in a database? If so you could simply retrieve the content from the database based on the ID and display it using echo.

  7. #7
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Yes the information is stored in a database, but I dont know how to retreive the information to display it. Do I need to query the database to retrieve the information, if so do you know what code I need to do this please?

  8. #8
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Yes you would. Sound as if you are new with this so I think best to start by learning a bit about database as well as PHP since this will be the language you use. Take a look at this tutorial and see if it helps. MySQL is used for the tutorial. If your database is not that then just Google it and Iím sure you will find them too. Post up additional info about your site if you could. Perhaps other members will offer suggestions.

  9. #9
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Many thanks, I have been watching a number of YouTube videos. I shall also read through this.

    The frustrating thing is I can echo everything if I put it into the URL such as this article.php?ID=<?php echo $row['ID']; ?>&content=<?php echo $row['content']; ?>............................

    It does work but it looks messy.

    But if I use just the ID article.php?ID=<?php echo $row['ID']; ?> I cant work out how to echo the content.

    Is there some form of query I need to carry out?

  10. #10
    SitePoint Addict
    Join Date
    Apr 2011
    Posts
    266
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    For what you need , you must perform a Select in the database to get the row with data associated to that ID.
    Code:
    $sql = "SELECT * FROM table_name WHERE ID =". intval($_GET['ID']]). " LIMIT 1";
    Than execute this query, and echo $row['article'] .
    Well, try learn about mysql and php if you work with database, here's a tutorial about Select PHP-MySQLi.
    Free: Web Programming Courses HTML, CSS, Flash
    Web Programming: AJAX Course and PHP-MySQL Course video Lessons
    Good JavaScript and jQuery course for beginners

  11. #11
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The frustrating thing is I can echo everything if I put it into the URL such as this article.php?ID=<?php echo $row['ID']; ?>&content=<?php echo $row['content']; ?>............................

    Can you give us the links to what you're talking about?

  12. #12
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Ive been working on this for nearly 4 hours today and it still wont work!

    This is my link...

    article.php?ID=2

    This is my code on article.php...

    <?php

    $query = mysql_query("SELECT * FROM articles ORDER BY ID DESC LIMIT 15");
    while($row = mysql_fetch_array($query)) {
    ?>

    These are my echoes, I am trying both Get and Row.

    <?php echo $_GET['title'];?>
    <?php echo $row['intro']; ?>

    Does anyone have a basic guide on how to echo information use the Get Command?

  13. #13
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The link I’m referring to is the one you enter on the browser’s address bar. For example:

    http://mysite.com/article.php?ID=2

  14. #14
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Yes its... mysites.com/article.php?ID=2

    It goes onto article.php but I cant echo the content.

    This is the code I use to enter the ID <a href="article.php?ID=<?php echo $row['ID']; ?>"

    If enter everything into the link then I can each it on the following page:

    <a href="article.php?ID=<?php echo $row['ID']; ?>"

    If echo everything into the link then I can display it on the following page but it should be done with just the ID but I dont know how to do this.

  15. #15
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I now have the following code but it says: Invalid query: Query was empty

    <?php



    $sql = "SELECT * FROM articles WHERE '". mysql_real_escape_string($ID) ."'";
    $rs = mysql_query($strSQL);

    if (!$strSQL) { // add this check.
    die('Invalid query: ' . mysql_error());


    }


    // Loop the recordset $rs
    // Each row will be made into an array ($row) using mysql_fetch_array
    while($row = mysql_fetch_array($rs)) {


    echo $row['title'] . "<br />";

    }

    mysql_close();
    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •