Re[2]: [PHP] How to write this correctly?
| From: | Tom Rogers | Date: | Sun, 07 Mar 2004 23:52:19 +0000 |
| Subject: | Re[2]: [PHP] How to write this correctly? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-179708@lists.php.net to get a copy of this message | ||
Hi,
Sunday, March 7, 2004, 11:20:18 PM, you wrote:
L> Hi, thanks for a help. but your script doesn't work correctly.
L> function output($action){ // this is line 64.
L> $output = ''; //if no file we return an empty string
L> $fname = 'data/'.$action.'.txt';
L> if(file_exists($fname)){
L> $file = file($fname);
L> foreach($file as $value ) {
L> $output .= "$value<br>";
L> }
L> }
L> return $output;
L> }
L> $content = output(); // I added this line because later I have an echo..
L> if(isset($_REQUEST['action'])){
L> $out = output($_REQUEST['action']);
L> }
L> echo "<tr><td>".$content."<td><tr>"; // as you can
L> see, it is important to
L> put whole output of the function to this variable ($content).
L> The browser debugs:
L> Warning: Missing argument 1 for output() in C:\www\RKV\start.php on line
L> 64
L> Sorry for my bad english,
L> Roman
L> ----- Original Message -----
L> From: "Tom Rogers" <trogers@kwikin.com>
L> To: "Labunski" <romans@skulme.lv>
L> Cc: <php-general@lists.php.net>
L> Sent: Sunday, March 07, 2004 4:14 AM
L> Subject: Re: [PHP] How to write this correctly?
You only need to call output if there is an action selected so
try something like this then
function output($action){
$output = ''; //if no file we return an empty string
$fname = 'data/'.$action.'.txt';
if(file_exists($fname){
$file = file($fname);
foreach($file as $value ) {
$output .= "$value<br>";
}
}
return $output;
}
echo '<table>';
if(isset($_REQUEST['action'])){
$content = output($_REQUEST['action']);
if(!empty($content)){
echo "<tr><td>".$content."</td></tr>";
}else{
echo '<tr><td>Sorry '.$_REQUEST['action'].' not
found!</td></tr>';
}else{
?>
<tr>
<td>
<a href='index.php?action=industry'>Factories</a><br>
<a href='index.php?action=art'>Beautiful pictures</a><br>
<a href='index.php?action=animals'>Zoo</a><br>
<a href='index.php?action=contact'>Contact us</a>
</td>
</tr>
<?php
}
echo '</table>';
--
regards,
Tom