SitePoint Sponsor |
|
User Tag List
Results 1 to 11 of 11
Thread: File Opening in new page
-
Apr 25, 2006, 03:02 #1
- 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"> </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"> </td>
<?php } while ($row_findpoems = mysql_fetch_assoc($findpoems)); ?>
-
Apr 25, 2006, 05:39 #2
- 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.
-
Apr 25, 2006, 05:44 #3
- Join Date
- Aug 2000
- Location
- Philadephia, PA
- Posts
- 20,578
- 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>
And 7Stud... I saw what you didTry Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more
-
Apr 25, 2006, 07:47 #4
- 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?????
-
Apr 25, 2006, 08:11 #5
- Join Date
- Aug 2000
- Location
- Philadephia, PA
- Posts
- 20,578
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:$text = file_get_contents($_GET['file']);
Try Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more
-
Apr 26, 2006, 07:30 #6
- 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.
-
Apr 26, 2006, 07:47 #7
- Join Date
- Aug 2000
- Location
- Philadephia, PA
- Posts
- 20,578
- 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.Try Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more
-
Apr 26, 2006, 07:56 #8
- 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?
-
Apr 26, 2006, 08:06 #9
- Join Date
- Aug 2000
- Location
- Philadephia, PA
- Posts
- 20,578
- 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>";
Try Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more
-
Apr 28, 2006, 08:32 #10
- 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?
-
Apr 28, 2006, 09:26 #11
- Join Date
- Aug 2000
- Location
- Philadephia, PA
- Posts
- 20,578
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:echo "<a href=\"?start=" . ($start + 20) . "&id=" . $_GET['id'] . "\">Next Page</a>";
Try Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more
Bookmarks