joomla pagination not working properly - php

function display($cachable = false, $urlparams = false){
$lim0 = 0;
$lim = 10;
$db =& JFactory::getDBO();
$db->setQuery('SELECT name,email,id,profile_value from y0sov_users,y0sov_user_profiles where y0sov_users.id=y0sov_user_profiles.user_id and profile_key="profile.department" LIMIT 0,10');
$rL=&$db->loadAssocList();
if (empty($rL)) {
$jAp->enqueueMessage($db->getErrorMsg(),'error'); return;
}
else
{
$db->setQuery('SELECT FOUND_ROWS();');
jimport('joomla.html.pagination');
$pageNav = new JPagination( $db->loadResult(), $lim0, $lim );
foreach($rL as $r) {
echo '<div id="values">';
echo '<ul>';
echo '<li>'.$r.'</li>';
echo '</div>';
}
echo $pageNav->getListFooter();
}
}
}
?>
The values are not displaying. I am new to Joomla so pardon me if I am missing something really fundamental.

nice try!
This is not the way to do it in joomla.
You do not need to create the ul li structure.
The echo $pageNav->getListFooter(); does it for you.
I assume that the code above belongs to a component.
Place the echo $pageNav->getListFooter();
part inside the appropriate file in the tmpl folder of the view. As far I can see in your code, you only use the view.html.php file?
This is not completely wrong, but you do not use joomla standards and you may face problems on cases such as creating menu items of such a type.
Usually we create the pagination object in the model and we just get it in the view.html.php file. Finally, we echo $pageNav->getListFooter(); in the appropriate file in tmpl.
This tutorial is quite good & easy:
http://www.tutsforu.com/pagination-in-joomla-component.html

Related

How to get a single variable attached to the URI?

I don't seem to able to acquire a GET variable that is attached to the URI.
The codes are => at the controller
...
parse_str($_SERVER['QUERY_STRING'], $_GET);
....
$data['ti'] = $this->input->get('hamleno');
this->load->view('anasayfa', $data);
The codes are => at the view the link is
...
<div class="row"><?php for ($b=0; $b<=(count($hml)-1); $b++) { ?><?php echo $hml[$b]." "; ?> <?php } ?></div>
The link is working. I have added the
$config['uri_protocol'] = "PATH_INFO";
to the config.php file.
However I am not able to get the $ti variable
if ($ti){
$t=$ti;
}else{
$t = $this->input->post('t');
if (!$t) $t = 0;
if( $this->input->post('ileri') ) {
$t=$t+1;
if($t>($uz-1)){
$t=$uz-1;
}
} // Forward button was pressed;
if( $this->input->post('geri') ) {
$t=$t-1;
if($t<0){
$t=0;
}
} // Back button was pressed;
}
I'm not familiar with codeigniter, but I've always passed GET variables in this manner:
URL = www.site.com/folder/webpage.php?myvariable=myvalue
I would retrieve that value this way:
$x = $_GET['myvariable'];
or with codeigniter: (I think)
$x = $this->input->get('myvariable');
Tailored to your example, I would personally de-obfuscate your loop code just a little and instead of switching from PHP to HTML and back in one line, I would simply echo both from PHP like this:
(I also don't exactly understand the url you're using, so here is my approximate)
<?php
for ($b=0; $b<=(count($hml)-1); $b++)
{
echo '',$hml[$b],' ';
}
?>
I found out how Codeigniter solves the problem =>
$get = $this->uri->uri_to_assoc();
if(isset($get['hamleno'])){
$data['ti'] = $get['hamleno'];
}
This sends the $b assigned to $hamleno together with all the other stuff in $data.
Thank you all for your kind comments

How to make a php variable $_POST upon clicking it?

I'm trying to make $suggestion[$ss_count] become a clickable link that does a $_POST once it is clicked. I'm trying to achieve a query expansion sort of an effect. The word itself of course needs to be the information posted and it needs to be recognized as
if ($_POST['query'])
The code I use for this is:
<?php
if ($_POST['query'])
{
$query = urlencode($_POST['query']);
$s_count = 0;
$ss_count = 0;
$query = 'http://www.dictionaryapi.com/api/v1/references/collegiate/xml/'.$query.'? key=135a6187-af83-4e85-85c1-1a28db11d5da';
$xml = new SimpleXMLIterator(file_get_contents($query));
foreach ($xml -> suggestion as $suggestion[$s_count])
{
$s_count++;
}
if ($s_count > 1)
{
echo ('<h4>Did you mean?</h4>');
while ($ss_count <=$s_count)
{
echo ($suggestion[$ss_count].'<br>');
$ss_count++;
}
}
}
?>

How to implement this image preloader into my php file?

I want to have my images which are processed via ajax to be preloaded visually rather then the usual loading of images where you see them build up from top to bottom. Please take a look here. What you see there is what I want to have in my php file visually.
The part where the pictures are loaded from the database are the following:
$sql = "SELECT * FROM `fabric`".$filter;
$result=mysql_query("$sql");
//echo $sql;
$data = "";
$ii = 0;
$m = 0;
while($myrow = mysql_fetch_array($result)){
$ii++;
$m++;
if ($m == 1) $data = $data."<div class=\"page current\">";
elseif ($ii == 1) $data = $data."<div class=\"page\">";
$data = $data."<img src=\"".$image_directory.$myrow['thumbnail']."\" width=\"100 px\" height=\"100 px\"><div class=\"fb_name\">".$myrow['name']."</div>\n";
if ($ii == 10) {
$data = $data."</div>";
$ii = 0;
}
}
if ($ii != 10) {
$data = $data."</div>";
}
if (empty($data)) echo "No result";
else echo $data;
?>
I really don't know how to change the php in order to have the effect shown in the demo.
Thank you for all constructive advices and forgive my noobiness :)
You will need javascript for this, you canĀ“t do it in php alone. The basic idea is to hide your images using for example a visibility: hidden and have them fade in when they are completely loaded. And at load-time you position a loading image on top that you remove when you start fading in the image.
As the example you've given, is a plugin, perhaps you can even use that one instead of writing it yourself.

Is there a way to tell Drupal not to cache a specific page?

I have a custom php page that processes a feed of images and makes albums out of it. However whenever i add pictures to my feed, the Drupal page doesn't change until I clear the caches.
Is there a way to tell Drupal not to cache that specific page?
Thanks,
Blake
Edit: Drupal v6.15
Not exactly sure what you mean oswald, team2648.com/media is hte page.
I used the php interpreter module. Here is the php code:
<?php
//////// CODE by Pikori Web Designs - pikori.org ///////////
//////// Please do not remove this title, ///////////
//////// feel free to modify or copy this software ///////////
$feedURL = 'http://picasaweb.google.com/data/feed/base/user/Techplex.Engineer?alt=rss&kind=album&hl=en_US';
$photoNodeNum = 4;
$galleryTitle = 'Breakaway Pictures';
$year = '2011';
?>
<?php
/////////////// DO NOT EDIT ANYTHING BELOW THIS LINE //////////////////
$album = $_GET['album'];
if($album != ""){
//GENERATE PICTURES
$feedURL= "http://".$album."&kind=photo&hl=en_US";
$feedURL = str_replace("entry","feed",$feedURL);
$sxml = simplexml_load_file($feedURL);
$column = 0;
$pix_count = count($sxml->channel->item);
//print '<h2>'.$sxml->channel->title.'</h2>';
print '<table cellspacing="0" cellpadding="0" style="font-size:10pt" width="100%"><tr>';
for($i = 0; $i < $pix_count; $i++) {
print '<td align="center">';
$entry = $sxml->channel->item[$i];
$picture_url = $entry->enclosure['url'];
$time = $entry->pubDate;
$time_ln = strlen($time)-14;
$time = substr($time,0,$time_ln);
$description = $entry->description;
$tn_beg = strpos($description, "src=");
$tn_end = strpos($description, "alt=");
$tn_length = $tn_end - $tn_beg;
$tn = substr($description, $tn_beg, $tn_length);
$tn_small = str_replace("s288","s128",$tn);
$picture_url = $tn;
$picture_beg = strpos($picture_url,"http:");
$picture_len = strlen($picture_url)-7;
$picture_url = substr($tn, $picture_beg, $picture_len);
$picture_url = str_replace("s288","s640",$picture_url);
print '<a rel="lightbox[group]" href="'.$picture_url.'">';
print '<img '.$tn_small.' style="border:1px solid #02293a"><br>';
print '</a></td> ';
if($column == 4){ print '</tr><tr>'; $column = 0;}
else $column++;
}
print '</table>';
print '<br><center>Return to album</center>';
} else {
//GENERATE ALBUMS
$sxml = simplexml_load_file($feedURL);
$column = 0;
$album_count = count($sxml->channel->item);
//print '<h2>'.$galleryTitle.'</h2>';
print '<table cellspacing="0" cellpadding="0" style="font-size:10pt" width="100%"><tr>';
for($i = 0; $i < $album_count; $i++) {
$entry = $sxml->channel->item[$i];
$time = $entry->pubDate;
$time_ln = strlen($time)-14;
$time = substr($time,0,$time_ln);
$description = $entry->description;
$tn_beg = strpos($description, "src=");
$tn_end = strpos($description, "alt=");
$tn_length = $tn_end - $tn_beg;
$tn = substr($description, $tn_beg, $tn_length);
$albumrss = $entry->guid;
$albumrsscount = strlen($albumrss) - 7;
$albumrss = substr($albumrss, 7, $albumrsscount);
$search = strstr($time, $year);
if($search != FALSE || $year == ''){
print '<td valign="top">';
print '<a href="/node/'.$photoNodeNum.'?album='.$albumrss.'">';
print '<center><img '.$tn.' style="border:3px double #cccccc"><br>';
print $entry->title.'<br>'.$time.'</center>';
print '</a><br></td> ';
if($column == 3){
print '</tr><tr>'; $column = 0;
} else {
$column++;
}
}
}
print '</table>';
}
?>
Thanks for your answer.
The site you linked gave me some new verbiage to search with, and thus I found this:
http://www.drupalcoder.com/story/365-disable-drupals-page-cache-for-some-pages
which then led me to this:
http://drupal.org/project/cacheexclude
which did exactly what I wanted.
Hope this helps.
That is for Drupal 6.
This doesn't answer your specific question about caching, but -- consider using Drupal-native solutions like the Picasa module for things like this.
When you use non-Drupal PHP applications in a Drupal environment like you have here, you get weird interactions with other Drupal components. Drupal modules are build with Drupal in mind, so things like sane caching usually come built in.
Write this code line at the top of the custom page you dont want to be cached:
$GLOBALS['conf']['cache'] = FALSE;
For Drupal 6,
If you just want to exclude a specific page from being cached then you can use Cache exclude module, where you just have to provide a url.
for drupal 7 also it is available but its in the development version.
Yes you can do it programmatically and the below code is valid for Drupal 6 and 7 both.
Reference : http://techrappers.com/post/27/how-prevent-javascript-and-css-render-some-drupal-pages
/**
* Implements hook_init().
*/
function MODULE_NAME_init() {
global $conf;
// current_path() is the path on which you want to turn of JS or CSS cache
if (current_path() == 'batch' || current_path() == 'library-admin') {
// If you want to force CSS or JS cache to turned off
$conf['preprocess_js'] = FALSE;
$conf['preprocess_css'] = FALSE;
// If you want normal caching to turned off
drupal_page_is_cacheable(FALSE);
}
}
Please Note that drupal_page_is_cacheable(FALSE); can only turn off normal caching, it will not force JS caching to be turned off automatically unless you use $conf['preprocess_js'] = FALSE.

How do I write Smarty Block Plugins that loop over database records

Given a Category (parent) and Product (child) tables in a database, say, I want to create Smarty Block Plugins that would enable template snippets similar to this:
{products category="Some Category"}
<h1>{products_name}</h2>
<p>{products_description}</p>
{/products}
I believe plugins like these would help avoid repeated chunks of code that read a database and do a smarty-assign on the result in my controller.
I know how to write this as a smarty function. But I am looking for a block version to give the template designer the flexibility to style the individual columns in whatever way he wants. I am a long-time Perl programmer and new to Smarty. Perl users will recognise something like this in the Movable Type Templating System for example, and I wonder if a smarty version is possible.
Is something like this possible in Smarty at all? Is it a good thing to make a DB call from inside a smarty plugin?
My suggestion is use configuration array ($conf) with the SQL query template to use inside the plugin for simple modification.
Of course is not a good thing make a DB call inside the Smarty plugin. Instead, you can load the results in the $conf array making the DB call in the PHP script and unload in the plugin, as you wish.
This is the Smarty plugin:
<?php
function smarty_block_products($params, $content, &$smarty, &$repeat)
{
global $conf;
$category = $params['category'];
$md5 = md5($category);
if (empty($content))
{
if (empty($category))
{
$smarty->trigger_error("products: missing 'category' parameter");
}
$sql = str_replace('{$category}', $category, $conf['get-products-sql-template']);
$query = mysql_query($sql);
$result = array();
while ($row = mysql_fetch_assoc($query))
{
$result[] = $row;
}
if (count($result) == 0)
{
$result = false;
}
$GLOBALS['__SMARTY_PRODUCTS'][$md5] = $result;
}
if (is_array($GLOBALS['__SMARTY_PRODUCTS'][$md5]))
{
$field = "product";
if (isset($params['item']))
{
$field = $params['item'];
}
$product = array_shift($GLOBALS['__SMARTY_PRODUCTS'][$md5]);
$smarty->assign($field, $product);
if (count($GLOBALS['__SMARTY_PRODUCTS'][$md5]) == 0)
{
$GLOBALS['__SMARTY_PRODUCTS'][$md5] = false;
}
$repeat = true;
} else {
$repeat = false;
}
echo $content;
}
?>
the Smarty template:
{products category="Some Category" item=product}
<h1>{$product.name}</h2>
<p>{$product.description}</p>
{/products}
and the PHP:
<?php
require 'Smarty/Smarty.class.php';
$smarty = new Smarty;
$conf['get-products-sql-template'] = 'SELECT product.* FROM product INNER JOIN category ON category.id = product.category_id WHERE category.title = \'{$category}\'';
$smarty->display('test.tpl');
?>

Categories