JQuery Plugin with database records- Codeigniter - php

I have found following JQuery plugin to show the records in alphabetical orders.
http://esteinborn.github.io/jquery-listnav/
I am using demo one. I have implemented in codeigniter and got successful to print all the records. However, all the records appearing only under "All" option. It does not display records alphabetically.
I am not sure either am I using this plugin in the correct way ? Following is my code:
<?php if (!$companies): ?>
<tr>
<td colspan="4">No companies in the system yet...</td>
</tr>
<?php
else :
?> <ul id="demoOne" class="demo">
<?php
$i = 0;
foreach($companies as $company) :
?>
<li>
<?php print $company->title; ?>
</li>
</ul>
</tr>
<?php
$i++;
endforeach;
endif;
?>
Following is script:
<script>
$(function(){
$('#demoOne').listnav();
});
</script>

Your html doesn't seem to be correct. Try:
<?php if (!$companies): ?>
<tr>
<td colspan="4">No companies in the system yet...</td>
</tr>
<?php else : ?>
<tr>
<ul id="demoOne" class="demo">
<?php
$i = 0;
foreach($companies as $company) :
?>
<li>
<?php print $company->title; ?>
</li>
<?php
$i++;
endforeach;
?>
</ul>
</tr>
<?php
endif;
?>

Related

how to allow more than 1 rows to appear horizontally

This is an example of what I want to achieve
but what I was able to display is 1 product per row.
This is what I have done and but is not working as intended.
<ol>
<?php
$no = 1;
foreach($projects as $project):?>
<?php if($project['finish'] == 'no'):?>
<li><?=$no?></li>
<li><?=$project['type']?></li>
<li><?=$project['date_started']?></li>
<li><?=$project['brief_description']?></li>
<li><?=$project['full_description']?></li>
<li>
<?php foreach($images as $image):?>
<?php if($image['project_id'] == $project['id']):?>
<img src="img/<?=$image['name']?>">
<?php endif;?>
<?php endforeach;?>
</li>
<li>
Contact admin
</li>
<?php endif;?>
if($no % 5 === 0):
echo "<br>";
endif;
<?php $no++; ?>
<?php endforeach;?>
How can I get the code to display 5 lists per row
<html>
<body>
<table>
<?php
echo '<tr>';
for($i=1;$i<100;$i++)
{
echo '<td>'.$i.'</td>';
if($i%5==0)
{
echo $i;
echo '</tr><tr>';
}
}
?>
</table>
</body>
</html>
This will you the idea

PhpStorm: How to separate PHP & HTML indentation

Is it possible to configure PhpStorm 8 to indent HTML and PHP code separately?
I'll copy the examples from this question: How to properly indent PHP/HTML mixed code?
How PhpStorm formats the code currently:
<table>
<?php foreach ($rows as $row): ?>
<tr>
<?php if ($row->foo()): ?>
<?php echo $row ?>
<?php else: ?>
Something else
<?php endif ?>
</tr>
<?php endforeach ?>
</table>
How I want it to look like:
<table>
<?php foreach ($rows as $row): ?>
<tr>
<?php if ($row->foo()): ?>
<?php echo $row ?>
<?php else: ?>
Something else
<?php endif ?>
</tr>
<?php endforeach ?>
</table>
No, not currently possible. See this comment

Editing a php scripèt divs to output a table

Hey guys ok so i'm wokring on a clients Weekly Newsletter i'm working with Joomla 2.5.19 and using the enterprise version of acymailling to send it out. I'm kicking my heading in at the moment because of outlook, i'm using a module from Jreviews that publishes the latest reviews submitted to the site in the newsletter, it all works fine except in outlook.
the out put of the script is meant to be a 2x2table with the 4 latest reviews in it. the only prob is outlook seems to hates me using Div for a table and stacks the 2x2 table into a verticle kaotic mess.
the code i'm trying to edit is:
'>
<?php /* root element for the items */ ?>
<div class="jrModuleItems <?php echo $orientation . ' jrThumbnail'.ucfirst($tn_position); ?>">
<?php /* new page starts here */
$pages = array_chunk($reviews,$limit);
$j=0;
foreach($pages AS $page):
?>
<div class="jr-results jrResults jrModuleContainer jrReviewsModule">
<?php $i=0;
while(!empty($page)):
$i++; $j++; $review = array_shift($page); ?>
<?php
// Process link title
$listing_title = ($listing_title_chars && mb_strlen($review['Listing']['title'])>$listing_title_chars) ? $Text->truncate($review['Listing']['title'],$listing_title_chars) : $review['Listing']['title'];
$review_title = ($review_title_chars && mb_strlen($review['Review']['title'])>$review_title_chars) ? $Text->truncate($review['Review']['title'],$review_title_chars) : $review['Review']['title'];
$link_title = str_replace('{listing_title}',$listing_title,$link_title_format);
$link_title = str_replace('{review_title}',$review_title,$link_title);
// Create the thumbnail
$tn_show and $mainMediaThumb = $Media->thumb(Sanitize::getVar($review,'MainMedia'),array('listing'=>$review,'size'=>$tn_size,'mode'=>$tn_mode,'css_size'=>true));
?>
<?php $lastItem = ($i == $columns) ? ' jrLastItem' : ''; ?>
<div class="jrModuleItem<?php echo $lastItem; ?>" style="width: <?php echo $item_width; ?>%; padding-right: <?php echo $item_padding; ?>%;">
<?php if($show_numbers):?><div class="jrModuleItemNumber"><?php echo $j;?>.</div><?php endif;?>
<?php if($tn_show && $mainMediaThumb && $tn_position != 'bottom'):?>
<!-- Listing Thumbnail -->
<div class="jrModuleItemThumbnail">
<?php echo $Html->sefLink($mainMediaThumb,$review['Listing']['url']);?>
<?php // Uncomment line below to show reviewer avatar. You can comment or remove the thumbnail code above
// echo $Community->avatar($review);
?>
</div>
<?php endif;?>
<div class="jrModuleItemContent">
<!-- Listing Title -->
<div class="jrModuleItemTitle">
<?php echo $Html->sefLink($link_title,$review['Listing']['url']);?>
<?php if(Sanitize::getString($review['Listing'],'tag')):?>
<span class="jrComponentLabel jrStatusLabel jrBlue">
<?php echo Sanitize::getString($review['Listing'],'tag');?>
</span>
<?php endif;?>
</div>
<!-- Rating -->
<?php if ( $review['Criteria']['state'] == 1 ):?>
<div class="jrOverallRatings">
<?php if($review['Review']['editor'] == 1):?>
<?php
$rating_stars = $Rating->drawStars($review['Rating']['average_rating'], $this->Config->rating_scale, 'editor');
$rating_value = $Rating->round($review['Rating']['average_rating'],$this->Config->rating_scale);
?>
<div class="jrOverallEditor" title="<?php __t("Editor rating"); ?>">
<div class="jrRatingStars"><?php echo $rating_stars ?></div>
<span class="jrRatingValue"><?php echo $rating_value?></span>
</div>
<?php else:?>
<?php
$rating_stars = $Rating->drawStars($review['Rating']['average_rating'], $this->Config->rating_scale, 'user');
$rating_value = $Rating->round($review['Rating']['average_rating'],$this->Config->rating_scale);
?>
<div class="jrOverallUser" title="<?php __t("User rating"); ?>">
<div class="jrRatingStars"><?php echo $rating_stars ?></div>
<span class="jrRatingValue"><?php echo $rating_value?></span>
</div>
<?php endif;?>
</div>
<?php endif;?>
<!-- Reviewer name -->
<div class="jrModuleItemReviewer">
<span class="reviewer"><?php __t("Reviewed by");?> <?php echo $Community->screenName($review);?></span>
</div>
<?php if($fields): ?>
<!-- Custom Fields -->
<div class="jrModuleFields">
<?php
foreach ($fields as $field):
$field = trim($field);
$field_value = $CustomFields->field($field,$review);
?>
<?php if($field_value != ''):?>
<div class="jrModuleFieldDiv <?php echo lcfirst(Inflector::camelize($field)); ?>">
<span class="jrModuleFieldTitle"><?php echo $CustomFields->label($field, $review); ?>: </span>
<span class="jrModuleFieldValue"><?php echo $field_value; ?></span>
</div>
<?php endif;?>
<?php endforeach; ?>
</div>
<?php endif;?>
<?php if($show_comments && trim($review['Review']['comments'])!=''):?>
<!-- Review Comments -->
<div class="jrModuleItemInfo">
<?php
// Uncomment line below to show review title
// echo '<strong>' . $review['Review']['title'] . '</strong><br />';
?>
<span class="comments">"<?php echo $Text->truncateWords($review['Review']['comments'],$comments_words,'...');?>"</span>
</div>
<?php endif;?>
</div>
<?php if($tn_show && $mainMediaThumb && $tn_position == 'bottom'):?>
<!-- Listing Thumbnail -->
<div class="jrModuleItemThumbnail">
<?php echo $Html->sefLink($mainMediaThumb,$review['Listing']['url']);?>
<?php // Uncomment line below to show reviewer avatar. You can comment or remove the thumbnail code above
// echo $Community->avatar($review);
?>
</div>
<?php endif;?>
</div>
<?php /*end of row , start new row*/
if(!empty($page) && ($i == $columns || $total == $j)):?>
<div class="jrDivider"></div>
<?php $i=0; endif;?>
<?php endwhile;?>
</div>
<?php endforeach; /* new page ends here */?>
</div><?php /* end items root element */?>
Does any one have the slightest idea how i could turn this into a for loop that outputs a table?
The quickest path from A to B is to edit the attached code to render a table versus stacked divs.
* EDIT *
The answer to your comment isn't so simple as replace all of 'A' with 'B.' A div is a "self-contained" HTML element while a table is a grouping with syntax rules.
An HTML table is constructed like so:
<table>
<thead>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1 - Column 1</td>
<td>Row 1 - Column 2</td>
</tr>
<tr>
<td>Row 2 - Column 1</td>
<td>Row 2 - Column 2</td>
</tr>
</tbody>
</table>
The foreach loop in your code should create a row through each iteration. Which means you need to render your table, thead and tbody tags outside of this looping code. Inside the loop, you render a new row each iteration, which requires an opening/closing tag for the row and an opening/closing for each column.
Hope this helps.

While inside another while

I am trying to display data from two different Mysql tables in the same html table. Do do that I have put a while loop inside another while loop. The problem is that in the table the data of the second loop is displayed only on the first raw of the html table. I really don't know what is wrong. Thanks for your help.
<?php
while($results = mysql_fetch_array($raw_results)){
echo '<td>';
echo '<a href="linkto.php?data='.ucfirst($results['song_name']).'" class="iframe"><img src="icons/1384070574_95.png"> ';
echo '<a href="'.ucfirst($results['song_name']).'" class="clapping">';
echo '<img src="icons/Hand-icon.png" id="songs'.$pictureid.'" onClick="action(\'songs'.$pictureid.'\')"/></a>';
echo '</td>';
echo '</tr>';
if (isset($userid)){
echo '<td>
<div id="cssmenu">
<ul>
li class="has-sub><span><img src="icons/1384074758_document_music_add.png"></span>
<ul>
<li class="has-sub"><span>Create a Playlist</span></li>';
while($playlist = mysql_fetch_array($raw_playlist)){
echo'<li class="has-sub"><span>'.ucfirst($playlist['title']).'</span></li>';
}
echo'</ul>
</li>
</ul>
</div>
</td>';
}
echo' </tr>
';
$pictureid = $pictureid + 1;
$songid= $songid + 1;
}
echo '</tbody>';
?>
As mentioned in the comments, you may have a problem with your nested data depending on what you're trying to show.
However, your HTML is a mess, missing some opening and closing tags, which may mean that some data is being sent to the browser but not being displayed. Have you looked at the source of the page in the browser to check the data is not there? Until you do, we cannot be sure whether the missing data is an HTML, SQL or PHP error.
You should try to limit the amount of HTML that you echo from PHP for this reason, and I've tidied it up a bit and added missing tags below. See if that helps at all.
<?php while ($results = mysql_fetch_array($raw_results)) : ?>
<tr>
<td>
<img src="icons/1384070574_95.png">
<img src="icons/Hand-icon.png" id="songs<?php echo $pictureid; ?>" onClick="action('songs<?php echo $pictureid; ?>')" />
</td>
</tr>
<?php if (isset($userid)) : ?>
<tr>
<td>
<div id="cssmenu">
<ul>
<li class="has-sub><span><img src="icons/1384074758_document_music_add.png"></span>
<ul>
<li class="has-sub"><span>Create a Playlist</span></li>
<?php while ($playlist = mysql_fetch_array($raw_playlist)) : ?>
<li class="has-sub"><span><?php echo ucfirst($playlist['title']); ?></span></li>
<?php endwhile; ?>
</ul>
</li>
</ul>
</div>
</td>
<?php endif; ?>
</tr>
<?php
$pictureid++;
$songid++;
endwhile;

Magento - pull one single customer review

I've been trying to pull one single customer review onto the product page.
I've no code to show as honestly i'm not sure where to start and can't find any mention of it online.
Anyone have any ideas?
I wrote a tutorial earlier on bringing all the review elements onto the product page, so you could follow this tutorial: http://www.e-commercewebdesign.co.uk/blog/magento-tutorials/product-reviews-on-product-view-page.php
All you'd have to do is rename the list block and bring it out in the same way. Then simply modify the loop which brings out the reviews in any way you see fit. E.g. limit to a certain number or only echo out review from a certain user.
EDIT:
To get the latest review is quite simple because the reviews are in date order anyway.
Go to review > product > list.phtml
Replace the code in that file with this:
<?php $_items = $this->getReviewsCollection()->getItems();?>
<div class="box-collateral box-reviews" id="customer-reviews">
<?php if (count($_items)):?>
<h2><?php echo $this->__('Customer Reviews') ?></h2>
<?php echo $this->getChildHtml('toolbar') ?>
<dl>
<?php $r_count = 0; ?>
<?php foreach ($_items as $_review):?>
<?php if ($r_count == 0) { ?>
<dt>
<?php echo $this->htmlEscape($_review->getTitle()) ?> <?php echo $this->__('Review by <span>%s</span>', $this->htmlEscape($_review->getNickname())) ?>
</dt>
<dd>
<?php $_votes = $_review->getRatingVotes(); ?>
<?php if (count($_votes)): ?>
<table class="ratings-table">
<col width="1" />
<col />
<tbody>
<?php foreach ($_votes as $_vote): ?>
<tr>
<th><?php echo $this->escapeHtml($_vote->getRatingCode()) ?></th>
<td>
<div class="rating-box">
<div class="rating" style="width:<?php echo $_vote->getPercent() ?>%;"></div>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<?php echo nl2br($this->htmlEscape($_review->getDetail())) ?>
<small class="date"><?php echo $this->__('(Posted on %s)', $this->formatDate($_review->getCreatedAt()), 'long') ?></small>
</dd>
<?php } ?>
<?php $r_count++; ?>
<?php endforeach; ?>
</dl>
<?php echo $this->getChildHtml('toolbar') ?>
<?php endif;?>
<?php echo $this->getChildHtml('review_form') ?>
</div>
I've simple put an interator into the loop $r_count and put a check inside the foreach which prevent it from progressing on the next loop iteration.

Categories