Link to home
Start Free TrialLog in
Avatar of Rapturer
RapturerFlag for United States of America

asked on

PHP conditional in XML db query output

I have a php script which is outputting the correct data.I wont lead off with the whole query...

I believe someone can help me code this:

CURRENT:
print("<cell><![CDATA[".$row['loc']."]]></cell>");
...which returns and XML "CELL" element with the sql query result populating the cell data.

WHAT I NEED TO DO:

I need this line to be a conditional...

WHAT I'VE TRIED:
IF ($row['loc'] = "Shipping" print("<cell><![CDATA["."<div class='redbg'>".$row['loc']."</div>"."]]></cell>"));
ELSE
(print("<cell><![CDATA["."<div class='bluebg'>".$row['loc']."</div>"."]]></cell>"));
<<<<<I've tried several versions of this...XML debugging is very lacking>>>>>>
The div works fine without the conditional...it only breaks when the IF and ELSE

THANKS!

Rapturer

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Use double equal signs for comparison!

if ($row['loc'] == "Shipping")
{
   print("<cell><![CDATA["."<div class='redbg'>".$row['loc']."</div>"."]]></cell>")
}
else
{
   print("<cell><![CDATA["."<div class='bluebg'>".$row['loc']."</div>"."]]></cell>");
}

Open in new window

Avatar of Rapturer

ASKER

I actually did have the correct operator.. "==" just did not show it in the code.
 
I did try your code Ray and got a the following:
PHP Parse error:  syntax error, unexpected '}' in /home/control/public_html/APTS_BETA/clave_view1_GET.php on line 60
Line 60 is the single closing bracket " } "
Thanks! - Rapturer
I only posted 8 lines, but the error cited line 60.  In order to understand the error, I would need to see what's in the actual code that generated the error message.  Squirt that into the code snippet and I will take a look.
Here you are Ray. As you can see the code is a real wreck right now with line edits and such, but you will get the drift.
This is the GET file for  DHTMLX's Dataprocessor. Dhtmlx grid has an amazing JAX library.
Best,
Rapturer  

<?php
/*
Copyright DHTMLX LTD. http://www.dhtmlx.com
This version of Software is free for using in non-commercial applications.
For commercial use please contact sales@dhtmlx.com to obtain license
*/
 
//include db connection settings
require_once("modules/config.php");
 
$link = mysql_pconnect($mysql_host, $mysql_user, $mysql_pasw);
$db = mysql_select_db ($mysql_db);
 
 
//start session to build different trees for different sessions (if you set $_SESSION["id"] to some hardcoded value, this way of processing will be skipped)
/*
session_start();
//$_SESSION = array();
if(!isset($_SESSION["id"])){
	$_SESSION["id"] = microtime();
	//add some rows to the table if user comes first time
	$sql = 	"Insert into samples_grid(sales,title,author,price,instore,shipping,bestseller,pub_date,GUID) ";
	$sql.= 	"Values(100,'Your Favotite Book','Bill Starter',23,'1','12','1',null,'".$_SESSION["id"]."')";
	$res = mysql_query ($sql);
	$sql= "Insert into samples_grid(sales,title,author,price,instore,shipping,bestseller,pub_date,GUID) ";
	$sql.= 	"Values(-50,'Good Start','Phillip Nomore',12.5,'0','12','0',null,'".$_SESSION["id"]."');";
	$res = mysql_query ($sql);
}
*/
 
//FUNCTIONS TO USE IN THE CODE LATER
 
//print tree XML based on parent_id (function calls itself to go through the nested levels)
	function getRowsFromDB($parent_id){
		//get tree level from database taking parent id as incomming argument
		$sql = "SELECT DISTINCT products.partnumber AS \"Part Number\", invoices.id, invoices.loc, invoices.stagestatus, invoices.day, invoices.month, invoices.year, invoices.tracking as \"Shipping\", invoices.productionnotes as \"Notes\", products.claveid AS \"CR1\", products.claveid2 \"CR2\", lineitems.id AS \"LID\", lineitems.width, invoices.requireddate as \"Required Date\", invoices.ponumber as \"PO Number\", invoices.scheduledtorun, lineitems.height, SUM(lineitems.width * lineitems.height) /144 * ( lineitems.quantity ) AS \" Total SqFt\", lineitems.quantity,  SUM(lineitems.quantity) as quantity, clients.company FROM clients INNER JOIN invoices ON ( clients.id = invoices.clientid ) , lineitems INNER JOIN products ON ( lineitems.productid = products.id ) WHERE (lineitems.invoiceid = invoices.id) AND invoices.stagestatus=\"Production\" GROUP by lineitems.invoiceid ORDER by invoices.loc";
 
 
 
 
		//echo $sql;
		$res = mysql_query ($sql);
		if($res){
			while($row=mysql_fetch_array($res)){
				//create xml tag for grid row
				print("<row id=' ".$row['id']." '>");
					print("<cell><![CDATA["."<a href='workorders_addedit.php?id=".$row['id']."'target="."'_blank' >SG".$row['id']."</a>"."]]></cell>");
				//	print("<cell><![CDATA["."<b>".$row['Required Date']."<b>"."]]></cell>");
				//	print("<cell><![CDATA[".$row['company']."]]></cell>");
				//	print("<cell><![CDATA[".$row['Part Number']."]]></cell>");
				//	print("<cell><![CDATA[".$row['PO Number']."]]></cell>");
					print("<cell><![CDATA["."<b>".ceil ($row['Total SqFt'])."</b>"."]]></cell>");
					print("<cell><![CDATA["."<b>".$row['quantity']."<b>"."]]></cell>");
						print("<cell><![CDATA[".$row['CR1']."]]></cell>");
						print("<cell><![CDATA[".$row['CR2']."]]></cell>");
				//			print("<cell><![CDATA[".$row['Notes']."]]></cell>");
				//			print("<cell><![CDATA[".$row['stagestatus']."]]></cell>");
				//	print("<cell><![CDATA["."<div class='redbg'>".$row['loc']."</div>"."]]></cell>");
					if ($row['loc'] == "Inspection"){
   print("<cell><![CDATA["."<div class='redbg'>".$row['loc']."</div>"."]]></cell>")}else{
   print("<cell><![CDATA["."<div class='bluebg'>".$row['loc']."</div>"."]]></cell>")
};
 
							
						//	print("<cell><![CDATA[".if ($row['loc']!=0 echo('<div class=`redbg`>'.$row[`loc`])."</div>".else echo $row['loc'];."]]></cell>");
				//	print("<cell><![CDATA[".$row['scheduledtorun']."]]></cell>");
			//		print("<cell><![CDATA[".gmdate("m/d/Y",strtotime($row['pub_date']))."]]></cell>");
				//close xml tag for the row
				print("</row>");
				
			}
		}else{
			echo mysql_errno().": ".mysql_error()." at ".__LINE__." line in ".__FILE__." file<br>";
		}
	}
 
//XML HEADER
 
//include XML Header (as response will be in xml format)
if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
 		header("Content-type: application/xhtml+xml"); } else {
 		header("Content-type: text/xml");
}
echo("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"); 
?>
 
<!-- start grid xml -->
<rows id="0">
	
<?php
	//print tree XML
	getRowsFromDB(0);
	//Close db connection
	mysql_close($link);
?>
 
<!-- close grid xml -->
</rows>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you Ray ... Worked Perfectly

Rapturer
Cool!  Thanks for the points, ~Ray