I did not want to have to ask here but I guess I have no choice since I be wasting my time starting at the screen finding a solution that will never come so here is my issue.
I am making a facebook like feed feature but more unique but in terms on how it will work like facebook to be the closest.
but for some reason it keeps looping in rows together (look at the image I have linked that will explain more)
For example
instead of displaying the latest to oldest updates it keeps displaying them in rows on each group.
Image: http://oi58.tinypic.com/11jmd1d.jpg
You will see there instead of looping as
Oldest,old,latest,update etc it is looping them in there own groups as a bundle instead :/
PHP:
} else if ($feed_viewing=='clan_updates') {
$select_clan_membership = $db->query("SELECT * FROM spud_groups_members WHERE member_name='$mybb_username'");
while($select_clan_membership_array = $db->fetch_array($select_clan_membership)) {
$gurl = $select_clan_membership_array['gurl'];
$select_posts_from_groups_query = $db->query("SELECT * FROM spud_groups_posts WHERE group_url='$gurl' ORDER BY post_id DESC");
while($select_posts_from_groups_array = $db->fetch_array($select_posts_from_groups_query)) {
$group_url_id = $select_posts_from_groups_array['group_url'];
$post_body = $select_posts_from_groups_array['post_body'];
$select_group_data_from_posts_query = $db->query("SELECT * FROM spud_groups WHERE gid='$group_url_id'");
$select_group_data_from_posts_array = $db->fetch_array($select_group_data_from_posts_query);
$group_name_data = $select_group_data_from_posts_array['group_name'];
#$group_name_data = false;
echo "<div class='mx'>
<p> <h2> $group_name_data </h2></p>
$post_body</div>
<br>
";
}
}
any ideas on what I am doing wrong?
Thanks!
Related
It's me again, Van.
Hi everyone,
I hope you're doing well!
I am doing a tutorial on a chat application using Codeigniter 4 with Ajax.
Everything worked fine until I applied the following code in the Model below
public function load_chat_data($sender_id,$receiver_id) {
// $where = ['sender_id' => $sender_id, 'receiver_id' => $receiver_id];
$where1 = "sender_id = $sender_id OR sender_id = $receiver_id";
$where2 = "receiver_id = $receiver_id OR receiver_id = $sender_id";
$builder = $this->db->table('chat_messages');
// $builder->where($where);
$builder->where($where1);
$builder->where($where2);
$builder->orderBy('chat_messages_id','ASC');
$results = $builder->get();
$rows = $results->getResultArray();
if($rows > 0)
{
return $rows;
}
else
{
return false;
}
}
The lines that I commented worked well before they were commented but it was not enough data I wanted to get so I tried to get both data of sender and receiver to display on the view by adding more code. However, when I tried $where1 and $where2 for the WHERE clauses, it didn't work. I think it must be the syntax error. Please correct my codes or any ideas on how the codes work with the same meaning supposed.
Thank you so much!!!
I tried as below, but it still didn't work.
$where1 = "sender_id={$sender_id} OR sender_id={$receiver_id}";
$where2 = "receiver_id={$receiver_id} OR receiver_id={$sender_id}";
Also, I tried:
$where1 = "'sender_id'=$sender_id OR 'sender_id'=$receiver_id";
$where2 = "'receiver_id'=$receiver_id OR 'receiver_id'=$sender_id";
I think you are trying to receive the messages of the conversation between two people. Can you try the following code for this?
$builder->groupStart(); // or $builder->orGroupStart();
$builder->where('sender_id', $sender_id);
$builder->where('receiver_id', $receiver_id);
$builder->groupEnd();
$builder->orGroupStart();
$builder->where('sender_id', $receiver_id);
$builder->where('receiver_id', $sender_id);
$builder->groupEnd();
Hello I am having the above error in production but all works well in development. I am using the code bellow to get the path to the main image for the property but it defaults into the else despite the if not being false plus the else does not find the paths even when dump shows that the object has been returned
//check if there are hotels in the selected destination
if($hotels->isNotEmpty()){
//Loop through the hotels
foreach($hotels as $hotel){
//get hotels main image
$banner = Photo::where(['p_id'=>$hotel->id])->where(['is_main'=>1])->first();
$altbanner = Photo::where(['p_id'=>$hotel->id])->first();
$banner_path = "";
$altText = "";
if($banner!=null){
$banner_path = $banner->path;
$altText = $banner->alt_text;
}else{
$banner_path = $altbanner->path;
$altText = $altbanner->alt_text;
}
Have you checked your database if each hotel has an image? Based on your question and explanation, there is a part of the for each that returns null for the image hence the if part fails and the else return the error. If that is the case then you may want to check and sort it by uploading the image or modifying your checks to handle cases where no image is found.
I think the way you are using the where clause isn't right
foreach($hotels as $hotel){
//get hotels main image
$banner = Photo::where('p_id',$hotel->id)->where('is_main',1)->first();
$altbanner = Photo::where('p_id',$hotel->id)->first();
// .....
if($banner){
$banner_path = $banner->path;
// ......
I'm using the following code to limit the number of words that appear on my blog pages.
function custom_excerpt_length( $length ) { return 32; } add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
I need to limit the number of words that appear on the BuddyPress Activity Stream when someone creates a blog post. Currently when someone creates a new blog post, the excerpt appears on the Activity Stream with about 50+ words. I need to limit this to around 32 words.
Does anyone know how to accomplish this?
Thx
This is what I'm using. The first part limits the text, the second part ensures the thumbnail is present. Thank you shanebp for pointing me in the right direction.
function 5_activity_content_body( $content, $activity ) {
$content_length = 42;
if ( 'new_blog_post' == $activity->type ) {
$images = extractImageFromContent($content);
$_content = (strlen($content) > $content_length) ? substr($content, 0, $content_length).'...' : $content;
if(!empty($images)) {
$_content .= implode("", $images);
}
return $_content;
}
return $content;}
add_filter( 'bp_get_activity_content_body', '5_activity_content_body', 10, 2 );
This brings the thumbnail back.
function extractImageFromContent($html) {
preg_match_all('/<img.*?src=[\'"](.*?)[\'"].*?>/i', $html, $matches);
return ($matches[0]) ? $matches[0] : array(); }
i recently tried sanity.io CMS to manage content on my personal blog. however i'm facing a little difficulty to find part in the documentation about 'auto referencing' (this just my term). i want for each my blog post to have data of next and previous post, so i can create button at the bottom to navigate to next or previous blog post. how can i achieve it? thankss
To me, this is a job for a query rather than a reference.
There is no way to "auto-reference" something the way you are describing however there are a few ways you can achieve your effect:
1. Manually link them
2. Create a custom input field that queries for your previous/next posts. More on custom input components here: https://www.sanity.io/docs/custom-input-widgets
3. Use a GROQ query to get all posts and the find the ones you need (in JS):
const posts = await Sanity.fetch(`*[_type == 'post']`);
const currentPostIndex = posts.findIndex(post => post.id === currentPost.id);
const previousPost = posts[currentPostIndex - 1];
const nextPost = posts[currentPostIndex + 1];
4. Add date queries to get the adjacent posts with GROQ (in JS):
const posts = await Sanity.fetch(`*[_type == 'post' && _id == '${currentPost.id}' ][0] {
'currentPost': {
...
},
'previousPost': *[_type == 'post' && _createdAt < ^._createdAt][0],
'nextPost': *[_type == 'post' && _createdAt > ^._createdAt] | order(_createdAt asc)[0]
}`);
const currentPostIndex = posts.findIndex(post => post.id === currentPost.id);
const previousPost = posts[currentPostIndex - 1];
const nextPost = posts[currentPostIndex + 1];
More info on GROQ https://www.sanity.io/docs/query-cheat-sheet
I have many websites that use some of the same content snippets and instead of manually updating all the different websites, I thought it would be a good idea to have the content stored in a database as to only have one copy instead of multiple. It works great except for one issue which is the images that are in the article are sometimes left aligned and other times right aligned.
My solution was to add the following code to the article's image CSS tag that is in the database and use a variable on each of the individual pages to add the custom classes to the image.
class="<?php echo $ImgClass01; ?>"
EDIT: here is more of the content from what is stored in the database field to make my question a little more understandable.
<p><img src="img/charleston.jpg" class="<?php echo $ImgClass01; ?>">Is it the delightful year-round climate? The almost-European feel of its downtown city streets? The overwhelming...</p>
However, the webpage is only showing the text when viewing the source code and not using the variable. Almost anything is possible, but I'm not sure how to make this work.
Here is the code on the page...
// value for the class within the article to be printed on the page
$ImgClass01 = 'img-responsive img-rounded pull-right';
//Start a while loop to process all the rows
while ($row = mysql_fetch_assoc ($result_set))
{
$article = $row['article'];
echo $article;
} //END WHILE
EDIT: Just in case the entire page will be helpful, here is it.
<?php
$PageTitle = "Charleston, South Carolina | Local Towns";
$PageDescription = "Charleston is rated the first most popular vacation destination in the United States, and it surely must rank in...";
// 1. Create a database connection
$link = mysql_connect ("localhost", "root", "");
if (!$link) die("Could not connect: " . mysql_error());
// 2. Select a database to use
if (!mysql_select_db ("articleBank"))
die("Problem with the database: " . mysql_error());
// 3. Set up query for items to display
$query = "SELECT article FROM `articles` WHERE ID = 1";
// 4. Execute the query
$result_set = mysql_query ($query);
include ("theme/header.php");
// value for the class within the article to be printed on the page
$ImgClass01 = 'img-responsive img-rounded pull-right';
//Start a while loop to process all the rows
while ($row = mysql_fetch_assoc ($result_set))
{
$article = $row['article'];
echo $article;
} //END WHILE
// 5. Close Connection
mysql_close();
include ("theme/footer.php");
?>
while ($row = mysql_fetch_assoc ($other_result_set))
{
$ImgClass01 = $row['ImgClass01'];
}
not sure what you wanted, but you could use left, right in some row like place..