Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×
The Claris Museum: The Vault of FileMaker Antiquities at Claris Engage 2025! ×

This topic is 6013 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hi all

I am having a problem with PHP. I am using FX.php.

I have data in my database, Header and TitleCalc. I have several headers, eg. state, federal, other.

I want to see all the titleCalc for each header.

My page is returning all the data I need but it is not right.

I am getting a list of all the headers and then the Titles.

What have I missed out? The code is below. Any help would be greatly appreciated.

<?php

foreach ($catResult['data'] as $key => $catData)

{

?>

<?php echo $catData['Header'][0]; ?>

<?php

}

?>

<?php

foreach ($catResult['data'] as $key => $catData)

{

?>

<?php echo $catData['TitleCalc'][0]; ?>

<?php

}

?>

Thanks

Zippy

Posted

Hi Zippy,

The reason you are seeing all the headers and then the titles is because you have two sets of loops on your page.

The first loop runs through the data and shows your header then the second runs afterwards.

What you need to do is loop through the data once looking for changes in the Header. When the field value for Header changes you need it to display that header and then show all the data underneath.

As you have found out not quite as easy as in FileMaker but still very doable.

What we need to do is create a variable for the Header. Then we compare the value in the Header field with this new variable. If it does NOT match then we display the header plus a titlecalc row otherwise just display the titlecalc row.

See the example below for code;


<?php

$checkHeader = NULL;



foreach ($catResult['data'] as $key => $catData) 

{

$header = $catData['Header'][0];

$titleCalc = $catData['TitleCalc'][0];

if ($header != $checkHeader) 

{

//Display the header

echo $header;

}



//change the checkHeader variable to match the current header. This way it will only display the header info once.

$checkHeader = $header;

// Now display the table row

echo "n

$titleCalc n

n";



} // End the foreach loop

?>

Posted

Thanks Andy, you are a champ.

Once I put the header into its own table row, it worked perfectly .. thanks again for your help.

I am still getting my head around php, could you explain the /n when doing the html?

Thanks

Zippy

<?php

$checkHeader = NULL;

foreach ($catResult['data'] as $key => $catData)

{

$header = $catData['Header'][0];

$titleCalc = $catData['TitleCalc'][0];

if ($header != $checkHeader)

{

//Display the header

echo "

$header n

n";

}

//change the checkHeader variable to match the current header. This way it will only display the header info once.

$checkHeader = $header;

// Now display the table row

echo "

$titleCalc n

n";

}

// End the foreach loop

?>

Posted

Andy,

Another question, how do I use an href in the php now.

In other pages I used the following code to create my links

<?php echo $catData['TitleCalc'][0];?>

I have used the code you supplied me for the TitleCalc

echo "

$titleCalc n

n";

but I can't seem to get the link to work when I add the html in.

Could you please give me a hand.

Any help is greatly appreciated.

Thanks again

Zippy

Posted

Zippy,

Glad it worked.

OK, firstly the n is used inside a " " echo to put a return into the source code. Otherwise what happens is all your table rows end up on a veeeeery long line of source code.

As to using an href, simply substitute your double quotes for single quotes

$linkCalc = $catData['Link_Calc'][0];

echo "

n

$titleCalcn

n";

or if you prefer to keep them you can escape the quote with

$linkCalc = $catData['Link_Calc'][0];

echo "

n

$titleCalcn

n";

Of course, you could also create your link outside the table row and just include it as a variable

$linkCalc = $catData['Link_Calc'][0];

$linkDisplay = "$titleCalc";

echo "

n

$linkDisplayn

n";
  • 1 year later...
Posted

Hi

My PHP skills are progressing slowly and since this code was done I have used it in so many pages.

I now need some more help please, if possible.

The code here produces a nice subsummary style report, but I now would like it to be split in half if possible.

I have another page where I have used


	

		

			

<?php

$i=0;

$half = (int) ($catResult['foundCount']/2 + 0.5);



foreach ($catResult['data'] as $key => $catData)

{

if($i == $half)

{

?>

			

		

		

			

<?php

}

?>	

	

    	

			

		

    			

			<?php echo $catData['Full Name'][0];?>	

			 	

				  			

			<?php echo $catData['PFP Title'][0];?>

			 	

	

  	

<?php

$i++;

}

?>



	

  

Which halves the results and creates two seperate lists, but everytime I try to modify my orginal code to incorporate this code, I don't get anything back.

Any help would be greatly appreciated.

This topic is 6013 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.