Enrol table:
From this table I try get value from active_shop
Here I have code:
<?php
$get_config_details = $this->db->get('enrol',$per_page, $this->uri->segment(1));
?>
<?php if ($get_config_details->num_rows() > 0):
foreach($get_config_details->result_array() as $get_config_detail):
$course_details = $this->crud_model->get_course_by_id($get_config_detail['course_id'])->row_array();?>
<?php echo $get_config_detail['active_shop']; ?>
<?php endforeach; ?>
<?php endif; ?>
Now I get the result: 1
But I copied this function from another function. I don't need the foreach function and if and so much code here. I need some simple code to squeeze this table and echo the result. Can anyone help me to correct this code?
Related
I want to fetch YouTube embedded link from database and to run in a while loop that its not coming in while loop.
<?php
$video_query=mysqli_query($connect,"select Vdo_SNo, Vdo_Name, Vdo_Category, Vdo_Discription, Vdo_Date from user_videoarena where user_did='3' AND Vdo_Category='Portfolio' ORDER BY Vdo_SNo DESC ");
$i = 1;
while ($video_Row = mysqli_fetch_array($video_query)){
?>
<div class="video_sec fl">
<?php echo $video_Row['Vdo_Name']; ?>
</div><!------------ video_sec -------------------->
<?php $i++; }
?>
With this code only a single video is fetching but not all that is stored in database.
try
<?php
$video_query=mysqli_query($connect,"select Vdo_SNo, Vdo_Name, Vdo_Category, Vdo_Discription, Vdo_Date from user_videoarena where user_did='3' AND Vdo_Category='Portfolio' ORDER BY Vdo_SNo DESC LIMIT 10 ");
while($video_Row = mysqli_fetch_array($video_query)){
?>
<div class="video_sec fl">
<?php echo $video_Row['Vdo_Name']; ?>
</div>
<?php } ?>
If Your record is row-wise in Sql Table then You Have to use a Simple For-loop
First store the result of query in one array.
Then print the array and check the output. If output is same as you want. and if not then you have something mistake in query.
Then simply make a loop like this
for($i=0;$i<count($array_name);$i++){
echo $array[$i]['field name_in_database'];
}
Hope this solution help you.
i have a write panel in magic fields with a group that can be duplicated, within this is an image field that can be duplicated.
So far i have the code for the duplicate group but i'm a little stuck on how to display the duplicate field within this.
I'm using Magic Fields 1.6.2.1
My code for the duplicate group is
<?php
$gallerys = getGroupOrder('gallery_section_title');
foreach($gallerys as $gallery) {
?>
<?php echo get('gallery_section_title',$gallery);?>
<?php echo get('gallery_section_text',$gallery);?>
<?php echo get('gallery_section_image',$gallery);?>
<?php } ?>
This part is the part that needs to be duplicated with in the duplicate group
<?php echo get('gallery_section_image',$gallery);?>
I did a few searches but can't find anything that works.
Does anyone have any ideas how to implement this, i'm stumped.
Thank you
I've worked this out and the code below works for me, there a probably a better more efficient way of doing it, but this works.
<?php $groups = getGroupOrder('gallery_section_title');
foreach($groups as $group) { ?>
<?php echo get('gallery_section_title', $group); ?>
<?php echo get('gallery_section_text', $group); ?>
<?php $fields = get_field_duplicate('gallery_section_image',$group);
foreach($fields as $field)
{ ?>
<?php echo $field[o]; ?>
<?php } ?>
<?php } ?>
I have a code that can get me the category_id of an item. This is the code:
<?php echo lavada_category_id() ; ?>
I want to know how I can add this code. Inside this, I want to replace the number 2 in here;
<?php lavada_query_item("category=2");?>
with:
<?php echo lavada_category_id() ; ?>
I know you cannot do like this
<?php lavada_query_item("category=<?php echo lavada_category_id() ; ?>");?>
But how can I do it?
Why not store it into a variable and then use that variable?
<?php
$catID = lavada_category_id();
lavada_query_item("category={$catID}");
?>
OR if you just want category ID to be passed into lavada_query_item do this:
lavada_query_item($catID);
The syntax error that you have is that you can not use <?php within <?php
You just need to concatenate the string like this:
<?php lavada_query_item("category=". lavada_category_id() );?>
I think this is what you are looking for:
<?php lavada_query_item(lavada_category_id());?>
The value returned from thelavada_category_id() function will be passed into the lavada_query_item() function.
I need a code that pulls out the listings count for a product in order to have them in the navigation. I am trying to get the product and listing number in the navigation (if there is any), but I don't want to display something if the listings count is equals to 0.
Here follows my code:
<?php if($listingsCount = getListingsCount(0,0,2,2,1,86) > 0): ?>
Bakery
<?php echo $listingsCount['totalRecords'] ?>.
<?php else: ?>
It should be
if ( ($listingsCount = getListingsCount(0,0,2,2,1,86)) > 0)
In this case you the assignment is done first and is then compared to 0. So $listingCount contains the real count.
The way you did it, the comparison is done first and the return value (true/false) is assigned to $listingCount.
Nevertheless. If you never reach the else-part, maybe something in your method getListingsCount() is broken.
Try this:
<?php if (($listingsCount = getListingsCount(0,0,2,2,1,86)) > 0) { ?>
Bakery
<?php echo $listingsCount['totalRecords']; ?>
<?php } else { ?>
Other text
<?php }?>
Thanks guys for your answers. managed to get it working with this...
<?php
$listingsCount = getListingsCount(0,0,2,2,1,86);
if($listingsCount['totalRecords'] > 0):
?>
<dd>
Bakery
[<?php echo $listingsCount['totalRecords'] ?>]
</dd>
<?php endif; ?>
How do you when using custom fields in Wordpress echo just the first value using foreach?
Currently the code is:
<?php for(get_field('venue_event') as $post_object): ?>
<?php echo get_the_title($post_object) ?>
<?php endforeach; ?>
This takes the field from the wordpress page (the field is a link to another page), creates a link to that page using get_permalink but when I want to echo the page title it does it, but then it also echos all other values that are not needed.
If you just want the execute the first iteration of the loop, try this:
<?php foreach(get_field('venue_event') as $post_object): ?>
<?php echo get_the_title($post_object) ?>
<?php break; ?>
<?php endforeach; ?>
Wouldn't it then be easier just to use the first element of the returned array? Maybe Wordpress offers other filters that return the the page's title only.
you can just add
$counter = 0;
<?php for(get_field('venue_event') as $post_object): ?>
$counter++;
if($counter == 1)
{
<?php echo get_the_title($post_object) ?>
}
<?php endforeach; ?>