Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 7 of 7
  1. #1
    Senior Member
    Join Date
    Oct 2007
    Posts
    241
    Member #
    15910
    Hello,

    here is a news table:

    id - date - title - par1- text body

    For example, here is the code for displaying latest 10 entries:

    select * from newsa ORDER BY id DESC LIMIT 10

    while ($row = mysql_fetch_array($query)) {
    echo"<p> " . $row['date'] . $row['title'] . "</p>".
    "<p> " . $row['par1'] ."</p>"."<a href='testdisplay2.php'>(more...)</a>" ; }


    How do you make "(more....)" link you see above which will come up with each separate result be an automatically updated link to that generic php / sql query page that will bring up the correct article? right now as you see, (more...) link is only pointing to a page called testdisplay2, which is not good, because it is the same for all results that come up.

    Or another example for the same kind of problem: lets say there is a search query that searches the database for certain keywords and brings up the headings of articles that contain that search word...Then I want user to click on that heading or somewhere in that result and be directed to the php page that will automatically display that relevant article..

    Thanks in advance...

  2.  

  3. #2
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Pass the row id as a GET parameter in the URI, and then you will be able to read it on the PHP page they go to via the $_GET superglobal. e.g.:

    PHP Code:
    <a href="article.php?id=<?= $row['id'?>">
    Then, on the other page:

    PHP Code:
    $id $_GET['id']; 
    Then you can use $id in your query.

  4. #3
    Senior Member
    Join Date
    Oct 2007
    Posts
    241
    Member #
    15910
    I see what you are doing and this is what i was looking for, but i guess there is a syntax error. I am pasting the line of code below, please tell me why it doesnt work..
    echo"<a href='article.php?id=<?= $row['id'] ?>'>"."(more...)"."</a>";

    Also what is this concept called, session variables or something?

  5. #4
    Senior Member
    Join Date
    Oct 2007
    Posts
    241
    Member #
    15910
    echo "<a href="article.php?id=<?= $row['id'] ?>">"."(more...)"."</a>" ;

    did not work either.
    getting differnt kind of syntax errors for both.. this one gave Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/.../.../.../../page.php on line 30

  6. #5
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Can't use that in echo. It has to be outside the PHP tags.

  7. #6
    Senior Member
    Join Date
    Oct 2007
    Posts
    241
    Member #
    15910
    i see, but I want to use it as a link to display differently at the end of each article teaser generated by query below. ...here is the whole thing..if i take it outside of php then it will display only once. i want this to display at the end of each of the three results differently, so when user clicks on one, the next page - which is one php page - will open that particular article.

    $query=mysql_query("select * from newsmil ORDER BY id DESC LIMIT 3");
    while ($row = mysql_fetch_array($query)) {
    echo"<p class='newstitle1'>" . $row['date']."<br/>". $row['title'] . "</p>".
    "<p id=newstext1>" . $row['par1'] ."</p>"."<a href=" whole article.php?id=<?= $row['id'] ?>">"."(more...)"."</a>" ; }

  8. #7
    Senior Member
    Join Date
    Oct 2007
    Posts
    241
    Member #
    15910
    well, just to follow up and update the entry in this forum, i am proud to say that i did it after a few hours full of agony...here is the solution:

    echo"<p class='newstitle1'>" . $row['date']."<br/>". $row['title'] .$row['id']. "</p>".
    "<p id=newstext1>" . $row['par1'] ."</p>";
    $b=$row['id'];
    echo"<a href='article.php?id=$b'".">"."(more...)"."</a>" ; }
    you were right i had to take it out of echo, but when i did that i needed to add a new variable so that id is updated outside the echo statement....thanks for the help.....


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 12:22 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com