Help with this if statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Help with this if statement

Post 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?
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post by mhouldridge »

I have changed the last part to;

<

Code: Select all

TD>&quote;.include(&quote;reconciled.php&quote;).&quote;</TD>
This seems to be doing something now... but still not outputting "yes" correctly, and other data.
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post 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?
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post 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
-
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post 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?
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post 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
-
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post 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)
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post 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
-
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post by mhouldridge »

They are both within the same folder of f:\auditwebsite

I simply insert, http://localhost/view.php
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 ;)
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post by mhouldridge »

It looks like it is including the </td> part in the path....

'reconciled.php</TD>
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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()...
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post by mhouldridge »

Hi,

What I currently have is a table which shows results from database. The table has the following colums;

Code: Select all

Asset   Name   Customer   Type   IP
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?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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";
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post 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]
Post Reply