I want to iterate foreach loop to get list of Property details but this code shows nothing please anybody tell me what is wrong in my code
I am new to php.
<?php foreach ($this->Property_Model->getProperty() as $property): ?>
<div class='properties'>
<div class='image-holder'><img src='images/properties/1.jpg' class='img-responsive' alt='properties'/>
<?php if (strcmp($property->status, 'new') == 0) {
?>
<div class='status sold'><?php $property->status ?></div>
<?php
} else {
?>
<div class='status new'><?php $property->status ?></div>
<?php } ?>
</div>
<h4><a href='property-detail.php'><?php $property->property_info ?></a></h4>
<p class='price'><?php $property->prize ?></p>
<div class='listing-detail'>
<span data-toggle='tooltip' data-placement='bottom' data-original-title='Bed Room'>5</span>
<span data-toggle='tooltip' data-placement='bottom' data-original-title='Living Room'>2</span>
<span data-toggle='tooltip' data-placement='bottom' data-original-title='Parking'>2</span>
<span data-toggle='tooltip' data-placement='bottom' data-original-title='Kitchen'>1</span>
</div>
<a class='btn btn-primary' href='property-detail.php'>View Details</a>
</div>
<?php endforeach; ?>
your file line of view is incorrect
< php foreach($this->Property_Model->getProperty() as $property): ?>
you forget ? in your php tag
it should be
<?php foreach($this->Property_Model->getProperty() as $property): ?>
and you can call your model in controller not in view
Related
I have created a module in Joomla which will fetch the values from Joomla database table and show in a bootstrap HTML carousal. fetching part is working well but whenever I put the PHP code into Html code where I want those fields to display the carousel is not working. any help will be appreciated. below is my full page code (tmpl/dafault.php)
<script type="text/javascript" src="//cdn.jsdelivr.net/npm/afterglowplayer#1.x"></script>
<?php
defined('_JEXEC') or die;
?>
<?php
$db = JFactory::getDBO();
try {
$query = $db->getQuery(true);
$query->select("*")
->from("tkps5_spotlightamsw_spotlight");
$db->setQuery($query);
$row = $db->loadObjectList();
}
catch (exception $e) { echo $e; }
?>
<div class="container" style="margin-top: 50px;">
<div class="row">
<div class="col-md-6">
<h2 class="block-title1">xyz text</h2>
<p class=" "><a class="button subbutton btn btn-border1" href="#">More info</a></p>
</div>
<div class="col-md-6">
<h2 class="block-title1">Spotlight</h2>
<!-- Wrapper for slides -->
<script>
$(document).ready(function() {
//Enable swiping...
$(".carousel-inner").swipe( {
//Generic swipe handler for all directions
swipeLeft:function(event, direction, distance, duration, fingerCount) {
$(this).parent().carousel('prev');
},
swipeRight: function() {
$(this).parent().carousel('next');
},
//Default is 75px, set to 0 for demo so any distance triggers swipe
threshold:0
});
});
</script>
<?php foreach ($row as $row): ?>
<?php
$fetured_spotlight = $row->featured_spotlight;
$name = $row->name;
$modified_date = $row->modified;
if($fetured_spotlight == 1 )
{
echo "<div id='myCarousel' class='carousel slide' data-ride='carousel' data-touch='true'> ";
echo " <div class='carousel-inner'>";
echo substr($modified_date,0 , 10);
echo "<div class='item '>";
echo "<img src='".$row->thumbnailimage."' alt='".$name."'>";
echo "<div class='carousel-caption1'>";
echo "<p><strong>".$name."</strong></p>";
echo "</div>";
echo "</div>";
//echo $row->name;
echo " <a class='left carousel-control' href='#myCarousel' data-slide='prev'>";
echo " <span class='glyphicon glyphicon-chevron-left'></span>";
echo " <span class='sr-only'>Previous</span>";
echo " </a>";
echo " <a class='right carousel-control' href='#myCarousel' data-slide='next'>";
echo " <span class='glyphicon glyphicon-chevron-right'></span>";
echo " <span class='sr-only'>Next</span>";
echo " </a>";
echo "</div>";
}
?>
<?php endforeach; ?>
<!-- Left and right controls
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">Next</span>
</a>-->
<p class="align-right"><a class="button subbutton btn btn-border1" href="flame-spotlight">VIEW ALL</a></p>
</div>
</div>
</div>
</div>
Finally i got the answer where i was not assigning the "active" class to first slider image. so below is my working code .. just posting for loop rest of the code is same..
<?php foreach ($row as $key=>$row): ?>
<?php
$fetured_spotlight = $row->featured_spotlight;
$name = $row->name;
if($fetured_spotlight == 1 )
{
?>
<div class='item <?php echo ($key == 0) ? "active" : ""; ?>'>
<?php
echo "<img src='".$row->thumbnailimage."' alt='".$name."'>";
echo "<div class='carousel-caption1'>";
echo "<p><strong>".$name."</strong></p>";
echo "</div>";
//echo $row->name;
echo "<br />";
}
?>
</div>
<?php endforeach; ?>
I am working on search data, and want to send HTML from controller to view with AJAX. I am getting syntax error. Here is my code.
function search()
{
$params['searchKeys'] = $this->input->post('query');
$params['userID'] = $this->session->userdata('id');
$storeArray = $this->Store_model->searchStore($params);
foreach($storeArray as $store){
echo "<div class='col-lg-3 col-md-4 col-sm-6 col-xs-12'>
<div class='store-block'>
<img class='img-responsive' src=".getImageURL($s['image'], array( 'alt' => '' )).">
<div class='overlay'>
<h2>".$s['storeName']."</h2>".if($this->session->userdata('userType') == '2'):.
.if($s['isBlocked'] == '1'):.
"<a class='info'>Your store is blocked!</a>
".else:."
<a class='info' href=".site_url('Store/preview/'.encode($s['storeID'])).">Preview</a>
<a class='info' href=".site_url('Slot/index/'.encode($s['storeID'])).">Slots</a>
<a class='info' href=".site_url('Booking/index/'.encode($s['storeID'])).">Bookings</a>
<a class='info' href=".site_url('Store/edit/'.encode($s['storeID'])).">Edit</a>
<a class='info' href='#'data-toggle='modal' data-target='#confirm-".$s['storeID'].">Delete</a>
".endif;."
".elseif($this->session->userdata('userType') == '1'):."
<a class='info' href=".site_url('Store/preview/'.encode($s['storeID'])).">Preview</a>
".if($s['isBlocked'] == '0'):.
"<a class='info' href='#' data-toggle='modal' data-target='#confirm-block-".$s['storeID'].">Block</a>
".else:."
<a class='info' href='#' data-toggle='modal' data-target='#confirm-unblock-".$s['storeID'].">Un block</a>
".endif.
.endif."
</div>
</div>
</div>
</div>
";
}
exit;
}
I am getting error on this line.
<h2>".$s['storeName']."</h2>".if($this->session->userdata('userType') == '2'):.
The error is because $s is not defined. You either have to change
foreach($storeArray as $store){
to
foreach($storeArray as $s){
Or change every instance of $s['example_key'] to $store['example_key']
But you are still going to run into the problem described in #Bartek's comment.
This whole thing could be made easier by using $this->load->view which will "echo" the view file for you. Writing HTML that drops into and out of the PHP processor is easier to write and read. Plus it's a lot more versatile.
Here's the controller that loads a view.
public function search()
{
$params['searchKeys'] = $this->input->post('query');
$params['userID'] = $this->session->userdata('id');
$viewdata['storeArray'] = $this->Store_model->searchStore($params);
$this->load->view('store_search_view', $viewdata);
}
The "view": /application/views/store_search_view.php
<?php
foreach ($storeArray as $s) :
$storeID = $s['storeID'];
$enc_storeID = encode($storeID);
?>
<div class='col-lg-3 col-md-4 col-sm-6 col-xs-12'>
<div class='store-block'>
<img class='img-responsive' src=".getImageURL($s['image'], array( 'alt' => '' )).">
<div class='overlay'>
<h2><?php echo $s['storeName']; ?></h2>"
<?php
if($this->session->userdata('userType') == '2'):
if($s['isBlocked'] == '1'):
?>
<a class='info'>Your store is blocked!</a>
<?php
else:
?>
<a class='info' href='<?php echo site_url('Store/preview/'.$enc_storeID); ?>'>Preview</a>
<a class='info' href='<?php echo site_url('Slot/index/'.$enc_storeID); ?>'>Slots</a>
<a class='info' href='<?php echo site_url('Booking/index/'.$enc_storeID); ?>'>Bookings</a>
<a class='info' href='<?php echo site_url('Store/edit/'.$enc_storeID); ?>'>Edit</a>
<a class='info' href='#' data-toggle='modal' data-target='#confirm-<?= $storeID; ?>'>Delete</a>
<?php
endif;
elseif($this->session->userdata('userType') == '1'):
?>
<a class='info' href='<?= site_url('Store/preview/'.$enc_storeID); ?>'>Preview</a>
<?php if($s['isBlocked'] == '0'): ?>
<a class='info' href='#' data-toggle='modal' data-target='#confirm-block-<?= $storeID; ?>'>Block</a>
<?php else: ?>
<a class='info' href='#' data-toggle='modal' data-target='#confirm-unblock-<?= $storeID; ?>'>Un block</a>
<?php
endif;
endif;
?>
</div>
</div>
</div>
<?php
endforeach;
In case you're wondering, it is more efficient to drop into and out of PHP "mode" than to concatenate a gigantic string. There is zero performance penalty for switching between processing PHP and outputting HTML directly.
If you're not familiar with the syntax, <?= ... is the same as <?php echo .... If it seems I was switching between the two syntax styles at random that is true. There's no reason for one style over the other except one involves less typing.
<h2>".$s['storeName']."</h2>".if($this->session->userdata('userType') == '2'):.
The error comes from if() part. You can't use if() inside echo.
Instead you can save result of your if condition to variable and display it in echo or you can put your echo inside the if() else block.
I'm inner joining two databases together here, when using the separate views individually they work fine, so do the databases, I think the cause of this is the inner join, but putting the query directly into phpmyadmin and replacing the $categoryID with a number works.
Some rows load, such as the images, but joined variables are undefined, What is causing the variables to be undefined?
Model:
function DisplayBySpecificCategory($categoryID)
{
$query = $this->db->query("SELECT * FROM CIUploads
INNER JOIN CIUsers ON CIUploads.UserID = CIUsers.UserID
WHERE CIUploads.UploadCategoryID = $categoryID
ORDER BY CIUploads.UploadTime DESC");
return $query->result();
}
Controller:
function SpecificCategory()
{
$categoryID=$this->uri->segment(3);
$this->load->model('Previews_model');
$this->load->model('Category_model');
$this->load->view('../includes/header.php');
$data['category'] = $this->Category_model->GenerateCategoryHeader($categoryID);
$data['allwork'] = $this->Previews_model->DisplayBySpecificCategory($categoryID);
$this->load->view('headers/Specific_category_header', $data);
$this->load->view('previews/Previews_view', $data);
$this->load->view('../includes/footer.php');
}
Header view:
<?php foreach ($category as $value2){ ?>
<header style="background-color:#<?php echo $value2->CategoryColor ?>">
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="page-intro">
<h1 class="inverted text-center"><?php echo $value2->CategoryTitle ?></h1>
<p class="inverted text-center"><?php echo $value2->CategoryDescription ?></p>
</div>
</div>
</div>
</div>
</header>
<?php } ?>
Previews view:
<?php
if($value->UploadCategoryID == 2){
echo '<video muted class="video-responsive fit-centered">';
echo '<source src="'.base_url("/public/uploads/works")."/".$value->UploadedAt.'" type="video/mp4">Your browser does not support the video tag.';
echo '</video>';
}
else if($value->UploadCategoryID == 3){
echo '<iframe class="fit-centered" src="http://'.$value->UploadedAt.'" scrolling="no"></iframe>';
}
else{
echo '<img class="img-responsive fit-centered" src="'.base_url("/public/uploads/works")."/".$value->UploadedAt.'" alt="'.$value->UploadTitle.'">';
} ?>
<div class="overlay">
<p>
<i class="fa fa-eye fa-3x ease-color"></i>
</p>
</div>
</div>
<div class="hovereffect-information no-bounding">
<span class="category-tab pull-right text-center inverted" style="background-color:#<?php echo $value->CategoryColor ?>"><i class="fa <?php echo $value->CategoryIcon ?>"></i></span>
<p class="pull-left no-bounding text-uppercase preview-info"><?php echo $value->UploadTitle ?></p>
<img class="img-responsive small-profile-img pull-right hover-dim fit-centered" src="<?php echo base_url("/public/uploads/profile-images/")."/".$value->ProfileImg ?>" alt="<?php echo $value->Username ?>"/>
<p class="pull-left no-bounding text-uppercase preview-info">
<span class="preview-span"> <i class="fa fa-eye"></i> <?php echo $value->UploadViews ?> </span> |
<span class="preview-span"> <i class="fa fa-heart"></i> <?php echo $value->UploadLikes ?> </span> |
<span class="preview-span"> <i class="fa fa-comments"></i> <?php echo $value->UploadComments ?> </span>
</p>
</div>
</div>
<?php } ?>
Error:
Severity: Notice
Message: Undefined property: stdClass::$CategoryIcon
Filename: previews/Previews_view.php
Line Number: 31
Backtrace:
File:
/web/stud/u1263522/cmw/application/views/previews/Previews_view.php
Line: 31 Function: _error_handler
File:
/web/stud/u1263522/cmw/application/controllers/Views_controller.php
Line: 64 Function: view
File: /web/stud/u1263522/cmw/index.php Line: 292 Function:
require_once
In the question you have mentioned : Undefined property: stdClass::$CategoryID
whereas the error shows : Undefined property: stdClass::$CategoryIcon
If $CategoryIcon is undefined it means that you do not have a column called CategoryIcon in any of your tables.
Can you mention the details of the tables?
It is always a good practice to mention the column names in the query instead of *.
add your loading model before called in Controller , Check name is correct , Make sure that some name in (model = Class)
$this->load->model('model_name'); //
Or in Confige.php
Well im having this problem and cant resolved it would like to have some help from you guys, so here it is:
I have this code:
<?php if (mysql_num_rows($tournaments) !=0){
do { ?>
<div id="mainContainer">
<div id="leftContainer">
<img src="images/tournaments/<?php echo $row_tournaments['logo']; ?>.png">
</div>
<div id="rightContainer">
<div id="rightContent">
<p><?php echo $row_tournaments['description']; ?></p>
<a href="tournaments.php?id_tournament=<?php echo $row_tournaments['id_tournament']; ?>">
<div id="galleryButton">
<p>Entrar no torneio</p>
</div>
</a>
</div>
<div id="rightDetails">
<i class="fa fa-gamepad"></i>
<a href="games.php?id_game=<?php echo $row_tournaments['id_game']; ?>">
<?php echo $row_tournaments['game']; ?>
</a>
<br>
<i class="fa fa-calendar-o"></i>
<a href="#">
<?php echo $row_tournaments['date']; ?>
</a>
<br>
<i class="fa fa-pencil-square-o"></i>
<a href="tournaments.php?id_tournament=<?php echo $row_tournaments['id_tournament']; ?>#disqus_thread">
Sem comentários
</a>
<br>
<script type="text/javascript">
function giveThatInputAValue(){
var elem = document.getElementById("search");
elem.value = "<?php echo $row_tournaments['city']; ?>";
/*document.forms["form"].submit();
*/}
</script>
<i class="fa fa-map-marker"></i>
<a onClick="giveThatInputAValue()">
<?php echo $row_tournaments['city']; ?>
</a>
<br>
<img src="images/<?php echo $row_tournaments['online']; ?>.png">
<a href="#">
<?php echo $row_tournaments['online']; ?>
</a>
</div>
</div>
</div>
<?php } while ($row_tournaments = mysql_fetch_assoc($tournaments));
} else {
?>
<div id="noresults">
<p>Sem torneios</p>
</div>
<?php } ?>
Everything loop fine but this part is not looping at all:
<script type="text/javascript">
function giveThatInputAValue(){
var elem = document.getElementById("search");
elem.value = "<?php echo $row_tournaments['city']; ?>";
/*document.forms["form"].submit();*/
}
</script>
And dont know why is it, someone please help. Cumps.
You are defining your function in a loop. Over and over again. So when you call your function, which one should it call? Probably all previous ones have been overwritten by the last version.
You should define your function outside of any loop and then call it with the parameters that you have available in the loop.
Apart from that you are also adding elements with ID's in your loop. ID's need to be unique as well so you should use classes or give them a unique ID.
a real php programmer knows this (meaning i am not one). been a while away from php.
ok first as i see it you never get your first row from result set (someone advise here). you are checking to see if you have rowcount then plod about. i reserve the right to be very wrong.
try something like
if ($result) {
while($row = mysql_fetch_array($result)) {
// output $row info
}
}
else {
echo "nada";
}
put your script for the function at the top
don't surround the main div section creations like you are with a loop
this code out put is here....(look at the footer subscribe section )
<?php if(!empty($this->items))foreach($this->items as $level): ?>
<?php
$formatedPrice = sprintf('%1.02f',$level->price);
$dotpos = strpos($formatedPrice, '.');
$price_integer = substr($formatedPrice,0,$dotpos);
$price_fractional = substr($formatedPrice,$dotpos+1);
?>
<div class="level akeebasubs-level-<?php echo $level->akeebasubs_level_id ?>">
<p class="level-title">
<span class="level-price">
<?php if(AkeebasubsHelperCparams::getParam('currencypos','before') == 'before'): ?>
<span class="level-price-currency"><?php echo AkeebasubsHelperCparams::getParam('currencysymbol','€')?></span>
<?php endif; ?>
<span class="level-price-integer"><?php echo $price_integer ?></span><?php if((int)$price_fractional > 0): ?><span class="level-price-separator">.</span><span class="level-price-decimal"><?php echo $price_fractional ?></span><?php endif; ?>
<?php if(AkeebasubsHelperCparams::getParam('currencypos','before') == 'after'): ?>
<span class="level-price-currency"><?php echo AkeebasubsHelperCparams::getParam('currencysymbol','€')?></span>
<?php endif; ?>
</span>
<span class="level-title-text">
<a href="<?php echo JRoute::_('index.php?option=com_akeebasubs&view=level&slug='.$level->slug.'&format=html&layout=default')?>">
<?php echo $this->escape($level->title)?>
</a>
</span>
</p>
<div class="level-inner">
<div class="level-description">
<div class="level-description-inner">
<?php if(!empty($level->image)):?>
<img class="level-image" src="<?php echo JURI::base()?><?php echo trim(AkeebasubsHelperCparams::getParam('imagedir','images/'),'/') ?>/<?php echo $level->image?>" />
<?php endif;?>
<?php echo JHTML::_('content.prepare', AkeebasubsHelperMessage::processLanguage($level->description));?>
</div>
</div>
<div class="level-clear"></div>
<div >
<button onclick="window.location='<?php echo JRoute::_('index.php?option=com_akeebasubs&view=level&slug='.$level->slug.'&format=html&layout=default')?>'">
<?php echo JText::_('COM_AKEEBASUBS_LEVELS_SUBSCRIBE')?>
</button>
</div>
</div>
</div>
<?php endforeach; ?>
this is the language file contain that name
COM_AKEEBASUBS_LEVELS_SUBSCRIBE="Subscribe Now"
I want to name those three sections butons as 6month,12month,24month
How will change the code ?
If you are unable to get the value using PHP, try changing the value of the button's name on page load
Here is the JQUERY
$(document).ready(function){
$('div.akeebasubs-awesome-description').each(function(
substription = $(this).children('H4').html()
button = $(this).parent().next().children('button')
$(button).attr(name,substription.split(' ')[0]+'month')
})
})
and the JAVASCRIPT
divs = document.getElementsByClassName('akeebasubs-awesome-description');
for (var i in divs){
divs[i].parentElement.nextElementSibling.children[0].name = divs[i].children[0].innerHTML.split(' ')[0] + 'month'
}
This will take the text of the H4 and make that the corresponding button's name