If I add this Bootstrap Tab into html code, it works perfectly:
<ul class="nav nav-tabs">
<li class="active">Hello</li>
<li>Empty</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="hello">
<h3>Hello my Friend!</h3>
<p>hello</p>
</div><!-- #end #hello -->
<div class="tab-pane" id="empty">
<h3>Just gonna be empty...</h3>
<p>Yup. Nothin' here.</p>
</div><!-- #end #empty -->
</div>
But in those tap I need to connect to my database so show some information, my code is:
<ul class="nav nav-tabs">
<li class="active">Facilities</li>
<li>Course Fee</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="facilities">
<h3>Just gonna be empty...</h3>
<p>Yup. Nothin' here.</p>
<?php echo "<table>";
$userpic = '<img src="images/user.png"/>';
while ($roww = mysqli_fetch_array($usercomment)){
$cm_fac = $roww['facilities'];
$name = $roww['UserName'];
$time = $roww['CmtDate'];
echo '<tr>';
echo '<td>';
//i put some info here as table
echo '</td>';
echo '</tr>';
}
echo "</table>";
?>
</div><!-- end of facilities-->
<div class="tab-pane" id="fee">
<h3>Hello my Friend!</h3>
<p>hello</p>
<?php echo "<table>";
$userpic = '<img src="images/user.png"/>';
while ($roww = mysqli_fetch_array($usercomment)){
$cm_fee = $roww['fee'];
$name = $roww['UserName'];
$time = $roww['CmtDate'];
echo '<tr>';
echo '<td>';
//some info here too
echo '</td>';
echo '</tr>';
}
echo "</table>";
?>
</div><!-- end of fee-->
</div> <!--end of tab-content-->
but it doesn't work. Can anyone show me my problem?
Thank you for your time.
You maybe can try this:
<div class="tab-pane" id="fee">
<h3>Hello my Friend!</h3>
<p>hello</p>
<!-- open the 'while' -->
<?php
while ($roww = mysqli_fetch_array($usercomment)){
$cm_fac = $roww['facilities'];
$name = $roww['UserName'];
$time = $roww['CmtDate'];
?>
<!-- your table -->
<table>
<tr>
<td>
<?php echo "your data here"; ?>
</td>
</tr>
</table>
<?php } ?> <!-- close the 'while' here -->
</div>
Check results of your query.
You can use $roww = mysqli_fetch_array($usercomment, MYSQLI_ASSOC); to fetch data.
Related
I've got this PHP code:
<div class="connect_wrap <?php echo $this->class; ?> block" <?php echo $this->cssID; ?>>
<?php if(!$this->empty): ?>
<?php foreach($this->entries as $entry): ?>
<div class="entry block <?php echo $entry->class; ?>">
<div class="tab">
<ul class="tabs">
<li class="tab-link current" data-tab="Kunden">Kunden</li>
<li class="tab-link" data-tab="Loesungen">Lösungen</li>
</ul>
<?php
$this->import('Database');
$pName = $entry->field('name')->value();
$result = \Database::getInstance()->prepare("SELECT * FROM kunden WHERE partner=?")->execute($pName);
?>
<?php if($result->numRows):?>
<div id="Kunden" class="tab-content current">
<?php while($result->next()) { ?>
<div class="items">
<a href="{{env::url}}/kunden-detail/<?php echo $result->alias; ?>">
<div class="logo">
<img src="<?php $objFile = \FilesModel::findByUuid($result->logo); echo $objFile->path;?>"width="180" height="135">
</div>
</a>
</div>
<?php } ?>
</div>
<?php endif;?>
<?php
$this->import('Database');
$pName = $entry->field('name')->value();
$result = \Database::getInstance()->prepare("SELECT * FROM solutions WHERE solution_provider=?")->execute($pName);
?>
<?php if($result->numRows):?>
<div id="Loesungen" class="tab-content">
<?php while($result->next()) { ?>
<div class="items">
<a href="{{env::url}}/synaptic-commerce-solution/<?php echo $result->alias; ?>">
<div class="logo">
<img src="<?php $objFile = \FilesModel::findByUuid($result->logo); echo $objFile->path;?>"width="180" height="135">
</div>
</a>
</div>
<?php } ?>
</div>
<?php endif;?>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<?php endif;?>
In that code, I've got two DB queries. My problem is, if there is no data for both queries, the div with the class "connect_wrap" should not be displayed.
How can I do that?
Thanks in advance.
do you want to check if the query has data in it and its not empty ? if so try num_rows it will return the number of rows that the query found/affected for example to check if th query returned one or more rows
if($result->num_rows >= 1) {
//do stuf
} else {
// no result found
}
Move the query execution up or preferably: not within the html but in a different file/class. Then add a check before the content_wrap div: if($kundenResult->num_rows >= 1 || $solutionsResult->num_rows >= 1). If you just keep the individual checks like you already have, it will only show the content_wrap div if either or both of the queries return rows of data.
This is my code, actually, it actually retrieves data, but, its looking bad.
I use Jquery, (nivoSlider), and Bootstrap loaded in that order.
I have 2 results on DB, it successfully fetched title, description and other information, but it looks bad formatted, or I cannot make it to display the information correctly.
QUESTION: How can I achieve From this-> http://prntscr.com/5imr6e to this-> http://prntscr.com/5imy35 - With its proper thumbnails ?
Any help will be greatly appreciated. Thank you
$sql = "SELECT * FROM homeslider ORDER by id DESC LIMIT 6";
$query = $handler->prepare($sql);
$query->execute();
$row = $query->fetchAll();
return $row;
}
?>
<?php
$data = getContent();
foreach ($data as $row) {
echo '<div id="wrapper">
<div class="slider-wrapper theme-default">
<div id="slider" class="nivoSlider">
';
$id = $row['id'];
$titulo = $row['titulo'];
$descripcion = $row['descripcion'];
$link = $row['link'];
$imgurl = $row['imgurl'];
$ultimo_update = $row['ultimo_update'];
$captions = '';
}
echo'
<img src="images/slider/'.$imgurl.'" data-thumb="images/slider/'.$imgurl.'" data-transition="fold" title="#htmlcaption_'.$id.'" />'; ?>
<?php $captions = '<div id="htmlcaption_'.$id.'" class="nivo-html-caption">
'.$titulo.'<br/>'.$descripcion.'<span class="nivoButtonSpan">Leer más <i class="glyphicon glyphicon-share-alt"></i></span>';?>
</div> <!-- Close htmlcaption_# -->
<?php echo $captions; ?>
</div> <!-- Close slider -->
</div> <!-- Close slider-wrapper -->
</div> <!-- Close wrapper -->
Well the first thing to do is switch this to use a more readable output syntax - breaking in and out of php instead of echoing all the html as complete strings. Additionally i think you want all the images to be slides but im pretty sure you are actually creating a slider for each image...
<div id="wrapper">
<div class="slider-wrapper theme-default">
<div id="slider" class="nivoSlider">
<?php foreach($data as $row): ?>
<?php // lets use printf since the majority of this is static with just a couple vars ?>
<?php printf(
'<img src="images/slider/%s" data-thumb="images/slider/%s" data-transition="fold" title="#htmlcaption_%s" />',
$row['imgurl'],
$row['imgurl'],
$row['id']
); ?>
<?php endforeach; ?>
</div> <!-- Close slider -->
<?php // output the captions ?>
<?php foreach ($data as $row): ?>
<div id="htmlcaption_<?php echo $row['id'] ?>" class="nivo-html-caption">
<?php echo $row['titulo']; ?>
<br />
<?php echo $row['descripcion'] ?>
<span class="nivoButtonSpan">
Leer más <i class="glyphicon glyphicon-share-alt"></i></span>
</span>
</div>
<?php endforeach; ?>
</div> <!-- Close slider-wrapper -->
</div> <!-- Close wrapper -->
We could further optimize this by building a big string of the captions in the loop so that we do not need loop over the array twice:
<div id="wrapper">
<div class="slider-wrapper theme-default">
<div id="slider" class="nivoSlider">
<?php
// initialize captions as an empty string
$captions = '';
?>
<?php foreach($data as $row): ?>
<?php // lets use printf since the majority of this is static with just a couple vars ?>
<?php printf(
'<img src="images/slider/%s" data-thumb="images/slider/%s" data-transition="fold" title="#htmlcaption_%s" />',
$row['imgurl'],
$row['imgurl'],
$row['id']
); ?>
<?php ob_start(); // start a buffer ?>
<div id="htmlcaption_<?php echo $row['id'] ?>" class="nivo-html-caption">
<?php echo $row['titulo']; ?>
<br />
<?php echo $row['descripcion'] ?>
<span class="nivoButtonSpan">
Leer más <i class="glyphicon glyphicon-share-alt"></i></span>
</span>
</div>
<?php
// get the buffer contents, append them to $captions
// and then clear the buffer and stop buffering
$captions .= ob_get_clean();
?>
<?php endforeach; ?>
</div> <!-- Close slider -->
<?php // output the captions ?>
<?php echo $captions; ?>
</div> <!-- Close slider-wrapper -->
</div> <!-- Close wrapper -->
It seems that you are not closing the nivoslider div:
echo'
<img src="images/slider/'.$imgurl.'" data-thumb="images/slider/'.$imgurl.'" data-transition="fold" title="#htmlcaption_'.$id.'" />'; ?>
<?php $captions = 'CLOSE HERE: </div><div id="htmlcaption_'.$id.'" class="nivo-html-caption">
'.$titulo.'<br/>'.$descripcion.'<span class="nivoButtonSpan">Leer más <i class="glyphicon glyphicon-share-alt"></i></span>';?>
</div> <!-- Close htmlcaption_# -->
Sorry if this have been asked before but I couldn't find what I wanted and I am not strong in PHP.
Right now I have this code, which is supposed to return result for different levels:
<div class="swiper-slide">
<img src="img/B1.jpg" alt="" />
<div class="content_container">
<?php
$result = mysqli_query($con,"SELECT * FROM floor_directory WHERE level='B1'");
while($row = mysqli_fetch_array($result))
{
?>
<h1><?php echo $row['categories']; ?></h1>
<ul class="shop_listing clearfix">
<li class="float_left"><?php echo $row['name']; ?></li>
<li class="float_right"><?php echo $row['unit_number']; ?></li>
</ul>
<?php
}
?>
</div>
</div>
<div class="swiper-slide">
<img src="img/L1.jpg" alt="" />
<div class="content_container">
<?php
$result = mysqli_query($con,"SELECT * FROM floor_directory WHERE level='L1'");
while($row = mysqli_fetch_array($result))
{
?>
<h1><?php echo $row['categories']; ?></h1>
<ul class="shop_listing clearfix">
<li class="float_left"><?php echo $row['name']; ?></li>
<li class="float_right"><?php echo $row['unit_number']; ?></li>
</ul>
<?php
}
?>
</div>
</div> and so on...
Right now I can only duplicate it in order to fulfil the displaying of result for each individual levels. If let's say the building have 10 levels, is there a way to simplified the coding?
Hope you guys understand. Thanks in advance! =)
Try this:
<?php
$levelArray=array('L1','B1','L2','B2');
foreach ($levelArray as $i=>$level) {
$data='';
$img = "img/".$levelArray[$i];
$result = mysqli_query($con,"SELECT * FROM floor_directory WHERE level='$levelArray[$i]'");
while($row = mysqli_fetch_array($result)){
$data .= '<h1>'.$row['categories'].'</h1>
<ul class="shop_listing clearfix">
<li class="float_left">'.$row['name'].'</li>
<li class="float_right">'.$row['unit_number'].'</li>
</ul>';
}
echo '<div class="swiper-slide">
<img src="'.$img.'" alt="" />
<div class="content_container">'.$data.'</div>
</div>'
}
?>
I've made a repeat region with dreamweaver and the result is this:
<div>
<?php do { ?>
<div class="slide">
<img src="<?php echo $row_Recordset1['imagemUrl']; ?>" />
<h2><?php echo $row_Recordset1['titleProj']; ?></h2>
</div>
<?php while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</div>
No problem here, it works fine.
The thing is, I'm trying to use only 5 slides for each page, something like this:
<div>
<div class="page">
<?php do { ?>
<div class="slide">
<img src="<?php echo $row_Recordset1['imagemUrl']; ?>" />
<h2><?php echo $row_Recordset1['titleProj']; ?></h2>
</div>
<?php
$i = 0;
$r = $i % 5;
$i++;
if ( $r == 0 ) {
?>
</div> <!-- closes div.page -->
<div class="page"> <!-- adds a new div.page -->
<? } ?>
<?php while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</div>
It's obviously not working, but hopefully you'll see what I'm trying to reach.
Thanks in advance!
UPDATE:
The result i get is:
<div class="page">
<div class="slide">...</div>
<div class="slide">...</div>
<div class="slide">...</div>
<div class="slide">...</div>
<div class="slide">...</div>
<div class="slide">...</div>
<div class="slide">...</div>
<div class="slide">...</div>
</div>
I would like it to be:
<div class="page">
<div class="slide">...</div>
<div class="slide">...</div>
<div class="slide">...</div>
<div class="slide">...</div>
<div class="slide">...</div>
</div>
<div class="page">
<div class="slide">...</div>
<div class="slide">...</div>
<div class="slide">...</div>
</div>
You're setting $i to 0 on every iteration. Place the $i = 0 before the do-while loop.
You should probably also place $i++ before $r = $i % 5; to get the result you require.
EDIT: You're also missing a closing brace before your while statement (typo?)
Hence, the complete code:
<div>
<div class="page">
<?php
$i = 0;
do { ?>
<div class="slide">
<img src="<?php echo $row_Recordset1['imagemUrl']; ?>" />
<h2><?php echo $row_Recordset1['titleProj']; ?></h2>
</div>
<?php
$i++;
$r = $i % 5;
if ( $r == 0 ) {
?>
</div> <!-- closes div.page -->
<div class="page"> <!-- adds a new div.page -->
<?php
}
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</div>
the piece you gave is not a valid php code.
the line here:
<h2><?php echo $row_Recordset1['titleProj']; ?></h2>
opens a php tag without closing it before the next one you open.. so a first step would be to change that line to
<h2><?php echo $row_Recordset1['titleProj']; ?></h2>
also you missed closing a block, here:
<? } ?>
you should close both the if and the do/while block (so another })
another problem is the fact that on every step you change $i to 0, so every time $r will be 0 also
so in conclusion: take your problems step by step as you have more than one
<div>
<div class="page">
<?php for ($i = 0; $row_Recordset1 = mysql_fetch_assoc($Recordset1); $i++) { ?>
<div class="slide">
<img src="<?php echo $row_Recordset1['imagemUrl']; ?>" />
<h2><?php echo $row_Recordset1['titleProj']; ?></h2>
</div>
<?php if ( $i % 5 == 0 && $i ) { ?>
</div> <!-- closes div.page -->
<div class="page"> <!-- adds a new div.page -->
<?php } ?>
<?php } ?>
</div>
</div>
Something like this would loop through 5 times adding a new <div>content</div> to the variable $html. You can then echo the variable in your html body.
$html = "";
for ($i=0;$i<5;$i++) {
$html .= "<div class=\"page\">". $content[$i] . "</div>\n";
}
Additions:
<?PHP
while ($row_Recordset = mysql_fetch_assoc($Recordset1)) {
$html .= "<div class='page'>\n";
for ($i=0;$i<5;$i++) {
$html .= "<div class='slide'>". $row_Recordset[$i]['column'] . "</div>\n";
}
$html .= "</div>\n";
}
?>
This code will loop through the recordset populating $html on each iteration. Try echo $html and you will have an output structured as you want.
I would like to edit my current template in myBlog component which I believe is located here:
\components\com_myblog\templates\bluestyle
My main reason for asking is because I don't know where to fix a misalignment in the website I am maintaining.
But if you would try to browse the other tabs on top of the site, they have no problems at all, it's just so happened that myBlog component has its own template aside from the default Joomla template.
I believe the problem is somewhere in this path of my Joomla file:
C:\xampp\htdocs\lopez-link\components\com_myblog\templates\bluesky
Obviously my chosen template is named "bluesky" inside this folder it has 3 html files (bloginfo.tmpl.html, entry.tmpl.html and index.tmpl.html) and a CSS file (template_style). I included below my index.tmpl.html code.
index.tmpl.html
<?php
if ($entry and is_array($entry) and count($entry) != 0)
{
foreach ($entry as $e)
{
$date = strtotime($e['created']);
$month_day = strftime("%b ", $date) . strftime("%d", $date);
$year = strftime("%Y", $date);
$month_day = i8n_date($month_day);
?>
<div class="entryContent">
<div class="entry">
<table class="entryTitle">
<tr>
<td class="my-dateCell">
<div class="dateContainer">
<div class="date">
<div class="month"><span><?php echo $month_day; ?></span></div>
<div class="year"><span><?php echo $year; ?></span></div>
</div>
</div>
</td>
<td class="my-titleCell">
<div class="entry-title">
<h3><?php echo $e['title']; ?></h3>
<p>_MB_POSTED_BY <?php echo $e['author']; ?> in <?php echo $e['categories']; ?></p>
</div>
</td>
<?php if(!empty($e['avatar'])){ ?>
<td class="my-avatarCell">
<div class="userAvatar">
<?php echo $e['avatar']; ?>
</div>
</td>
<?php } ?>
</tr>
</table>
<?php
if ($e['beforeContent'])
{ ?>
<div class="onBeforePrepareContent">
<?php echo $e['beforeContent'];?>
</div>
<?php
}
?>
<div class="entry-body">
<?php echo $e['text']; ?>
<div class="clear"></div>
</div>
<?php if ($e['afterContent'])
{ ?>
<div class="onAfterPrepareContent">
<?php echo $e['afterContent'];?>
</div>
<?php
}
?>
<div class="entry-footer">
<?php
if ($e['comments']!="") // if comments enabled
echo '<div class="entry-comment">'.$e['comments'] .'';
else
echo '<div>';
if ($e['comments']!="" and $e['readmore']=="1")
echo ' | ';
?>
<?php // IF NEED READMORE
if ($e['readmore']=="1")
{ ?>
_MB_READ_MORE...
<?php } ?>
</div>
</div>
</div>
<?php
}
}
?>
How can I fix this?
EDITED :
May this help you.
find the code
if ($e['readmore']=="1")
{ ?>
_MB_READ_MORE...
<?php }
and replace it with
if ($e['readmore']=="1")
{ ?>
_MB_READ_MORE...
<?php }
echo '</div>';