[FX.php List] "previous" and "next" links for large array

Michael Layne fx at 9degrees.com
Tue Sep 19 11:58:08 MDT 2006


Alex,
It's been a while since I'v looked at this, but it definitely works:

first the FX query with specifying a particular found count to be  
returned:
	$returnCount = 20;
	$q = new FX($ip, $port);
	if (!isset($_GET['skip'])) {
     	$skipSize = 0;
     	} else {
     	$skipSize = $_GET['skip'];
     }
	$q->SetDBData($fmdb,$lay . 'glossary',$returnCount);
	$q->SetDBPassword($fmpw[0],$fmpw[1]);
	$q->FMSkipRecords($skipSize);
	$r = $q->FMFind();
	$d = current($r['data']);
	$n = $r['foundCount'];


then code to paginate a the top to navigate through the pages/records:
	$pages = ceil(($r['foundCount'] / $returnCount));

	if (strlen($r['linkPrevious']) < 1) {
		$firstPage = '1';
		} else {
		$firstPage = $skipSize + 1;
	}
	if (strlen($r['linkNext']) < 1) {
		$lastPage = $r['foundCount'];
		} else {
		$lastPage = $returnCount + $skipSize;
	}

then outputting the links for pagination:
if ($r['foundCount'] <= 0 ) {
	echo "<span class=\"notice\">There are no glossary terms that match  
your search.</span>\n";
	} else {
		echo "<span class=\"sm\">There are currently <strong>" . $r 
['foundCount'] . "</strong> glossary terms (<strong>" . $pages . "</ 
strong> page(s))</span>\n<br />\n";
		echo "<table width=\"60%\" align=\"center\" border=\"0\"  
cellpadding=\"0\" cellspacing=\"0\"><tr>\n";
		if (strlen($r['linkPrevious']) < 1) {
			echo "<td width=\"50%\">&nbsp;</td>\n";
			} else {
			echo "<td width=\"50%\">\n<a href=\"" . $r['linkPrevious'] .  
"\">&#x2039;&nbsp;previous page</a></td>\n";
		}
		if (strlen($r['linkNext']) < 1) {
			echo "<td width=\"400\" align=\"right\">&nbsp;</td>\n";
			} else {
			echo "<td width=\"400\"><div align=\"right\">\n<a href=\"" . $r 
['linkNext'] . "\">next page&nbsp;&#x203A;</a></div></td>\n";
		}
		echo "</tr></table>\n";
}

then finally a 'foreach' loop to cycle through your data in a table:
if ($r['foundCount'] >= 1 ) {
	$counter = 1;
	echo "<table>\n";
	echo "<tr class=\"listingHead\">\n"; // begin row 1
	echo "<th width=\"10\">&nbsp;</th>";
	echo "<th><strong>Term</strong></th>";
	echo "<th>Source</th>";
	echo "</tr>"; // end row 1
	foreach ($r['data'] as $l) {
		if ($counter % 2 == 0) {
		echo "<tr class=\"even\">\n";
		} else {
		echo "<tr class=\"odd\">\n";  // begin row 2
		}
		echo "<td class=\"count\">" . $counter . "</td>\n";  // 1
		echo "<td><a href=\"/\" onclick=\"displayTerm('" . $l['recid'][0] .  
"');return false;\">" . $l['Term'][0] . "</a></td>\n";
		echo "<td>" . $l['Source'][0] . "</td>\n";
		echo "</tr>";
		++$counter;		// The '++' operator increments the argument it  
accompanies.
	}
	echo "</table>\n";
}


HTH,

Michael

On Sep 19, 2006, at 1:22 PM, Alex Gates wrote:

> The 1st email didn't make the trip right away - - - I seem to have
> thrown together something that is working... but if anyone still wants
> to give advice, I'd love to hear it...
>
> Alex P. Gates
>
> -----Original Message-----
> From: fx.php_list-bounces at mail.iviking.org
> [mailto:fx.php_list-bounces at mail.iviking.org] On Behalf Of Alex Gates
> Sent: Monday, September 18, 2006 2:04 PM
> To: 'FX.php Discussion List'
> Subject: [FX.php List] "previous" and "next" links for large array
>
> Hi everyone-
>
> Jonathan has graciously helped me with this question earlier today-  
> and
> I appreciate all the help he has given me.  I'm still quite confused
> here, so I thought I would turn to all of you for help.
> I understand this is not so much a specific fx.php question, but (I
> could be wrong) I think it involves enough fx that it would just  
> confuse
> people on regular php forums.
>
> I have a page that displays a container image, a chunk of css, email,
> web address, and some pricing info.
> I have some php code that puts my returned records into a table.
> Here is a link:
>
> http://www.gandrpub.com/cookbooks_for_sale/cookbooks_for_sale.php
>
> As you can see, if you hold your mouse over the image, a tooltip of a
> larger version will pop up.
>
> However, with IE, these tooltips wont pop up until all the images have
> loaded.  I think there are about 93 of them on this page.
>
> (as a side note, this uses a solution that will automatically place
> these cookbooks online once they ship- and it will keep them up for 90
> days)
>
> I got to thinking that many people are still using dialup, and having
> 93+ cookbooks on one page is a little much.  In fact, I'd like to
> display 9 per page and have "next" and "previous" links.
>
> Does anyone have any thoughts or recommendations on the best way to
> break this up?
>
> This is what I am using as my query:
>
>
> <?php
>
>
>     $lookup=new FX($serverIP,$webCompanionPort,'FMPro7');
> 	$lookup->SetDBData('CookbookSale.fp7','ToWeb', 'all');
> 	$lookup->SetDBPassword('admin','admin');
> 	$lookup->AddDBParam('Status', 'Online');
> 	$lookup->AddSortParam('DateOrderShipped', 'descend');
> 	$lookupResult=$lookup->FMFind();
> 	$foundResult=$lookupResult['foundCount'];
> 	
> 	//echo $foundResult;
> 	//echo '<br>';
> 	//echo $lookupResult['errorCode'];
>
> ?>
>
>
> And this is how I am displaying it in the table:
>
> <?php
> $http = "http://";
> $i = 0;
>
> foreach( $lookupResult['data'] as $key => $searchData ){
> $booktitle = $searchData['returnreplacesettitle'][0];
> $fixedtitle = str_replace("'", "\'", $booktitle);
> ?>
>     <?php
>     if ($i == 0) {
>         print "<tr>\n";
>     }
>     ?>
>     <td width="574" height="186" valign="top" class="phpcontent">
> <center><img src="FX/image_proxy.php?FXimage=<?php echo
> vignereEncryptURL($searchData['Cover'][0]); ?>" height="160"  
> border="1"
> onMouseOver="this.T_DELAY=300;this.T_WIDTH=200;this.T_LEFT
> =true;this.T_TITLE='<?php echo
> $fixedtitle;?>';this.T_BORDERCOLOR='#6a7d40';return escape('<img
> src=\'FX/image_proxy.php?FXimage=<?php echo
> vignereEncryptURL($searchData['Cover'][0]); ?>\'
> height=\'350\'>')"/></center>
>     <?php
> 	echo '<br><center>' . $searchData['CSSWebViewforCSS'][0] .
> '</center>';
> 	if($searchData['setEmail'][0] != "")
> 	{ echo '<br><center>' .'Email: <br> <a href=mailto:' .
> $searchData['setEmail'][0] . '>' . $searchData['setEmail'][0] .
> '</a></center>'; }
> 	if($searchData['setWebAddress'][0] != "")
> 	{ echo '<br><center>' .'Web: <a href=' . $http .
> $searchData['setWebAddress'][0] . '>' . $searchData['setWebAddress'] 
> [0]
> . '</a></center>'; }
> 	if($searchData['PriceInfo'][0] != "")
> 	{ echo '<br><center>' . $searchData['PriceInfo'][0] .
> '</center>';}
> 	?><br></td>
>
> <?php
>     $i = ($i + 1) % 3;
>     if ($i == 0) {
>         print "</tr>\n";
>     }
> ?>
> <?php
> }
> ?>
>
>
> I've spent some time searching and reading about arrays, but I'm not
> even to the point where I even have an idea of how to start.
>
> Please- can anyone provide some insight?
>
> Thanks-
>
>
> Alex P. Gates
>
>
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
>
>
>
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list


Michael Layne  |  9 degrees development  |  www.9degrees.com  |   
404.226.7835  |   Skype: LayneBay


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.iviking.org/pipermail/fx.php_list/attachments/20060919/baa5d977/attachment-0001.html


More information about the FX.php_List mailing list