Can someone help me with this, if you go to: https://developers.facebook.com/tools/explorer and use Graph API, GET Method on Connections->Home - You can grab your news feed.
In that newsfeed, the array shows some information based on each individual feed item.
One thing on there is likes which has a sub value of count which counts the number of likes.
Problem is, when I change it to use my applications and access token, the information is still there, expect the count part.
This is really confusing, I have read_stream as a scope.
My code the fetch the likes is:
if(isset($news['likes']['count'])) $likes_count = $news['likes']['count'];
else $likes_count = 0;
Which is part of my foreach loop.
For good measure, here is the function:
function newsitem($profile_pic,$from,$to,$message,$picture,$name,$link,$caption,$description,$icon,$time,$comments,$likes)
{
if($to) $to_section = '<div class="to" >to</div><div class="news-friend-name"><strong><a>' . $to . '</a></strong></div><div class="clear"></div>';
else $to_section = '';
if($message) $message_section = '<div class="message">' . $message . '</div>';
else $message_section = '';
if($picture) $picture_section = '<div class="external-image"><img src="' . $picture . '"/></div><div class="news-external">';
else $picture_section = '<div class="news-external" style="width: 410px;">';
if(!$link) $link='#';
if($name) $name_section = '<div class="news-title"><h3>' . $name . '</h3></div>';
else $name_section = '';
if($caption) $caption_section = '<div class="news-caption"><i>' . $caption . '</i></div>';
else $caption_section = '';
if($description) $description_section = '<div class="news-desc">' . $description . '</div>';
else $description_section = '';
if($icon) $icon_section = '<div class="news-icon" ><img src="' . $icon . '" /></div>';
else $icon_section = '';
$time_converted = time_elapsed($time);
$news = '<div class="news">
<div class="news-friend-thumb"><img src="' . $profile_pic . '"/></div>
<div class="news-content">
<div class="news-friend-name"><strong><a>'. $from . '</a></strong></div>'.$to_section.
'<div class="clear"></div>' . $message_section . $picture_section . $name_section . $caption_section . $description_section .
'</div>
<div class="clear"></div>
<div class="comment-like">' . $icon_section . $time_converted . ' ago • ' . $comments . ' comments • ' . $likes . ' likes</div>
</div>
</div>';
return $news;
}`
I'd appreciate the help, thanks!
Related
I am currently trying to create a class schedule which I pull from my Sql Server database with PHP and I am trying to get the layout output as well as the data as I am grouping the resources.
These groupings are nested such as:
-DAY
--TIME
---CLASS
----STUDENTS
And should output like this:
However, I am getting this:
My current output is working, however, it is only on the first loop, then everything goes haywire. I am assuming there is an erroneous </div> tag somewhere in my code yet I cannot for the life of me find it.
My php code is a function that is delcare as such:
<div class="mainScheduleWrapper">
<?php daySchedule(); ?>
</div>
My php code is as such:
function daySchedule() {
global $conn;
$dayScheduleQuery = 'SET DATEFIRST 1
SELECT [DAY].[DAY] AS [DAY], CLASS.CLASSTIME AS CLASSTIME, CLASSLEVEL.CLASSLEVEL AS CLASSLEVEL, CLASS.MAXSTUDENT AS MAXSTUDENT, INSTRUCTOR.FIRSTNAME AS INSTRUCTOR, STUDENT.FIRSTNAME AS STUDENTFIRST, STUDENT.SURNAME AS STUDENTLAST, STUDENT.DOB AS STUDENTDOB
FROM STUDENT JOIN BOOKING ON STUDENT.ID = BOOKING.STUDENTID JOIN CLASS ON CLASS.ID = BOOKING.CLASSID JOIN CLASSLEVEL ON CLASS.CLASSLEVELID = CLASSLEVEL.ID JOIN [DAY] ON CLASS.CLASSDAY = [DAY].ID JOIN INSTRUCTOR ON CLASS.INSTRUCTORID = INSTRUCTOR.ID
WHERE [DAY].ID = (DATEPART(dw, GETUTCDATE() AT TIME ZONE \'AUS Eastern Standard Time\'))
ORDER BY CLASS.CLASSTIME ASC, INSTRUCTOR.FIRSTNAME ASC, CLASSLEVEL.CLASSLEVEL ASC';
// COUNTERS
$t = 0;
$i = 0;
//VARIABLES FOR DAY SCHEDULE
$classDay = NULL;
$classTime = NULL;
$classInstructor = NULL;
$closeClass = false;
$closeAll = false;
$queryConnector = $conn->query($dayScheduleQuery);
foreach ($queryConnector as $schedule) {
// CLASS DAY HEADER
if ($classDay != $schedule['DAY']) {
echo '<div class="grid-1">';
echo '<h1>' . $schedule['DAY'] . '</h1>';
echo '</div><!-- Day closed! -->';
$classDay = $schedule['DAY'];
}
// CLASS TIME HEADER
if ($classTime != $schedule['CLASSTIME']) {
if($classTime != $schedule['CLASSTIME'] && $t > 0) {
$closeAll = true;
goto closeAll;
}
echo '<div class="grid-12-noGutter scheduleContainer">'; //NON-CLOSED
echo '<h1>' . 'T = ' . $t . '</h1>';
echo '<div class="grid-middle-center col scheduleTimeTab">';
// FIX 3 DIGIT MILITARY TIME
if (strlen($schedule['CLASSTIME']) < 4) {
$classScheduleTime = '0' . $schedule['CLASSTIME'];
} else {
$classScheduleTime = $schedule['CLASSTIME'];
}
echo '<p>' . date('g:i A', strtotime($classScheduleTime)) . '</p>';
echo '</div>'; //CLOSE TIME TAB
echo '<div class="innerSchedule">'; // NON-CLOSED
$classTime = $schedule['CLASSTIME'];
$t += 100;
}
// INSTRUCTOR HEADER
if ($classInstructor != $schedule['INSTRUCTOR']) {
if ($classInstructor != $schedule['INSTRUCTOR'] && $i > 0) {
$closeClass = true;
goto closeClassWrapper;
}
echo '<div class="classWrapper">';
echo '<h1>' . 'I =' . $i . 'T = ' . $t . '</h1>';
echo '<div class="grid-3-middle classHeader">';
echo '<div class="col classHeaderCell' . classLevelColour($schedule['CLASSLEVEL']) . '">' . $schedule['CLASSLEVEL'] . '</div>';
echo '<div class="col classHeaderCell">' . $schedule['INSTRUCTOR'] . '</div>';
echo '<div class="col classHeaderCell">Max' . ' ' . $schedule['MAXSTUDENT'] . '</div>';
echo '</div>';
echo '<div class="grid-4-middle" id="studentHeaders">';
echo '<div class="col"><h6>Student Name</h6></div>';
echo '<div class="col"><h6>Student Birthday</h6></div>';
echo '<div class="col"><h6>Class Level</h6></div>';
echo '<div class="col"><h6>Attendance</h6></div>';
echo '</div>';
$classInstructor = $schedule['INSTRUCTOR'];
$i += 100;
}
echo '<div class="grid-4 studentRow">';
echo '<div class="col">';
echo '<span class="studentCell">' . $schedule['STUDENTFIRST'] . ' ' . $schedule['STUDENTLAST'] . '</span>';
echo '</div>';
echo '<div class="col">';
echo '<span class="studentCell">' . $schedule['STUDENTDOB'] . '</span>';
echo '</div>';
echo '<div class="col">';
echo '<span class="studentCell">' . $schedule['CLASSLEVEL'] . '</span>';
echo '</div>';
echo '<div class="col">';
echo '<span class="studentCell">--</span>';
echo '</div>';
echo '</div>';
// GOTO TAGS
closeClassWrapper: {
if ($closeClass === true) {
echo '</div>';
$closeClass = false;
$i = 0;
}
}
closeAll: {
if ($closeAll === true) {
echo '</div>';
echo '</div>';
echo '</div>';
$closeAll = false;
$t = 0;
$i = 0;
}
}
}
}
Any help would be greatly appreciated - even if it's to tell me I'm going about it the completely wrong way.
Kindest Regards
Michael Z
I wouldn't say you're going about it the completely wrong way, but a few red flags jumped out at me in your code.
The use of goto jumping is bad practice. It butchers your program flow and forces you to segregate tasks that shouldn't be kept apart. You marked the sections of code "// NON CLOSED" when there was a </div> missing, is there any purpose for that? How do you know the goto sections are reliable?
When you echo something like <div class="col">, without escaping the double-quotes (as in \" for every " character), it can be problematic. Your code can get mangled or misinterpreted, both on the PHP end or on the HTML end.
Like others have said, the use of PHP may be overkill here. Besides just sending the JSON, the rest could be handled with JavaScript.
I'm programming a map of theatre seats.
With this code I try to show selected seats on a previous page, but I can't show all of the seats in a color and in another color the selected ones.
It shows all of the seats and only one selected.
Then all of the seats again, and another selected.
And so on...
Any suggestions?
Thank you very much and here's the piece of code:
foreach ($AsientosSeleccionadosI as $claveAI=>$valorAI) {
$resultButacas = mysql_query("SELECT U.Id AS IdUbicacion, U.IdModoTeatro, U.Numero, U.Fila, U.IdSector, U.CordX, U.CordY,
P.IdEspectaculo, P.IdFuncion, P.IdSector, P.Precio
FROM TeatroAsiento U, PrecioEspectaculoSector P
WHERE U.IdSector = '$Sector'
AND P.IdSector = '$Sector'
AND P.IdFuncion = '$fn'
AND P.IdEspectaculo = '$id'
");
while($rowButacas=mysql_fetch_array($resultButacas)){
$fila = $rowButacas["Fila"];
$asiento = $rowButacas["Numero"];
$IdUbicacion = $rowButacas["IdUbicacion"];
$precio = $rowButacas["Precio"];
echo '<div id="Casilla"><label for="asiento'.$fila.''.$asiento.'">';
if($IdUbicacion == $valorAI){
echo '<div id="ubicacion" style="background-image: url(../css/images/asientosReservado.png);"><input id="asiento'.$fila.''.$asiento.'" value="'.$IdUbicacion.'" name="asientoI[]" type="hidden"><input id="'.$IdUbicacion.''.$precio.'" value="'.$precio.'" type="hidden" name="precioseleccionI[]">';
}else{
echo '<div id="ubicacion" style="background-image: url(../css/images/asientosDisponible.png);">';
}
echo 'F: '.$fila.'<br>Nro: '.$asiento.'<br>'.$precio.'';
echo '</div></label></div>';
}
}
If I got your logic correctly IMHO you don't need loop-wrapper.
You just need to check if value $IdUbicacion exists in your array $AsientosSeleccionadosI :
$resultButacas = mysql_query("SELECT U.Id AS IdUbicacion, U.IdModoTeatro, U.Numero, U.Fila, U.IdSector, U.CordX, U.CordY,
P.IdEspectaculo, P.IdFuncion, P.IdSector, P.Precio
FROM TeatroAsiento U, PrecioEspectaculoSector P
WHERE U.IdSector = '$Sector'
AND P.IdSector = '$Sector'
AND P.IdFuncion = '$fn'
AND P.IdEspectaculo = '$id'
");
while ($rowButacas = mysql_fetch_array($resultButacas)) {
$fila = $rowButacas["Fila"];
$asiento = $rowButacas["Numero"];
$IdUbicacion = $rowButacas["IdUbicacion"];
$precio = $rowButacas["Precio"];
echo '<div id="Casilla"><label for="asiento' . $fila . '' . $asiento . '">';
if ( array_search($IdUbicacion,$AsientosSeleccionadosI)!= false) {
echo '<div id="ubicacion" style="background-image: url(../css/images/asientosReservado.png);">'
. '<input id="asiento' . $fila . '' . $asiento . '" value="' . $IdUbicacion . '" name="asientoI[]" type="hidden">'
. '<input id="' . $IdUbicacion . '' . $precio . '" value="' . $precio . '" type="hidden" name="precioseleccionI[]">';
} else {
echo '<div id="ubicacion" style="background-image: url(../css/images/asientosDisponible.png);">';
}
echo 'F: ' . $fila . '<br>Nro: ' . $asiento . '<br>' . $precio . '';
echo '</div></label></div>';
}
I found this code for showing last posts in phpbb forum. I wanna set charatcters limit in post_text.
<?php
// Now let's output the content
// A ted vypsat obsah
while ($row = $db->sql_fetchrow($result))
{
$url = generate_board_url() . "/viewtopic.{$phpEx}?f={$row['forum_id']}&t={$row['topic_id']}&p={$row['post_id']}#p{$row['post_id']}"; //added fedforum to url
$urlmini = generate_board_url() . "/memberlist.{$phpEx}?mode=viewprofile&u={$row['poster_id']}"; //added fedforum to url
//old line $url = generate_board_url() . "viewtopic.{$phpEx}?f={$row['forum_id']}&t={$row['topic_id']}&p={$row['post_id']}#p{$row['post_id']}";
echo '<small><a target="_blank" href="' . $url . '">' . $row['post_subject']. '</a><br>'. $row['post_text'] .'<br>od: <a target="_blank" href="' . $urlmini . '">' . ucwords($row['username']).'</a>' . ' v '.'<font style="color:#aaa;">' . date("H:i",$row['post_time']).'</font>', '<br><br></small>';
}
?>
Does anybody know how to set characters limit for $row['post_text'] ?
you can use
substr($row['post_text'],0,40);
or change 40 to any limit as you want
I have the following WordPress query:
$my_query = new WP_Query($args);
if ($my_query->have_posts()) {
echo '<div class="' . $tax_term->slug . '" style="display:none; background:url(' . $whatdoiputhere . ');">';
while ($my_query->have_posts()) : $my_query->the_post();
In the background URL, I need to include an image URL that is generated by the following code:
<?php if (function_exists('z_taxonomy_image_url')) echo z_taxonomy_image_url(); ?>
How would I include this IF function inside the background URL?
I tried this but as you can guess it didn't work:
background:url(' . if (function_exists('z_taxonomy_image_url')) echo z_taxonomy_image_url(); . ');
Would appreciate some help as to how I would do this.
<?php
if (function_exists('z_taxonomy_image_url')) $background_url = 'background:url(' . z_taxonomy_image_url() . ')';
echo '<div class="' . $tax_term->slug . '" style="display:none; ' . $background_url . '">';
?>
Ternary operator:
background:url(' . (function_exists('z_taxonomy_image_url') ? z_taxonomy_image_url() : '') . ');
I'd do something like this:
<?php
if (function_exists('z_taxonomy_image_url')) {
echo "background:url('" . z_taxonomy_image_url() . "');";
}
?>
If you wanted, you could set a default background image via an else clause, otherwise the background definition will just not exist in your CSS.
I have a WordPress site and currently the code it set to create titles based on the page title. The titles are: Interior House Painting, Exterior House Painting and Commercial Painting. I would like to override the titles to remove the word "house". This is the code currently:
<?php
// interior_painting: 18
// exterior_painting: 25
// other services: 36
$page_ids = array(18, 25, 36);
$images = array('servicesInterior.jpg', 'servicesExterior.jpg', 'servicesOther.jpg');
foreach ($page_ids as $key => $page_id) {
$page_post = get_post($page_id);
$page_custom_key = 'home_page_info';
$page_link = $page_post->post_name;
$li_class = $page_id == 36 ? 'noMargin' : '';
$title = $page_id == 18 ? 'Interior Painting' : $page_post->post_title . " ";
$title = $page_id == 36 ? 'Commercial Projects' : $page_post->post_title . " ";
$title = $page_id == 25 ? 'Exterior Painting' : $page_post->post_title . " ";
echo '<li class="' . $li_class . '"> <a href="' . $page_link . '">';
echo '<img class="alignright size-full wp-image-349" title="servicesInterior" src="/wp-content/uploads/2011/04/' . $images[$key] . '" alt="" width="200" height="95" /></a>';
echo '<h2>' . $title . '</h2>';
echo get_post_meta($page_id, $page_custom_key, true);
echo '<a class="btn-find-more" href="' . $page_post->post_name . '">FIND OUT MORE</a></li>';
}
?>
The output is this: Interior House Painting, Exterior Painting, Commercial Painting. How do I get "house" removed from "Interior House Painting"?
$title = ucwords(trim(strtolower(str_replace('house', '', $page_post->post_title))));
Though, I am a little curious as to why you would not prefer to just remove the word from the title altogether.
ADDITIONALLY: Somebody else mentioned using preg_replace. That's also entirely possible, but it would be best to do a case-insensitive search:
$title = trim(preg_replace('/house/i', '', $page_post->post_title));
Just use preg_replace('House'|| 'house','',/*Variable Page title is in*/);
You could try replacing the line:
echo '<h2>' . $title . '</h2>';
With something like this:
if (is_page('Interior House Painting')) { echo '<h2>Interior Painting</h2>'; }
if (is_page('Exterior House Painting')) { echo '<h2>Exterior Painting</h2>'; }
else { echo '<h2>' . $title. '</h2>'; }