Page 1 of 2
Help with this if statement
Posted: Tue Jul 19, 2005 5:12 am
by mhouldridge
Hi,
I have the following php, which runs through my database table and pulls out all of the fields and displays themm within an alternate coloured table.
Code: Select all
echo "<TABLE BORDER=\"0\" table width=\"100%\">\n";
echo "<TR bgcolor=\"#cccccc\"><TD font colour=\"red\"><b>Asset</b></TD><TD><b>Title</b></TD><TD><b>Customer</b></TD><TD><b>Type</b></TD><TD><b>IP address</b></TD><TD>Reconciled</TD>/TR>\n";
for($i = 0; $i < $numofrows; $i++) {
$reconciled = include("reconciled.php");
$row = mysql_fetch_array($result); //get a row from our result set
$stopped = $row['stopped'];
$void = $row['title'];
if($stopped =='yes'){
echo "<TR bgcolor=\"#C1FFD1\">\n";
}
else if($void =='VOID'){
echo "<tr bgcolor=\"#FFCCCC\">\n";
}
else if($i % 2) {
echo "<TR bgcolor=\"#ffff99\">\n";
}
else {
echo "<TR bgcolor=\"#ffffcc\">\n";
}
echo "<TD><font color=\"red\"><b><a href='viewall.php?varl=".$row['asset']."'>".$row['asset']."</a></b></font></TD><TD><font size=\"2\">".$row['title']."</TD><TD><font size=\"2\">".$row['customer']."</TD><TD><font size=\"2\">".$row['type']."</TD><TD><font size=\"2\">".$row['IP']."</TD><TD>".$row['$reconciled']."</TD>\n";
echo "</TR>\n";
}
echo "</TABLE>\n";
?>
As you can see I have put
Code: Select all
$reconciled = include("reconciled.php");
I need to run this from script and use it within my table output. I have put the following at the end of the above script;
<TD>".$row['$reconciled']."</TD>
However this is not working..
How do I call the reconciled.php script to run and then display the output (an image) within the last table coloumn?
Posted: Tue Jul 19, 2005 5:25 am
by mhouldridge
I have changed the last part to;
<
Code: Select all
TD>"e;.include("e;reconciled.php"e;)."e;</TD>
This seems to be doing something now... but still not outputting "yes" correctly, and other data.
Posted: Tue Jul 19, 2005 5:29 am
by mhouldridge
Iget the following error;
Warning: main(): Failed opening 'reconciled.php</TD> ' for inclusion (include_path='.;c:\php4\pear') in F:\Auditwebsite\view.php on line 78
yes
As you can see, yes is being displayed, however it says for inclusion (include_path) part...
Any ideas?
Posted: Tue Jul 19, 2005 5:35 am
by djot
-
$row['$reconciled'] is undefined (emtpy)
you assign this:
$reconciled = include("reconciled.php");
$row[] only holds information out of your DB(-query).
Whatever you do in reconciled.php, you have to give back the result.
You may do this in two ways:
first way: ($reconciled will hold "hello world!" hereafter)
Code: Select all
<?php
// do anything
$test = "hello world";
// return the results of what you have done.
return $test;
?>
second way: set $reconciled in the include file itself.
so just use
include("reconciled.php");
and set $reconciled in the included file itself like this:
Code: Select all
<?php
// do anything
$test = "hello world";
// return the results of what you have done.
$reconciled = $test;
?>
djot
-
Posted: Tue Jul 19, 2005 5:45 am
by mhouldridge
I get the error;
Warning: main(reconciled.php ): failed to open stream: No such file or directory in F:\Auditwebsite\view.php on line 76
Warning: main(): Failed opening 'reconciled.php</TD> ' for inclusion (include_path='.;c:\php4\pear') in F:\Auditwebsite\view.php on line 76
when simply running an include file with an echo "no"
Is this because I need to set the ini file include path?
Posted: Tue Jul 19, 2005 5:48 am
by djot
-
Where is your include file located?
it should be here (the same folder as view.php):
F:\Auditwebsite\reconciled.php
This has nothing todo with the echo command inside
djot
-
Posted: Tue Jul 19, 2005 5:51 am
by mhouldridge
Yes -
reconciled.php is within f:\auditwebsite
the same directory as view.php (the file which runs the reconciled.php from an include)
Posted: Tue Jul 19, 2005 5:53 am
by djot
-
Well, it's not!
PHP wrote:Warning: main(reconciled.php ): failed to open stream: No such file or directory in F:\Auditwebsite\view.php on line 76
Or do you include view.php in some other file like in F:\index.php for example?
djot
-
Posted: Tue Jul 19, 2005 8:04 am
by mhouldridge
They are both within the same folder of f:\auditwebsite
I simply insert,
http://localhost/view.php
Posted: Tue Jul 19, 2005 8:10 am
by Chris Corbyn
If they *are* all in the saem directory - Does apache have read permissions to the file?
Any included files will follow paths relative to themselves... not the file it is included into but that should be irreleveant if what you say is true

Posted: Tue Jul 19, 2005 8:17 am
by mhouldridge
It looks like it is including the </td> part in the path....
'reconciled.php</TD>
Posted: Tue Jul 19, 2005 9:00 am
by Chris Corbyn
Code: Select all
"<TD>".include('anything_here.php')."</td>
Makes no sense

What line did you do that on?
It looks almost like you tried to echo() include()...
Posted: Tue Jul 19, 2005 9:09 am
by mhouldridge
Hi,
What I currently have is a table which shows results from database. The table has the following colums;
I would like to add another field to the end which displays a picture for each row result. There are two image files which I wanted to be displayed from recon.php (a file which looks through a filed in my database for either YES or NO - If yes one image is displayed, if no the other image is displayed).
Any ideas?
Posted: Tue Jul 19, 2005 9:14 am
by Chris Corbyn
Rather than
Code: Select all
echo "Yadda yadda yadda <td>".include('recon.php')."</td> yadda yadda yadda";
Jump out of echo() to do the include()
Code: Select all
echo "Yadda yadda yadda <td>";
include('recon.php');
echo "</td> yadda yadda yadda";
Posted: Tue Jul 19, 2005 11:06 am
by mhouldridge
hi,
I have got the include file pulling in, however the include file is erroring on the if statement. Please look at the following;
Code: Select all
<?
$db = mysql_connect("localhost","","") or die("Problem connecting");
mysql_select_db("audit") or die("Problem selecting database");
$query = "SELECT recon FROM dedicated";
$result = mysql_query($query) or die ("Query failed");
if ($yesno == "Yes"){
$db = mysql_connect("localhost","","") or die("Problem connecting");
mysql_select_db("audit") or die("Problem selecting database");
$img = "1";
$result = @mysql_query("SELECT * FROM images WHERE imgid=" . $img . "");
}
while ( $row = mysql_fetch_array($result) )
{
$imgid = $row["imgid"];
$encodeddata = $row["sixfourdata"];
}
echo base64_decode($encodeddata);
}
else if ($yesno =="No"){
$db = mysql_connect("localhost","gia","") or die("Problem connecting");
mysql_select_db("audit") or die("Problem selecting database");
$img = "2";
$result = @mysql_query("SELECT * FROM images WHERE imgid=" . $img . "");
}
while ( $row = mysql_fetch_array($result) )
{
$imgid = $row["imgid"];
$encodeddata = $row["sixfourdata"];
}
echo base64_decode($encodeddata);
}
?>
I get Parse error: parse error, unexpected '}' in F:\Auditwebsite\image2.php on line 19
This is before the else if statement in my code[/b]