Hi there, I have written down a PHP program to read a Server folder, just I am using FTP statement to do that, I am reading the folder and move the files to an array, that array has been moved into a HTML TABLE using the FOREACH() PHP statemen, all those files are PDF and my goal is read every one of them and open that file, the problems is that when I click on a row the last table record is opne and not the row selected
I need to get a way to read the HTML table and get the correct file name
thank in advance
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<link href="css/css1.css" rel="stylesheet" type="text/css">
<h1>FGPO's FOLDER</h1>
</head>
<body >
<?php
include("FTP.php");
$filesArr=xp($filesArr,$connect );
?>
<form method="POST" action="showpdf.php">
<div id="scrolltable" >
<table class="tabla" border="1" >
<tr class="header">
<th>Sequence #</th>
<th>File Name</th>
<th>View </th>
</tr>
<?php foreach($filesArr as $k => $value) {
?>
<tbody >
<tr class="detail">
<td onmouseover='this.style.background="#cc0000"' onmouseout='this.style.background="white"' ><?php echo $k ;?></td>
<td onmouseover='this.style.background="#cc0000"' onmouseout='this.style.background="white"' ><?php echo $value ;?></td>
<td ><input value="<?php echo $value ?>" type="hidden" name="accion" value="<?php echo $value;?>">
<input type="submit" value="View"</td>
</tr>
</tbody>
<?php }
ftp_close($connect);
?>
</table>
</div>
read a HTML row
Moderator: General Moderators
- iankent
- Forum Contributor
- Posts: 333
- Joined: Mon Nov 16, 2009 4:23 pm
- Location: Wales, United Kingdom
Re: read a HTML row
Your loop looks ok so I'd guess possibly a problem in FTP.php somewhere - copy and paste it here if you can but remember to remove usernames/passwords!
just noticed, you give the value="" parameter for <input> twice in your loop. shouldn't cause a problem but no point having it there twice!
just noticed, you give the value="" parameter for <input> twice in your loop. shouldn't cause a problem but no point having it there twice!
Re: read a HTML row
Hey Thanks a lot for your answ, just I have fixed the duplicated value, well I need help with somethig related with the HTML, I am populating the HTML with 7 records, but I need to read or click the recod 2, I am talking abou the HTML TABLE, I have included a INPUT tag to view the file but the $value has the last value added for instance
fil1
fil2
fil3
file4
file5
file6
file7
when I made click to the first(fil1) the program is taking the last one(FILE70, so I need to know a method to get the position where I am cliking
fil1
fil2
fil3
file4
file5
file6
file7
when I made click to the first(fil1) the program is taking the last one(FILE70, so I need to know a method to get the position where I am cliking
- iankent
- Forum Contributor
- Posts: 333
- Joined: Mon Nov 16, 2009 4:23 pm
- Location: Wales, United Kingdom
Re: read a HTML row
It's because you're outputting an <input> tag called "accion" multiple times. When you submit the form, every one of those is submitted and PHP only takes notice of the last one. So, whichever button you click, PHP always gets the value from the last HTML field called accion.
What you're trying to do with a single form is a bit more complex. The easiest way would be to give every file its own form, i.e. put the <form></form> tags around the two <input>'s, so each form only has a single input called accion and a single submit button.
The only way you can do it with a single form is by working out which submit button was clicked. Because all of your buttons have the value 'View', the only way to differentiate between them in PHP is using the name tag. So, you'd need to give each of your submit buttons and hidden input fields its own name and check for those names when the form is submitted. Can get quite messy!
Alternatively, you could use javascript, but for the sake of what you're trying to do it'll be easier to use multiple forms as above.
What you're trying to do with a single form is a bit more complex. The easiest way would be to give every file its own form, i.e. put the <form></form> tags around the two <input>'s, so each form only has a single input called accion and a single submit button.
The only way you can do it with a single form is by working out which submit button was clicked. Because all of your buttons have the value 'View', the only way to differentiate between them in PHP is using the name tag. So, you'd need to give each of your submit buttons and hidden input fields its own name and check for those names when the form is submitted. Can get quite messy!
Alternatively, you could use javascript, but for the sake of what you're trying to do it'll be easier to use multiple forms as above.
Re: read a HTML row
Hey Man,
I have pu the <Form> tag just like you recomended and it is working
So THANKS A LOT
I have pu the <Form> tag just like you recomended and it is working
So THANKS A LOT