I have problem that I store in DB column (video_id) and the value of it like that store (1,3,4,7) the number mean the id of video in the Video table which store the video title and text and all information about the video but when I wrote code to select all video the result give me one video
<div class="panel-body">
<?
$qu="SELECT video_id FROM `training_questions` WHERE id=$questions_id AND category_id=$training_id";
$query_c= mysqli_query($con, $qu);
while ($row7 = mysqli_fetch_assoc($query_c)) {
$vedoes=$row['video_id'];
$pieces = explode(",", $vedoes);
}
for($i=0;$i<=count($pieces);$i++){
$query = "SELECT * FROM `video` WHERE id IN $pieces[$i] ";
$query_che= mysqli_query($con, $query);
while ($row2 = mysqli_fetch_assoc($query_che)) { ?>
<div class="col-lg-3 col-sm-6">
<div class="thumbnail">
<div class="video-container">
<div class="thumb"> <img src="../upload/<?= $row2['img'] ?>" class="img-responsive img-rounded media-preview" alt=""> <span class="zoom-image"><i class="icon-play3"></i></span> </div>
</div>
<div class="caption">
<h6 class="no-margin">
<a href ="video_details.php?id=<?= $row2['id'] ?>" class="text-default"><?= $row2['title'] ?>
</a>
</h6>
</div>
</div>
</div>
<?
}
} ?>
</div>
How I can fix it?
Remove the
$pieces = explode(",", $vedoes);
its useless
make your for loop condition look like this
for($i=0;$i<=count($vedoes);$i++)
Hope it Helps
Related
This is my code and I wanted to display an image from DB. I followed some videos and recommendations here on Stack Overflow, but still does not work.
Other values like description, title etc works, so the problem is not in the connection with the DB.
Thank you.
<?php
$sql= "SELECT * FROM guides WHERE id='$id'";
$result = mysqli_query($link, $sql);
$num = mysqli_num_rows($result);
if ($num > 0) {
$row = mysqli_fetch_assoc($result)
?>
<h1 class="title"><?=$row['title']?></h1>
<?php echo' <img class="header" style="height:400px" src="data:image/jpeg;base64,'.base64_encode( stripslashes($row['photo']) ).'" style="width:100px;"></img>' ?>
<div class="row">
<div class="leftcolumn">
<h2><?=$row['date']?></h2>
<div class="card" >
<div class="clearfix">
<p class="text" ><?=$row['description']?></p>
</div>
</div>
</div>
</div>
<?php
}
?>
I think you should try and specify the folder containing the given image also. E.g src = “containing_folder/$row[‘photo’]” and see if that works. You can still add your functions to the $row[‘photo’], this was just an example.
mysqli_fetch_assoc($result) this returns an array and you need to loop through the array:
The modified code given below----
$sql= "SELECT * FROM guides WHERE id='$id'";
$result = mysqli_query($link, $sql);
$num = mysqli_num_rows($result);
if ($num > 0) {
while($row = mysqli_fetch_assoc($result)){
?>
<h1 class="title"><?=$row['title']?></h1>
<?php echo' <img class="header" style="height:400px" src="data:image/jpeg;base64,'.base64_encode( stripslashes($row['photo']) ).'" style="width:100px;"></img>' ?>
<div class="row">
<div class="leftcolumn">
<h2><?=$row['date']?></h2>
<div class="card" >
<div class="clearfix">
<p class="text" ><?=$row['description']?></p>
</div>
</div>
</div>
</div>
<?php
}
}
?>
I need to get all looped records to single variable. I tried this but i got final records of loop. How do i get all records. Can you please solve this. Here i added my code,
$text = '';
$sql = mysql_query("SELECT * FROM table WHERE column_name = 'column_value'");
while($row = mysql_fetch_array($sql)){
$text = '<li><div class="row">
<div class="col-md-12 post">
<div class="row">
<div class="col-md-12">
<h5>
<strong>'.$row['field2'].'</strong></h4>
</div>
</div>
<div class="row post-content">
<div class="col-md-12">
<p style="margin-bottom:0px">
';
$text.= substr($row['field3'],0,150);
$text.= '...</p>
<a class="pull-right" href="'.$row['field2'].'.php">>> Read more</a>
</div>
</div>
</div>
</div></li>';
}
you are not concating your $text variable
$text = '';
while() { ...
$text .= '<li>...'; // you missed this dot
}
echo $text;
I want to retrieve data from my database using CDbcriteria. I want to get the name and image of the last 4 Ngos from my Ngo table.
<?php
$Criteria = new CDbCriteria();
$Criteria->limit = 4;
$Criteria->order = "id DESC";
$Criteria->select = "id, ngo_name, image";
$Ngos =Ngo::model()->findAll($Criteria);
?>
<div class="row">
<h3>NGO's</h3>
<div class="col-md-3">
<div class="thumbnail">
<img src="<?php
foreach ( (array)$Ngos as $Ngo)
{
echo '$Ngo->image';
}
?>"
<div class="caption">
<h3><?php
foreach ( (array)$Ngos as $Ngo)
{
echo '$Ngo->ngo_name';
}
?></h3>
<button class="btn btn-primary center-block">View Profile</button>
</div>
</div>
</div>
just remove single quotes around the variable $Ngo->image and $Ngo->ngo_name or use double quotes instead.
I have a page with a search bar that gets images of people in alphabetical order from a database. I also have a page with Next and Previous buttons that allows the user to browse through the database of images using Next and Previous buttons. I'm trying figure out a way to make an image a link so that the user can search through images, click the image, and it takes them to the same image on the Next and Previous page.
This is my code that allows me to search and returns, lastname, firstname, and a picture:
<div class="clearfix"></div>
<?php
if (isset($_GET['LastName'])) {
$ln = $_GET['LastName'];
}
include 'connection.php';
$query = "SELECT * FROM residents WHERE LastName like '$ln%' ";
$result = mysql_query($query);
while($person = mysql_fetch_array($result)) { ?>
<div class="media col-sm-4">
<a class="pull-left" href="Browse.php">
<img class="media-object" src="upload/<?php echo $person['Picture'];?>" width="100"
height="100"/>
</a>
<div class="media-body">
<h4 class="media-heading"><?php echo $person['LastName'] . ", " .
$person['FirstName']; ?></h4>
</div>
The page I'm trying to connect to is "Browse.php" but as you browse through the images the URL changes by increasing..."Browse.php?page=1"..."Browse.php?page=2" and so on. Is there an easy way to connect an image with the corresponding Browse.php page? I've tried several things and any help would be much appreciated!
If you have id column in residents table. You can do something like this.
<div class="clearfix"></div>
<?php
if (isset($_GET['page'])) {
$page_id = $_GET['page'];
}
include 'connection.php';
$query = "SELECT * FROM residents WHERE ID = $page_id";
$result = mysql_query($query);
while($person = mysql_fetch_array($result)) { ?>
<div class="media col-sm-4">
<a class="pull-left" href="Browse.php?page=<?php echo $page_id; ?>">
<img class="media-object" src="upload/<?php echo $person['Picture'];?>" width="100" height="100"/>
</a>
<div class="media-body">
<h4 class="media-heading"><?php echo $person['LastName'] . ", " . $person['FirstName']; ?></h4>
</div>
</div>
<?php } ?>
I figured out how to get the data, how to use it in a while loop, but I am stuck on the last part: a loop in a loop.
I have the following code:
<div id="tab1" class="tab_content">
<ul class="columns">
<?php
$result = mysql_query("SELECT * FROM TabContent WHERE TabID = 1");
while($row = mysql_fetch_array($result))
{
echo '<li><img src="images/layouts/'. $row['LayoutName'] .'.png" alt="" />
<div class="info">
<h2>'. $row['LayoutName'] .'</h2>
<p>'. $row['LayoutTiles'] . 'Tiles, '. $row['LayoutLayers'] . 'Layers</p>
</div>
</li>';
}
?>
</ul>
<div class="clear"></div>
<div class="bottom">
<div class="clearfix">
<div class="lfloat"></div>
<div class="rfloat"><a class="hide" href="#" onclick="return false">Cancel</a></div>
</div>
</div>
</div>
<div id="tab2" class="tab_content">
etc etc same as above
The problem I have is with the div with id="tab1" and the next one with id="tab2" etc. I can get an array of tabs using:
<?php
$result = mysql_query("SELECT * FROM Tabs");
while($row = mysql_fetch_array($result))
{
echo 'tab'. $row['TabID'] .;
}
?>
Giving me: Tab1 Tab2 Tab3 etc. Now the hard part, how do I use these so I can make a loop using this to replace my html div ids?
Here's a couple of tutorials that might help you in your struggle:
http://www.freewebmasterhelp.com/tutorials/phpmysql
http://www.homeandlearn.co.uk/php/php.html