[FX.php List] RE: Do an "if" on found set ...

Andrew Denman adenman at tmea.org
Wed Sep 8 13:42:20 MDT 2010


Patricia,

1. Is there a [0] missing from this bit of code that you say doesn't work? I could not tell where in the page this code would go.
	if ($userData['ITEMNO']=='HGCATVHBO') {

2. It appears you are only pulling the current services for a user here. To provide an add/remove option you need a list of all available services and then compare the user's current services with the full list. You'll have to play with the user data to get it in a usable format to do the compare. I would put all of the user services into an array and then use in_array().

// Get list of all services
// Get list of user services
// foreach user service IDs into an array
// foreach echo list of all services
	// echo service info
	// if( in_array(current_service_ID, user_service_IDs_array) )
		// provide remove button
	// else
		// provide add button

3. An aside: I believe you need to add [] to your checkbox names so you get all of the values returned on the next page, otherwise PHP just uses the value of the last selected box on the page.
	echo "Remove&nbsp;<input name='D_CableService[]' type='radio' value='HGCATVHBO'>";
	echo "Add&nbsp;<input name='A_CableService[]' type='radio' value='HGCATVHBO'>";

Andrew Denman


-----Original Message-----
From: fx.php_list-bounces at mail.iviking.org [mailto:fx.php_list-bounces at mail.iviking.org] On Behalf Of VanBuskirk, Patricia
Sent: Wednesday, September 08, 2010 11:30 AM
To: FX.php Discussion List
Subject: [FX.php List] Do an "if" on found set ...

I have a FMFind as follows (on a user ID, it pulls back lines of items for that user)

	$userQuery = new FX(FM_IP, FM_PORT, FM_VERSION);
	$userQuery->SetDBData('Webtest_Forms.fp7', 'MS_HG_SERVICES');
	$userQuery->SetDBUserPass(FM_USERNAME, FM_PASSWORD);
	$userQuery->AddDBParam ('USERID', $_SESSION['fsusn'], 'eq');
	$userResult=$userQuery->FMFind();

	foreach($userResult['data'] as $key=>$userData){
	$userDetails=explode('.',$key);
	$userRecord=$userDetails[0];
	}

Then I have each line show in a table as follows, which works great:

	<?php
	if ($_SESSION['found']>0) {     // If user exists

	echo "<table align='center' cellpadding='3' class='bordertable'>
                <tr><td align='center' colspan='4'
class='tableborderheading'>You presently have ".$_SESSION['found']."
service(s):</td></tr>
				<tr valign='bottom'>
					  <td align='left'
class='ColumnHeader'><b>Description</b></td>
					  <td align='center'
class='ColumnHeader'><b>Start Date</b></td>
					  <td align='right'
class='ColumnHeader'><b>Rate</b></td>
				</tr>";

	foreach($userResult['data'] as $key=>$userData){
	$userDetails=explode('.',$key);
	$userRecord=$userDetails[0];

	echo "<tr align='center'>
                  <td align='left'
nowrap>".strtoupper($userData['DESCRIPTION'] [0])."</td>
                  <td align='center'>".$userData['STARTDATE'] [0]."</td>
                  <td align='right'>".$userData['AMOUNT'] [0]."</td>
           </tr>";
	  }
	echo "</table><br>";
	}
	?>

Now what I'd like to do is ... if an item exists, then have the checkbox be to Remove the item ... if not, it would be to add the item.  What would the syntax be for something like that?  Do I have to do a find for each item first?  

I tried the following, but it did not work:

	<?php

		if ($userData['ITEMNO']=='HGCATVHBO') {
			echo "Remove&nbsp;<input name='D_CableService'
type='radio' value='HGCATVHBO'>";
			} else {
			echo "Add&nbsp;<input name='A_CableService'
type='radio' value='HGCATVHBO'>";
			}

	?>
_______________________________________________
FX.php_List mailing list
FX.php_List at mail.iviking.org
http://www.iviking.org/mailman/listinfo/fx.php_list


More information about the FX.php_List mailing list