PHP MySQL carousel slider query displays no data [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have an Owl slider in my current project, in which up to three images from the database are to be displayed. I can also call up all the data I need without any problems, but if I want to display 2 or 3 pictures in the slider, only the first picture is displayed and the other pictures wont displayed without an error.
What is the problem?
<div class="container" style="margin-top: 10px;">
<div class="owl-carousel owl-theme">
<?php
$operator_one_id = escape($_GET['operator_one']);
$query = "SELECT * FROM strat WHERE player_one_operator_id = $operator_one_id";
$select_operator_one_strat = mysqli_query($connection, $query);
$row = mysqli_fetch_assoc($select_operator_one_strat);
$player_one_operator_id = $row['player_one_operator_id'];
$player_one_image_top = $row['player_one_image_top'];
$player_one_image_ground = $row['player_one_image_ground'];
$player_one_image_base = $row['player_one_image_base'];
echo "<div class='item'><img src='./assets/img/maps/strats/$player_one_image_top' alt='Operator One Top Strat'></div>";
echo "<div class='item'><img src='./assets/img/maps/strats/$player_one_image_ground' alt='Operator One Ground Strat'></div>";
echo "<div class='item'><img src='./assets/img/maps/strats/$player_one_image_base' alt='Operator Base Strat'></div>";
?>
</div>
</div>
![
Left picture 1, right picture 2]1

This is an example of how html is rendered. With the following options you can change almost every class the way you want.
<div class="owl-carousel owl-theme owl-loaded">
<div class="owl-stage-outer">
<div class="owl-stage">
<div class="owl-item">...</div>
<div class="owl-item">...</div>
<div class="owl-item">...</div>
</div>
</div>
</div>
While loop will display all images in database until you not limit query, so, you dont need to specify each image.
Your php codes in while loop should look like this :
<div class="owl-carousel owl-theme owl-loaded">
<div class="owl-stage-outer">
<div class="owl-stage">
<?php while($row = mysqli_fetch_assoc($select_operator_one_strat)){ ?>
<div class="owl-item">
<img src="path-to-image/<?php echo $row['image-name']; ?>" />
</div>
<?php }?>
</div>
</div>
</div>
Documentation : https://owlcarousel2.github.io/OwlCarousel2/docs/api-classes.html
But you are trying to display specific images so your codes should look like this without while loop :
<div class="owl-carousel owl-theme owl-loaded">
<div class="owl-stage-outer">
<div class="owl-stage">
<?php $row = mysqli_fetch_assoc($select_operator_one_strat);?>
<div class="owl-item">
<img src="path-to-image/<?php echo $row['image-1']; ?>" />
</div>
<div class="owl-item">
<img src="path-to-image/<?php echo $row['image-2']; ?>" />
</div>
<div class="owl-item">
<img src="path-to-image/<?php echo $row['image-3']; ?>" />
</div>
<div class="owl-item">
<img src="path-to-image/<?php echo $row['image-4']; ?>" />
</div>
</div>
</div>
</div>
Marquee is another choice

Related

I want to generate a new page where someone can comment something [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to generate a new page where someone can comment and see the post they clicked on, I currently have my database being looped and echoed onto the screen, they are clickable i'm just not sure how to make it so in generates its own page with the post they clicked on.
else{
$postquery = "SELECT `users`.`username`,`posts`.`text`,`posts`.`date`,`posts`.`title` FROM `users` INNER JOIN `posts` ON `users`.`user_id` = `posts`.`user_id` ORDER BY `posts`.`post_id` DESC";
$post = mysqli_query($dbc,$postquery);
if(mysqli_num_rows($post) > 0) {
foreach($post as $row) {
?>
<!-- Main Content -->
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div class="post-preview">
<a href="post.html">
<h2 class="post-title">
<!-- TITLE OF POST -->
<?php echo $row["title"];?>
</h2>
<h3 class="post-subtitle">
<!-- CONTENT OF POST -->
<?php echo $row['text']; ?>
</h3>
</a>
<p class="post-meta">Posted by <?php echo $row['username'];?></a><?php echo " On " . $row['date'];?></p>
</div>
<?php
}
}
}
This will output something like the following:
Title: Post
Content: Blablalala
Posted by: user On 2016-04-02
And what i want to do is make it so i can click the "Title" as a hyperlink and get directed to a different page where i see just that post and are able to comment on it. I heard of using "GET" as a method but currently i'm not sure where to start.
You can simply add and link to the other page.
<h2 class="post-title">
<!-- TITLE OF POST -->
<a href="anotherpage.php?title=<?php echo $row["title"];?>">
<?php echo $row["title"];?>
</a>
</h2>
But the better option is to use the post_id for linking to the post detail:
<h2 class="post-title">
<!-- TITLE OF POST -->
<a href="anotherpage.php?id=<?php echo $row["post_id"];?>">
<?php echo $row["title"];?>
</a>
</h2>
And from anotherpage.php you get it by id and make the query:
$id = $_GET['id'];
$singlepost = "SELECT * FROM `users` WHERE post_id='$id'";
$result = mysqli_query($dbc, $singlepost);
$row = mysqli_fetch_assoc($result);
Then your can normally output like this:
echo $row['title'];
echo $row['text']
echo $row['username'];
And put your comment like below:
<form method="post">
<label>Have your say</label>
<textarea rows="2" cols="5" name="comment"></textarea>
<input type="hidden" name="postid" value="<?php echo $row['post_id']">
<input type="submit" name="submit" value="comment">
</form>
You can check whether there is comment and update the same:
if(isset($_POST['submit'])){
$comment = isset($_POST['comment'])? $_POST['comment']:'';
$id = $_POST['id];
if(empty($comment)){
$error = "Comment field is blank";
}else{
mysqli_query($dbc, "INSERT INTO comment (comment, post_id)
VALUES ('$comment', '$id')");
}
}
Check whther there is error while posting comment.
if(!empty($error)){
echo $error;
}

How to display mysql array with limit together with PHP

I have a mysql query together with my html code looking like this.
<?php
/////////////////////////////////////////////////////////////
// RANDOM USER DISPLAYED WHICH MATCHS
/////////////////////////////////////////////////////////////
$statement = $dbConn->prepare("SELECT user_name, profile_image_url, user_age, country FROM users WHERE profile_image = '2' AND gender = ? ORDER BY RAND() LIMIT 2;");
$statement->execute(array($logged_in_user['searching_for']));
$random_match= $statement->fetch(PDO::FETCH_BOTH);
/////////////////////////////////////////////////////////////
// END OF RANDOM QUESTIONS
/////////////////////////////////////////////////////////////
?>
<div id="front_match">
<div class="front_box">
<div class="front_box_left">
<div style="position: relative;">
<img src="images/woman_1.jpg" style="max-width:100%;height:auto;">
<div class="transparent">Information about user one comes here</div>
</div>
</div>
<div class="front_box_right">
<div style="position: relative;">
<img src="images/woman_2.jpg" style="max-width:100%;height:auto;">
<div class="transparent">Information about user two comes here</div>
</div>
</div>
</div> <!-- div box finished here -->
</div> <!-- div match finished here -->
How to i insert information received from the database in
"Information about user one" and then "Information about user two"?
You can see that i'm using limit 2 so i want to display 1 results in one place and second result in second place
Cheerz
You can still use fetch_array to achieve your goal. Store it in an array, then you can call it whenever you want.
while($statement->fetch()){
$user_name_arr[] = $user_name;
$user_age_arr[] = $user_age;
/* ... REST OF CODE ... */
}
Then call them manually:
<div id="front_match">
<div class="front_box">
<div class="front_box_left">
<div style="position: relative;">
<img src="images/woman_1.jpg" style="max-width:100%;height:auto;">
<div class="transparent">
<?php
echo "Name: ".$user_name_arr[0];
echo "Age: ".$user_age_arr[0];
/* ECHO REST OF THE INFORMATION */
?>
</div>
</div>
</div>
<div class="front_box_right">
<div style="position: relative;">
<img src="images/woman_2.jpg" style="max-width:100%;height:auto;">
<div class="transparent">
<?php
echo "Name: ".$user_name_arr[1];
echo "Age: ".$user_age_arr[1];
/* ECHO REST OF THE INFORMATION */
?>
</div>
</div>
</div>
</div> <!-- div box finished here -->
</div> <!-- div match finished here -->
Just wondering:
I'm just wondering, why do you have to separate them and not use while loop. And just go with this:
<div id="front_match">
<div class="front_box">
<?php
while($statement->fetch()){
?>
<div class="front_box_left">
<div style="position: relative;">
<img src="<?php echo $profile_image_url; ?>" style="max-width:100%;height:auto;">
<div class="transparent">
<?php
echo "Name: ".$user_name;
echo "Age: ".$user_age;
/* ECHO REST OF THE INFORMATION */
?>
</div>
</div>
</div>
<?php
} /* END OF WHILE LOOP */
?>
</div> <!-- div box finished here -->
</div> <!-- div match finished here -->
You want excatly two rows? Then fatch two times:
$first_match = $statement->fetch(PDO::FETCH_BOTH);
$second_match = $statement->fetch(PDO::FETCH_BOTH);
You can use $first_match for the first table and $secon_match for the second table.

Kirby snippet shows only 10 subpages

I'm working on this (NSFW), I created 12 subpages but only 10 are showing in the list.
I'm not using any limit() or pagination() in the snippet nor in the panel config, I can't find where this limit is regulated. My guess is a numbering issue, because if in the panel I drag up the 11th subpage up, anything below will not be displayed.
Any clue?
php:
<section id="entries">
<ul>
<li>
<div class="line asger">
<div class="text">00</div>
<div class="text bold">Asger Carlsen</div>
</div>
</li>
<?php $n = 1; foreach($pages->children()->visible()->sortBy('date', 'asc') as $entries): ?>
<li>
<div class="line">
<div class="text">0<?php echo $n++; ?></div>
<div class="table"><div class="text bold"><?php echo kirbytext($entries->title()) ?></div></div>
<div class="text"><?php echo kirbytext($entries->kind()) ?></div>
</div>
<div class="description hidden">
<?php echo kirbytext($entries->description()) ?>
</div>
<div class="left-half">
<img class="images hidden" src="<?php echo $entries->images()->first()->url() ?>" alt="<?php echo html($entries->title()) ?>" />
</div>
</li>
<?php endforeach ?>
</ul>
</section>
Folder structure: https://www.dropbox.com/s/8gigspwup0kwqei/Screenshot%202014-09-03%2015.39.51.png?dl=0
Your folder-structure is defiantly correct. You only could try to rename 04-2001 to something like 04-foo2001 but i don`t think that this causes your issue.
I had some quite similar behavior once. It was caused by image-metadata txt's that had the same name like the page-content txt's. So maybe it would be helpful if you show us your complete folder-structure including the files/filenames.
Next idea: Are you sure you have no invalid markdown in your txt's?
PS: This should be a comment, but i’m at 49 reputation, so i’m not allowed to comment ;) cheers!
It was probably a combination of .txt name conflict plus a missing image from a page.

get two paths of images from database and loop them to display in slider

Im little bit stuck on a logic.scenario is i have a slider where two images are shown at a time taking 50%-50% part of screen,here is the simple html of it,
<div class="zeus-slider zeus-default" >
<div class="zeus-block">
<div class="zeus-slide s-50"> <img src="slider/slider1.jpg" data-effect="slideRight" alt="" /> </div>
<div class="zeus-slide s-50"> <img src="slider/slider2.jpg" data-effect="slideRight" alt="" /> </div>
</div>
</div>
here every block contains two images i have shown only one.now i have trying to make it dynamic, but i didnt get any idea how it will work, so i created database with two tables, each for individual image in a single block.Both table have fields like simg_id(A_I),img_name,simg_path.
here its my php on slider page.
<div class="zeus-block">
<?php
$slider_slt=getResultSet('select * from slider_img_master1 ORDER BY simg_id');
if(mysql_num_rows($slider_slt))
{
while($slider_data=mysql_fetch_assoc($slider_slt))
{
?>
<div class="zeus-slide s-50"> <img src="slider/first/<?php echo $slider_data['simg_path']?>" data-effect="slideRight" alt="" /> </div>
<?php }
} ?>
<?php
$slider_slt2=getResultSet('select * from slider_img_master2 ORDER BY simg_id');
if(mysql_num_rows($slider_slt2))
{
while($slider_data2=mysql_fetch_assoc($slider_slt2))
{
?>
<div class="zeus-slide s-50"> <img src="slider/second/<?php echo $slider_data2['simg_path']?>" data-effect="slideRight" alt="" /> </div>
<?php }
} ?>
</div>
now the problem is when i try to fetch path of image in slider, images are not changing one by one on both half of screen.instead it showing like both images from from both table top, another two images from both tables below 1st both, and so on , so full page is covered with images.
I know this idea of creating two tables for getting two images at once is silly,but i could not think any better.if any one can suggest any better way, it would be so helpful.
Update:getResultSet is function for mysql_query.
if anybody interested i found an answer for above question.
<div id="slide1" >
<div class="zeus-slider zeus-default" >
<?php
$slider_str="select *from slider_img_master1 where simg_status='Active'";
$i=1;
$result=mysql_query($slider_str);
if(mysql_num_rows($result)>0)
{
echo '<div class="zeus-block">';
while($row=mysql_fetch_assoc($result))
{
if($i%2==1 && $i!=1)
{
echo '<div class="zeus-block">';
}
?>
<div class="zeus-slide s-50"> <img src="slider/<?php echo $row['simg_path'];?>" data-effect="slideRight" alt="" /> </div>
<?php
if($i%2==0)
{
echo '</div>';
}
$i++;
}
} ?>
</div>
<div class="clear"> </div>
<div class="next-block"> </div>
<div class="prev-block"> </div>
</div>

Php to auto populate grids

I have the following html code:
<div class="media row-fluid">
<div class="span3">
<div class="widget">
<div class="well">
<div class="view">
<img src="img/demo/media/1.png" alt="" />
</div>
<div class="item-info">
Title 1
<p>Info.</p>
<p class="item-buttons">
<i class="icon-pencil"></i>
<i class="icon-trash"></i>
</p>
</div>
</div>
</div>
<div class="widget">
<div class="well">
<div class="view">
<img src="img/demo/media/2.png" alt="" />
</div>
<div class="item-info">
This is another title
<p>Some info and details go here.</p>
<p class="item-buttons">
<i class="icon-pencil"></i>
<i class="icon-trash"></i>
</p>
</div>
</div>
</div>
</div>
Which basically alternates between a span class with the widget class, and then the widget class without the span3 class.
What I wanted to know was if there was a way to have php "echo" or populate the details for and details under the "item-info" class. Would I need to use a foreach statement to get this done? I would be storing the information in a mysql database, and while I can get it to fill in the info one by one (repeatedly entering the and echoing out each image and item title) it's not practical when the content needed to be displayed is over 15 different items. I'm not well versed in foreach statements so I could definitely use some help on it.
If someone could help me perhaps structure a php script so that it can automatically output the html based on the number individual items in the database, that'd be greatly appreciated!
I'm wondering if the html + php (not including the foreach) would look like this:
<div class="span3">
<div class="widget">
<div class="well">
<div class="view">
<img src="img/<? $file ?>" alt="" />
</div>
<div class="item-info">
<?$title?>
<p>Info.</p>
<p class="item-buttons">
<i class="icon-pencil"></i>
<i class="icon-trash"></i>
</p>
</div>
</div>
</div>
EDIT:
I wanted to add some more information. The items populated would be based on a type of subscription - which will be managed by a group id.
I was initially going to use <? (if $_SESSION['group_id']==1)>
echo <div class="item-info">
$title
<p>$info</p>
</div>
so that only the subscribed items would populate. But, I would need it to iterate through all the items for group1 table and list it. Currently I know that I can do
<? (if $_SESSION['group_id']==1)
while ($row=mysql_fetch_assoc($sqlItem))
{
$itemInfo = $row['info'];
$image = $row['image'];
$title = $row['title'];
$url = $row['url'];
};
>
$sqlItem for now can only be assigned one thing (manually - as in: $sqlItem = '123'), unless I iterate through which is what I'm trying to figure out.
Just read that 'mysql_fetch_assoc' is being depreciated with 5.5, here is the new way and looks better, easier I think.. Hope this helps, was updated today.
I hope this helps http://php.net/manual/en/mysqli-stmt.fetch.php
replace the printf with echo '//then your html stuff
This will iterate through the rows in your database until their are no more matching records.
shouldn't a while be enough? It depends on the structure of your database and website (we didn't need so much HTML I think. Some more PHP maybe). Hope this helps.

Categories