I am attempting to display a list of users based on a month value. I want to display January then all the users associated with it etc...
What i have now is working correctly for the first months then does nothing after. I have comments in the code and a live version of this code is running at: http://blog.funeraldirectorslife.com/participants/
<?php
/*
Template Name: Participants
*/
?>
<?php
function display_user($author, $month){
$ID = $author->ID;
$full_name = get_the_author_meta('display_name', $ID);
$usr_name = get_the_author_meta('user_nicename', $ID);
$sab_descriptiom = get_cimyFieldValue("$ID", 'Sabbatical_desc');
$sab_start = get_cimyFieldValue("$ID", 'Sabbatical_Start');
$sab_end = get_cimyFieldValue("$ID", 'Sabbatical_End');
$sab_month = get_cimyFieldValue("$ID", 'Sabbatical_Month');
$author_posts = $author->num_posts;
//$months = array(January, February, March, April, May, June, July, August, September, October, November, December);
//echo $sab_month;
if ($sab_month == $month){
echo "<li>";
echo "<h4 class=\"nomar\"><a href=\"http://blog.funeraldirectorslife.com/author/"
. $usr_name
."\">"
.$full_name
."("
. $author_posts
. ")"
. "</a>"
. "</h4>";
echo $sab_start
. " - "
. $sab_end
. "<br />";
echo $sab_descriptiom
. "<br />"
. $sab_month . "</br>" . "</li>" . "\n";
}
else {
return;
}
}
?>
<?php get_header(); ?>
<div id="bd" class="grid_12 alpha omega clearfix">
<?php get_sidebar(); ?>
<div id="main" class="grid_9 omega">
<?php include(TEMPLATEPATH . '/banner.php'); ?>
<div class="unit">
<!--
<div class="head">
<div class="title"><h3><span>Blog Entries</span></h3></div>
</div>
//-->
<div class="body clearfix">
<ul class="styled_list">
<li class ="alpha"><h3 class="nomar"><span><?php the_title(); ?></span></h3></li>
<?php
//grab authors ids, post count, and extended info from database
//fill $authors array with data
$sql = "SELECT * FROM `wp_users` WHERE 1 ORDER BY ID";
$results = $wpdb->get_results($sql);
$authors = $results;
$author_count = array();
$rows = $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author");
foreach ($rows as $row) {
$author_count[$row->post_author] = $row->count;
}
//combine queries
foreach( $authors as $author ) {
$author->num_posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0;
}
//month array for comparing with sabbatical month
$months = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October','November', 'December');
//tried old method for iterating arrays --> same result
/*reset($months);
while (list($key, $month) = each($months)){
echo "<h2 class=\"nomar\">" . $month . "</h2>" . "\n";
foreach($authors as $author) {
display_user($author, $month);
//echo $author->ID;
}
}*/
foreach($months as $month ) {
echo "<h2 class=\"nomar\">" . $month . "</h2>" . "\n";
foreach($authors as $author) {
display_user($author, $month);
//echo $author->ID;
}
//lists authors by ID - just making sure array is intact after each author loop
/*foreach($authors as $author) {
$ID = $author->ID;
$foo = get_cimyFieldValue("$ID", 'Sabbatical_Month');
echo $ID . $foo . "<br /> . "\n"";
}*/
}
?>
</ul>
</div>
</div>
</div>
</div>
<?php get_footer();
?>
I'm not sure if it will work properly, but I have updated your code somewhat. Mainly I added the trim() function when comparing your $sab_month and $month but I also cleaned up your code a bit. You can embed variables inside of a double-quoted string in PHP, so you don't have to concatenate them :-)
<?php /* Template Name: Participants */ ?>
<?php
function display_user($author, $month){
$ID = $author->ID;
$full_name = get_the_author_meta('display_name', $ID);
$usr_name = get_the_author_meta('user_nicename', $ID);
$sab_descriptiom = get_cimyFieldValue("$ID", 'Sabbatical_desc');
$sab_start = get_cimyFieldValue("$ID", 'Sabbatical_Start');
$sab_end = get_cimyFieldValue("$ID", 'Sabbatical_End');
$sab_month = get_cimyFieldValue("$ID", 'Sabbatical_Month');
$author_posts = $author->num_posts;
//$months = array(January, February, March, April, May, June, July, August, September, October, November, December);
//echo $sab_month;
if (trim($sab_month) == trim($month)){
echo "<li>";
echo " <h4 class='nomar'><a href='http://blog.funeraldirectorslife.com/author/$usr_name'>$full_name($author_posts)</a></h4>";
echo " $sab_start - $sab_end<br />";
echo " $sab_descriptiom<br />";
echo " $sab_month</br>";
echo "</li>\n";
}
/* Not necessary. The function will return when it hits the end
else {
return;
}
*/
}
?>
<?php get_header(); ?>
<div id="bd" class="grid_12 alpha omega clearfix">
<?php get_sidebar(); ?>
<div id="main" class="grid_9 omega">
<?php include(TEMPLATEPATH . '/banner.php'); ?>
<div class="unit">
<!--
<div class="head">
<div class="title"><h3><span>Blog Entries</span></h3></div>
</div>
//-->
<div class="body clearfix">
<ul class="styled_list">
<li class ="alpha"><h3 class="nomar"><span><?php the_title(); ?></span></h3></li>
<?php
//grab authors ids, post count, and extended info from database
//fill $authors array with data
$sql = "SELECT * FROM `wp_users` WHERE 1 ORDER BY ID";
$results = $wpdb->get_results($sql);
$authors = $results;
$author_count = array();
$rows = $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author");
foreach ($rows as $row) {
$author_count[$row->post_author] = $row->count;
}
//combine queries
foreach( $authors as $author ) {
$author->num_posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0;
}
//month array for comparing with sabbatical month
$months = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October','November', 'December');
//tried old method for iterating arrays --> same result
/*reset($months);
while (list($key, $month) = each($months)){
echo "<h2 class=\"nomar\">" . $month . "</h2>" . "\n";
foreach($authors as $author) {
display_user($author, $month);
//echo $author->ID;
}
}*/
foreach($months as $month) {
echo "<h2 class='nomar'>$month</h2>\n";
foreach($authors as $author) {
display_user($author, $month);
//echo $author->ID;
}
//lists authors by ID - just making sure array is intact after each author loop
/*foreach($authors as $author) {
$ID = $author->ID;
$foo = get_cimyFieldValue("$ID", 'Sabbatical_Month');
echo $ID . $foo . "<br /> . "\n"";
}*/
}
?>
</ul>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
appearantly this if fails after the first month if ($sab_month == $month)
Maybe some typo, case differences perhaps? I'd try adding echo "Sab month == ",$sab_month,"\n script month ==",$month;
Put it just before the if. good luck
I know I used comma's , thats just another way of using echo.
Related
I'm trying to create a page where i can choose the hour to take a date with someone.
In my database i already have 3 dates for today as here :
at 9:00, 10:00 and 12:00 so these hours should not apear in the page.
But what i have is this :
9:30:00
9:30:00
10:00:00
10:30:00
11:00:00
11:00:00
11:00:00
11:30:00
11:30:00
11:30:00
12:00:00
12:00:00
14:00:00
14:00:00
14:00:00
...
I think there is an algorythm problem but i'm not shure there is the code :
<?php
/**
* Template Name: calendrier
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
//
get_header(); ?>
<div id="primary" <?php generate_do_element_classes( 'content' ); ?>>
<main id="main" <?php generate_do_element_classes( 'main' ); ?>>
<?php
do_action( 'generate_before_main_content' );
if(!isset($_GET['mydate'])){
$today=getdate();
$_GET['mydate']=$today['year']."-".$today['mon']."-".$today['mday'];
}
echo "<p>Entrez une date :</br><form action=\"\" method=\"get\"><input type=\"hidden\" name=\"page_id\" value=\"21\"><input type=\"hidden\" name=\"myuser\" value=\"".$_GET['myuser']."\" ><input type=\"hidden\" name=\"myform\" value=\"".$_GET['myform']."\"><input type=\"date\" name=\"mydate\" /></p><input type=\"submit\" value=\"Modifier la date\" /></form>";
$mydata = $wpdb->get_results(
$wpdb->prepare("
SELECT *
FROM cal
WHERE user_id = %s
AND date = %s
",
$_GET['myuser'],
$_GET['mydate']
)
);
$disp = $wpdb->get_results(
$wpdb->prepare("
SELECT * from disponibility where user_id = %s and date = %s
",
$_GET['myuser'],
$_GET['mydate']
)
);
$cat = $wpdb->get_row(
$wpdb->prepare("
SELECT * from cat where id = %s
",
$_GET['myform']
)
);
echo "<h1>Calendrier ".$_GET['mydate']."</h1>";
foreach($disp as $dispun){
$debut = $dispun->start; // start hour
$fin = $dispun->end; // end hour
$debut_parts = explode(":", $debut);
$fin_parts = explode(":", $fin);
$debut_parts[0] = intval($debut_parts[0]); // int start hour
$debut_parts[1] = intval($debut_parts[1]); // int start minutes
$debut_parts[2] = intval($debut_parts[2]); // int start seconds
$fin_parts[0] = intval($fin_parts[0]); // int end hour
$fin_parts[1] = intval($fin_parts[1]); // ...
$fin_parts[2] = intval($fin_parts[2]);
while($debut_parts[0] < $fin_parts[0] || ($debut_parts[0] == $fin_parts[0] && $debut_parts[1] < $fin_parts[1]) ){ // foreach half hour
if($mydata != null){ // if there is already an date recorded
foreach($mydata as $mydataun){ // foreach recorded date
$itime = $mydataun->time;
$jtime = explode(":", $itime);
$jtime[0] = intval($jtime[0]);
$jtime[1] = intval($jtime[1]);
$jtime[2] = intval($jtime[2]);
if(strval($jtime[0]).":".strval($jtime[1]).":".strval($jtime[2]) == strval($debut_parts[0]).":".strval($debut_parts[1]).":".strval($debut_parts[2])){
if($debut_parts[1]== 0 && $mydataun->duration == 1){
$debut_parts[1]+=30;
}elseif($mydataun->duration == 1){
$debut_parts[0]+=1;
$debut_parts[1]=0;
}
}else{
echo "<a href=\"https://someaddress/?page_id=24&mydate=".$_GET['mydate']."&myuser=".$_GET['myuser']."&myform=".$_GET['myform']."&mytime=".strval($debut_parts[0]).":";
if($debut_parts[1]==0){
echo "00:00";
}else{
echo "30:00";
}
echo "\">".$debut_parts[0].":";
if($debut_parts[1]==0){
echo "00:00";
}else{
echo "30:00";
}
echo "</a></br>";
}
}
}else{
echo "<a href=\"https://someaddress/?page_id=24&mydate=".$_GET['mydate']."&myuser=".$_GET['myuser']."&myform=".$_GET['myform']."&mytime=".strval($debut_parts[0]).":";
if($debut_parts[1]==0){
echo "00:00";
}else{
echo "30:00";
}
echo "\">".$debut_parts[0].":";
if($debut_parts[1]==0){
echo "00:00";
}else{
echo "30:00";
}
echo "</a></br>";
}
if($debut_parts[1]== 0){
$debut_parts[1]+=30;
}else{
$debut_parts[0]+=1;
$debut_parts[1]=0;
}
}
}
do_action( 'generate_after_main_content' );
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
/**
* generate_after_primary_content_area hook.
*
* #since 2.0
*/
do_action( 'generate_after_primary_content_area' );
generate_construct_sidebars();
get_footer();
echo "<a href=\"https://someaddress/?page_id=24&mydate=".$_GET['mydate']."&myuser=".$_GET['myuser']."&myform=".$_GET['myform']."&mytime=".strval($debut_parts[0]).":";
if($debut_parts[1]==0){
echo "00:00";
}else{
echo "30:00";
}
echo "\">".$debut_parts[0].":";
if($debut_parts[1]==0){
echo "00:00";
}else{
echo "30:00";
}
echo "</a></br>";
Have to be at the end of while loop
I got some records with column 'id','time','catagory','content' saved in MySql database.Demo PHP(Actually I am using Yii, the data were provided by dataprovider.)
And I need to present the data in a user-friendly way.
The list were group by "Week"=>"Date"=>"record". Demo Output html
Could some give me an smart way to do the php loop?
Should I need to do an Week loop to check the exist week and saved an key-value array,
then to check the any record were on the same day and saved in another array,
then finally do the output loop to show the html?Many thanks.
<div class="tree">
<ul>
<li>
<span>2014, Week 2 , 2014-01-05~2014-01-11</span>
<ul>
<li>
<span>Monday, January 6</span>
<ul>
<li>
<div class="record">
<span>08:00:30</span><br>
<span>Play</span><br>
<span>Do something good...</span><br>
</div>
</li>
</ul>
</li>
This is the php code:
<?php
//fake data setting
$recordlist=Array();
$record=Array();
$record['time']='2014-01-06 08:00:30';
$record['catagory']='Play';
$record['content']='Do something good...';
$recordlist[]=$record;
$record=Array();
$record['time']='2014-01-07 10:00:30';
$record['catagory']='Study';
$record['content']='Do something fun...';
$recordlist[]=$record;
$record=Array();
$record['time']='2014-01-07 12:00:30';
$record['catagory']='Sport';
$record['content']='Bike';
$recordlist[]=$record;
$record=Array();
$record['time']='2014-12-15 12:00:30';
$record['catagory']='Sport';
$record['content']='Bike';
$recordlist[]=$record;
$record=Array();
$record['time']='2014-12-12 12:01:30';
$record['catagory']='Sport';
$record['content']='Bike';
$recordlist[]=$record;
?>
<?php
//output
//how to output just as http://jsfiddle.net/euj89/
// Refactor Array
foreach($recordlist as $record){
$date = explode(" ",$record['time']);
$hour = $date[1];
$date = $date[0];
$week = date("W",strtotime($date));
$month = date("F",strtotime($date));
$year = date("Y",strtotime($date));
$newRecordList[$year][$month][$week][$date][$hour]['time'] = $record['time'];
$newRecordList[$year][$month][$week][$date][$hour]['category'] = $record['catagory'];
$newRecordList[$year][$month][$week][$date][$hour]['content'] = $record['content'];
}
//OUTPUT
?><div class="tree"><ul><?
foreach ($newRecordList as $year => $recordByYear) {
foreach ($recordByYear as $month => $recordByMonth) {
foreach ($recordByMonth as $week => $recordByWeek) {
?><li><span><?=$year?>, Week <?=$week?> , date</span><ul><?
foreach ($recordByWeek as $day => $recordByDay) {
?><li><span><?=date("l",strtotime($day))?>, <?=$month?> <?=$day?> </span><ul><?
foreach ($recordByDay as $hour => $recordByHour) {
?><li><div class="record">
<span><?=$hour?></span><br>
<span><?=$recordByHour['category']?></span><br>
<span><?=$recordByHour['content']?></span><br>
</div></li><?
}
?></ul></li><?
}
?></ul></li><?
}
}
}
?></ul></div><?
Output should be like this:
function getRecords($result){
$arr = new array();
while ($row = myqsli_fetch_array($result)) {
$arr[] = $row;
}
return $arr;
}
$week;
$date;
$records = getReceords($queryresultfromyourdb);
foreach($records as $rec)
{
if ($week != $rec["Week"])
{
echo $rec["Week"] . '<br>';
$week = $rec["Week"];
}
if ($date != $rec["Date"])
{
echo $rec["Date"] . '<br>';
$date = $rec["Date"];
}
echo $rec["record"] . '<br>';
}
I am trying to setup paging on my site using Ajax, I've inherited a script and put it into practice at the following link - http://www.testing.arrivaldesign.co.uk/properties.
I've got it working to an extent, but it's set to show the first 9 records and then carry on from there, but it's only showing the first 9 on the first page, but then when you click to the next page it just repeats 4 of the existing records.
As far as I can see it's to do with limit on my query, but I don't know how to get it working?
This is the code for the ajax side of things.
<?php
include('Connections/connection.php');
include 'functions.php';
// Pagination params
$basePath = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'];
$qString = $_REQUEST['qString'];
$items = $_REQUEST['items'];
$loadPage = $_REQUEST['p'];
$current = $_REQUEST['current'];
$limit = $loadPage*$items;
$min = ($max-$items)+1;
mysql_select_db($database, $conn);
$query_RSproperty = "SELECT properties.*, type.* FROM (properties LEFT JOIN type ON properties.propType=type.typeID) WHERE offline = 'N' ORDER BY propID ASC LIMIT 0, $limit";
$RSproperty = mysql_query($query_RSproperty, $conn) or die(mysql_error());
$row_RSproperty = mysql_fetch_assoc($RSproperty);
$totalRows_RSproperty = mysql_num_rows($RSproperty);
$maxItems = $totalRows_RSproperty;
// New pagination
$pagination = paginator($basePath . $qString, $loadPage, $maxItems, $items);
// Direction is important for the script to determine which way to animate, left or right.
$direction = 'left';
if ($current < $loadPage) {
$direction = 'right';
}
$paginatedStyle = 'style="left:'.($direction == 'left' ? '0' : '-960px').';"';
// The paginated content HTML slide
$page = '<div class="paginated" id="" '.$paginatedStyle.'>';
ob_start();
do {
?>
<div class="grid-1third res-block">
<div class="prop-brief-desc">
<div class="grid-140"><img src="/prop-images/thumbs/<?php echo $row_RSproperty['propImage1']; ?>" width="140" height="105" alt=""></div>
<div class="grid-140 fr">
<h2><?php echo $row_RSproperty['propBeds']; ?> Bed <?php echo $row_RSproperty['typeName']; ?></h2>
<?php
$fulladdress = $row_RSproperty['propAddress1'] . '<br />' . $row_RSproperty['propCity'] . ', ' . $row_RSproperty['propCounty'] . '<br />' . $row_RSproperty['propPostcode'];
?>
<p><?php echo $fulladdress; ?></p>
</div>
</div>
<div class="prop-brief-options<?php echo $no == 2 || $no == 3 ? " hide" : ""; ?>" id="newopt<?php echo $no; ?>">
<div class="grid-140"> Details Arrange Viewing Place Bid Buy it Now </div>
<div class="grid-140 fr">
<dl>
<dt>Auction Ending:</dt>
<dd><?php
if(!function_exists('countdown')) {
function countdown($year, $month, $day, $hour, $minute) {
$the_countdown_date = mktime($hour, $minute, 0, $month, $day, $year, -1);
$current = time();
$difference = $the_countdown_date - $current;
if ($difference < 0) $difference = 0;
$days = floor($difference/60/60/24);
$hours = floor(($difference - $days*60*60*24)/60/60);
$minutes = floor(($difference - $days*60*60*24 - $hours*60*60)/60);
echo $days."d ".$hours."h ".$minutes."m";
}
}
$theyear = date("Y",strtotime($row_RSproperty['propEndDate']));
$themonth = date("n",strtotime($row_RSproperty['propEndDate']));
$theday = date("d",strtotime($row_RSproperty['propEndDate']));
$thehour = date("H",strtotime($row_RSproperty['propEndDate']));
$theminute = date("i",strtotime($row_RSproperty['propEndDate']));
countdown($theyear,$themonth,$theday,$thehour,$theminute);
?></dd>
<?php if ($row_RSproperty['propCurrBid'] > 0) { ?>
<dt>Current bid:</dt>
<dd>£<?php echo number_format($row_RSproperty['propCurrBid']); ?></dd>
<?php } else { ?>
<dt>Starting Price:</dt>
<dd>£<?php echo number_format($row_RSproperty['propStartPrice']); ?></dd>
<?php } ?>
<dt>Buy it now:</dt>
<dd><span class="green">£<?php echo number_format($row_RSproperty['propBinPrice']); ?></span></dd>
</dl>
</div>
</div>
</div>
<?php
} while ($row_RSproperty = mysql_fetch_array($RSproperty));
/*while ($min <= $max) {
$page .= '<li>'.$min.'</li>';
$min++;
}*/
$page .= ob_get_contents();
ob_end_clean();
$page .= '</div>';
// return the JSON
echo json_encode(array( 'pagination' => $pagination, 'page' => $page, 'current' => $loadPage ));
exit;
?>
Many thanks
Chris
That's because you have hard coded LIMIT as 0 in your query
$query_RSproperty = "SELECT properties.*, type.* FROM (properties LEFT JOIN type ON properties.propType=type.typeID) WHERE offline = 'N' ORDER BY propID ASC LIMIT 0, $limit";
So when you move on second page, the query must be getting generated like follow
$query_RSproperty = "SELECT properties.*, type.* FROM (properties LEFT JOIN type ON properties.propType=type.typeID) WHERE offline = 'N' ORDER BY propID ASC LIMIT 0, 4";
hence you re getting first 4 records. If you want to retrieve the next set of records on subsequent pages, then you have to make 0 in LIMIT 0, $limit dynamic like:
$query_RSproperty = "SELECT properties.*, type.* FROM (properties LEFT JOIN type ON properties.propType=type.typeID) WHERE offline = 'N' ORDER BY propID ASC LIMIT $offset, $limit";
You have to calculate $offset depending on how much results you are displaying per page. On first page, offset will always be 0. If you are displaying 10 records per page, then on second page, offset will be 11, on third offset will be 21 and so on.
I keep getting this warning:
Warning: Invalid argument supplied for foreach() in
here is my full code which performe function list output from mysql and paging it 10 output per page , the error appear in last page
<?php
require_once('dbconnect.php');
$yesterday = date("Y-m-d", strtotime("yesterday"));
$page=intval($_POST['p']);
if($page=='')
{
$page=1;
}
$dbadd=($page-1)*10;
$query = "SELECT * FROM ranking";
$totalposts=mysql_num_rows(mysql_query($query));
$totalpages=ceil($totalposts/10);
$query = "SELECT r.ranking,r.screenname,r.name,r.followers,r.tweets,r.location,r.`join date`,r.avatar, h.date, r.followers-h.followers followers_diff, r.tweets-h.tweets tweets_diff FROM ranking r, ranking_hist h WHERE r.screenname=h.screenname and h.date='$yesterday' AND r.ranking>$dbadd AND r.ranking<($dbadd+11) ORDER BY ranking ASC LIMIT 10 ";
$result = mysql_query($query);
if( !$result ) {
die("Error: " . mysql_error() );
}
while($row = mysql_fetch_assoc($result) ) {
$tweep = $row['screenname'];
$tweeps[$tweep] = $row;
}
$query = "SELECT r.ranking,r.screenname,r.name,r.followers,r.tweets,r.location,r.`join date`,r.avatar FROM ranking r WHERE r.screenname NOT IN ( SELECT DISTINCT screenname from ranking_hist ) AND r.ranking>$dbadd AND r.ranking<($dbadd+11) ORDER BY ranking ASC LIMIT 10";
$result = mysql_query($query);
if( !$result ) {
die("Error: " . mysql_error() );
}
while($row = mysql_fetch_assoc($result) ) {
echo "";
$tweep = $row['screenname'];
$tweeps[$tweep] = $row;
}
mysql_free_result($result);
$i = 0;
$total_amount = count($tweeps);
foreach ($tweeps as $tweep) {
$i++;
if ($total_amount == $i) {
$class = 'divrow divrowlast';
} else {
$class = 'divrow';
}
$col5 = "";
if( $tweep['followers_diff'] > 0 ) {
$col5 = "<span style='color:green; display:inline;'> +" . $tweep['followers_diff'] . "▲ </span>";
}
else if( $tweep['followers_diff'] < 0 ) {
$col5 = "<span style='color:red; display:inline;'> -" . $tweep['followers_diff'] . "▼ </span>";
}
$html_table .= '<div class="'.$class.'"><ul>' .
"<li class='row100rank'> " . $tweep['ranking'] . "</li>" .
"<li class='row100user'>
<div class='avatar'><img width='32' height='32' src='" . $tweep['avatar'] . "' alt='" . $tweep['screenname'] ."' /></div>
<div class='feature-author'><a class='text_bigger' href='http://www.twitter.com/" . $tweep['screenname'] . "/'>#".$tweep['screenname']."</a></div>
<div class='row100description'>".$tweep['name']."<br />".$tweep['location']."</div></li>" .
"<li class='pad'><div class='stat'> <span>" . $tweep['followers'] . " $col5</span> followers</div></li>" .
"<li class='pad rowTwitte'><div class='stat'> <span>" . $tweep['tweets'] . " $col6</span> tweets</div></li>" .
"<li class='pad rowJoionDate'><div class='stat'> <span>" . date ( 'd M y', strtotime($tweep['join date'])) . "</span> joindate</div></li>" .
"</ul></div>";
}
echo $html_table;
?>
<div class="dataTables_paginate paging_full_numbers" ><span class="first paginate_button" ><a class="pagelinks" href="javascript:void(0);" pageid="1" onClick="changepage(1);">First</a></span>
<span class="previous paginate_button" ><a class="pagelinks" href="javascript:void(0);" pageid="<?php echo $page>1?($page-1):1;?>" onClick="changepage(<?php echo $page>1?($page-1):1;?>);" >Previous</a></span>
<span>
<?php
switch($page){
case 1:
$it=1;
$itl=6;
break;
case 2:
$it=1;
$itl=6;
break;
case $totalpages:
$it=$totalpages-4;
$itl=$totalpages+1;
break;
case $totalpages-1:
$it=$totalpages-4;
$itl=$totalpages+1;
break;
default:
$it=$page-2;
$itl=$page+3;
}
for(;$it<$itl;$it++){
?>
<span class="<?php echo $page== $it?'paginate_active':'paginate_button'; ?>">
<a class="pagelinks" href="javascript:void(0);" pageid="<?php echo $it;?>" onClick="changepage(<?php echo $it;?>);" ><?php echo $it; ?></a></span>
<?php
}
?>
</span>
<span class="next paginate_button" ><a class="pagelinks" href="javascript:void(0);" pageid="<?php echo $page<$totalpages?($page+1):$page;?>" onClick="changepage(<?php echo $page<$totalpages?($page+1):$page;?>);">Next</a>
</span>
<span class="last paginate_button" >
<a class="pagelinks" href="javascript:void(0);" pageid="<?php echo $totalpages;?>" onClick="changepage(<?php echo $totalpages;?>);">Last</a>
</span></div>
<div class="dataTables_info">
Showing <?php echo ($page-1)*10+1;?> to <?php echo ($page-1)*10+10;?> of <?php echo $totalposts;?>
</div>
Try the code blow. Your $tweeps might on some occasions not be an array or object, check if the array is not empty and is_array($tweeps).
$i = 0;
$total_amount = count($tweeps);
if(is_array($total_amount) && !empty($tweeps))
{
foreach ($tweeps as $tweep)
{
$i++;
if ($total_amount == $i)
{
$class = 'divrow divrowlast';
}
else
{
$class = 'divrow';
}
}
}
Your problem is likely to be that the query isn't retuning any data.
You are populating new entries into the $tweeps array inside the loop, but if there's no data, it won't ever go into that loop.
You aren't initialising the $tweeps variable anywhere else, so if it doesn't go into the loop, $tweeps won't be an array, it'll be undefined. This will then give you an error if you try to use it in a foreach().
You need to add a line to initialise the variable before you start populating it:
$tweeps = array();
This would go somewhere above the loop where you first start populating $tweeps.
Hope that helps.
I have code like this:
<ul>
<?php foreach($persons as $key) : ?>
<?php if($this->session->userdata('id_user') == $key['id_person'] ) : ?>
<li><em><?php echo $key['name'] . " " . $key['surname'] ?></em></li>
<?php else : ?>
<li><?php echo $key['name'] . " " . $key['surname'] ?></li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
How can I place result from the if condition at the first place? Can I do here or I need to write SQL query?
EDIT:
This is output:
<ul>
<li>Marko Džunić</li>
<li><em>Saša Miljković</em></li>
<li>mirko mirkovic</li>
</ul>
I want to get this:
<ul>
<li><em>Saša Miljković</em></li>
<li>Marko Džunić</li>
<li>mirko mirkovic</li>
</ul>
<ul>
<?php
$first = '';
$content = '';
$id_user = $this->session->userdata('id_user');
?>
<?php foreach($persons as $key) : ?>
<?php
$id_person = $key['id_person'];
$name = $key['name'];
$surname = $key['surname'];
if ($id_user == $id_person)
{
$first = '<li><em>' . $name . ' ' . $surname . '</em></li>';
}
else
{
$content .= '<li>' . $name . ' ' . $surname . '</li>';
}
?>
<?php endforeach; ?>
<?php echo $first, $content; ?>
</ul>
Go through your array two times.
The first time you only echo when the person is the selected person and then delete this person from the array by using unset().
Go through your array a second time like you did before.
The selected item is now the first item in the list.
Best way is to get the result sorted from the Mysql itself. In MySQL you can place particular rows at the top.