SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    File Opening in new page

    Hello to everyone and sorry about any stupidness in my questions.
    So i have a page where i list a rank of stories. When i hit the story name the data source is attached with the path in the mysql db and the file is opened. What i want to do instead is when i press the link to open the story in a page i designed e.g. viewstory in a textfiled. How do i do that?
    This is my php code where i have the link.
    PHP Code:
     <?php do { ?>
             <td width="73">&nbsp;</td>
             <td width="233"><a href="<?php echo $row_findpoems['path']; ?>"><?php echo $row_findpoems['path']; ?></a></td>
             <td width="197"><?php echo $row_findpoems['wid']; ?></td>
             <td width="139"><?php echo $row_findpoems['totalvotes']; ?></td>
             <td width="78">&nbsp;</td>
             <?php } while ($row_findpoems mysql_fetch_assoc($findpoems)); ?>
    Any help will be greatly appreciated.

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If the page you designed is called mypage.php, and it is in the same directory as the script you posted, change the link to:

    <a href="mypage.php?id=<?php echo $row_findpoems['wid']; ?>">

    Then on mypage.php, you can use $_GET['id'] to search your database for the poem you want, and display it's text.

  3. #3
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <a href="viewstory.php?file=<?php echo $row_findpoems['path']; ?>"><?php echo $row_findpoems['path']; ?></a>
    That would link to viewstory.php and pass it the file you want to view in $_GET['file']. Your viewstory page can then open it and display it in the text field.

    And 7Stud... I saw what you did

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is helpful, but how can i view the field in the text area since i only have the path to the field? I pass the id fine, but now i want automaticaly based on the path to fill the textarea with the text file i point to. How do i do that?????

  5. #5
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $text file_get_contents($_GET['file']); 
    That would populate the $text variable with the contents of the file passed in. You can then echo it in your textarea.

  6. #6
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now i get warning <br />
    <b>Warning</b>: file_get_contents(/Upload/addimagesphp.txt.txt): failed to open stream: No such file or directory in <b>C:\Inetpub\wwwroot\WriterClub\teststory.php</b> on line <b>61</b><br />
    inside my textarea.
    The /Upload/addimagesphp.txt.txt is my text file path.

  7. #7
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    That's an absolute path when you want a relative one. The difference is the first slash. That path on your Windows machine translates to:

    c:\Upload\addimagesphp.txt.txt

    When you want

    c:\Inetpub\wwwroot\WriterClub\Upload\addimagesphp.txt.txt

    If that's the path being stored in your database, strip that first slash off it and it should work.

  8. #8
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you that worked fine. Now another issue is that when the text file is opened i want to view only 20 lines, and the hit next and go to the next page to see next 20 lines. Is this feasible?

  9. #9
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    // $start = line number to start printing at
    if (!isset($_GET['start']) || !is_numeric($_GET['start'])) {
        
    $start 0;
    } else {
        
    $start $_GET['start'];
    }

    $text file_get_contents($_GET['file']); 
    $lines split("\n"$text);

    for (
    $i $start; ($i < ($start 20)) && ($i count($lines)); $i++) {
        echo 
    $lines[$i] . "\n";
    }

    echo 
    "<a href=\"?start=" . ($start 20) . "\">Next Page</a>"

  10. #10
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you Dan and all the others. And one last thing, i do a $_GET request on the first page which is an id from a previous page, how do i pass it to the next pages using the code above?

  11. #11
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    echo "<a href=\"?start=" . ($start 20) . "&id=" $_GET['id'] . "\">Next Page</a>"


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
  •