category_id name parent_id Action
1 pranav 0 Edit
2 shah 1(pranav) Edit
3 bugle 2(shah) Edit
Instead of parent id, I want to display name over there in codeigniter.
<td><?php echo $cat->parent_id; ?>
<?php foreach ($category as $child): ?>
if($cat->parent_id == $child->category_id)
{
echo $child->name;
break;
}
<?php endforeach; ?>
Related
I have magento website that develop using 1.9 version and i need to display the out of stock status on product page for both simple product & configurable product
I have tried below method and It's only getting status of simple products
$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product);
$qty = $stock->getQty();
What i need is How to display the out of stock status for simple and configurable products in product page
This code works for me,
Hope this will help you.
if( $_product->getTypeId() == 'simple' ){
if ($_product->getStockItem()->getIsInStock()<= 0) { ?>
<span class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('Out of stock') ?></span></span>
<?php }else { ?>
<span class="availability in-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('In stock') ?></span></span>
<?php };
}
else{
$_product->getTypeInstance(true)->getUsedProducts ( null, $_product);
foreach ($_product->getTypeInstance(true)->getUsedProducts ( null, $_product) as $simple) {
$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($simple)->getQty();
$stockTotal = $stockTotal + $stock;
}
if ($stockTotal <= 0){ ?>
<span class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('Out of stock') ?></span></span>
<?php } else{ ?>
<span class="availability in-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('In stock') ?></span></span>
<?php }
}
The code below is the view page used to display the different kinds of questions and their choices.. Questions like Fill in the blanks and multiple answer consists of more than one answer element.
<?php echo form_open('courseware/saveanswer'); ?>
<?php if(count($test_questions)):?>
<?php $i = 1 ?>
<ol>
<?php foreach($test_questions as $test_question):?>
<li>
<?php if($test_question->question_type == 'Fill-blanks'):?>
<?php $test_question->question_text = str_replace('___',form_input(array('name'=>'answer[]','id'=>'answer_'.$i++,'type'=>'text','size'=>'8')),$test_question->question_text)?>
<?php endif ?>
<?php echo $test_question->question_text ?>
<?php if($test_question->question_type == 'Multi-choice'):?>
<?php $choices = explode("\n", $test_question->question_choices)?>
<?php if(count($choices)):?>
<ul>
<?php foreach($choices as $choice):?>
<li><?php echo form_radio('answer'.$test_question->question_id,$choice) ?> <?php echo $choice ?></li>
<?php endforeach ?>
</ul>
<?php echo form_submit('$save', 'Save') ?>
<?php endif ?>
<?php elseif($test_question->question_type == 'Multi-answer'):?>
<?php $choices = explode("\n", $test_question->question_choices)?>
<?php if(count($choices)):?>
<ul>
<?php foreach($choices as $choice):?>
<li><?php echo form_checkbox('answer',$choice) ?> <?php echo $choice ?></li>
<?php endforeach ?>
</ul>
<?php echo form_submit('$save', 'Save') ?>
<?php endif ?>
<?php elseif($test_question->question_type == 'True/False'):?>
<ul>
<li><?php echo form_radio('answer_'.$test_question->question_id,1) ?> True</li>
<li><?php echo form_radio('answer_'.$test_question->question_id,0) ?> False</li>
</ul>
<?php echo form_submit('$save', 'Save') ?>
<?php else:?>
<?php endif ?>
</li>
<?php endforeach?>
<?php echo form_close(); ?>
below is a screenshot.
The question page looks like this ..
I want an array that has all the answers selected and sends the data to the database
The database consists of the table tbl_response and has the columns
test_reponse_id,
test_reponse_text ,
question_id ,
there's a number of ways to store multiple elements in a single value. You can use an implode() function to save as a string with a separator, as you are already doing with the $test_question->question_choices , which is separated by a '\n'. The cleanest alternative to that is often using json_encode().
either way, as you're presumably going to be comparing the selected answer(s) to something else, i suggest being careful about keeping the format and order consistent.
I created a form where we can register youtube embed url in a post.
I'd like to display the iframe only if an url has been register for this post.
I made this code to display the report information :
<?php
$req = $db->query('SELECT id, title, author, category, date_event, country, city, content, tag, youtube FROM report ORDER BY date_creation DESC LIMIT 0, 10');
while ($data = $req->fetch())
{
?>
<div class="news">
<h3><?php echo htmlspecialchars($data['title']); ?></h3>
<p>Author: <?php echo htmlspecialchars($data['author']); ?></p>
<p>Category : <?php echo htmlspecialchars($data['category']); ?></p>
<p>Date of the event : <?php echo htmlspecialchars($data['date_event']); ?></p>
<p>Country : <?php echo htmlspecialchars($data['country']); ?></p>
<p>City : <?php echo htmlspecialchars($data['city']); ?></p>
<p class="display_list"><?php echo html_entity_decode($data['content'], ENT_HTML5 , 'UTF-8'); ?></p>
<p>Tag : <?php echo htmlspecialchars($data['tag']); ?></p>
<p>Youtube : <?php echo htmlspecialchars($data['youtube']); ?></p>
<p>
<?php
$youtube=$data['youtube'];
if($youtube==1){
echo "<p>display iframe</p>";
}else{
{
echo "<p>don't display iframe</p>";
}
}
?>
</p>
The request to display url with works correctly. the urls are displayed if they are contained in the row.
However the condition code displays the same answers for all the posts : "don't display iframe".
The condition statement for $youtube variable is certainly not right but I can't figure out the issue.
you have assigned $youtube=1; instead of $youtube=$data['youtube']; in the code
try this
<?php
$req = $db->query('SELECT id, title, author, category, date_event, country, city, content, tag, youtube FROM report ORDER BY date_creation DESC LIMIT 0, 10');
while ($data = $req->fetch())
{
?>
<div class="news">
<h3><?php echo htmlspecialchars($data['title']); ?></h3>
<p>Author: <?php echo htmlspecialchars($data['author']); ?></p>
<p>Category : <?php echo htmlspecialchars($data['category']); ?></p>
<p>Date of the event : <?php echo htmlspecialchars($data['date_event']); ?></p>
<p>Country : <?php echo htmlspecialchars($data['country']); ?></p>
<p>City : <?php echo htmlspecialchars($data['city']); ?></p>
<p class="display_list"><?php echo html_entity_decode($data['content'], ENT_HTML5 , 'UTF-8'); ?></p>
<p>Tag : <?php echo htmlspecialchars($data['tag']); ?></p>
<p>
<?php
$youtube=$data['youtube'];
if($youtube==1){
echo "<p>display iframe</p>";
}else{
{
echo "<p>don't display iframe</p>";
}
}
?>
</p>
I wish to do something like this:
apple
bag
cat
dog
the first column: generate auto number start with 1.
the second column: get data from database
<table>
<?php do { ?>
<tr>
<td><ol>
<li></td>
<td><?php echo $row["object"]; ?></td>
</li></ol>
</tr>
<?php } while ($row = mysql_fetch_assoc($recordset)); ?>
</table>
The coding above make like:
1 apple
1 bag
1 cat
1 dog
I do not know where am I wrong. Please correct me. Thank you.
You're creating a new ordered list with each record. You're also mixing your ordered list in tables, which doesn't make sense - do one or the other.
Maybe something like:
<ol>
<?php do { ?>
<li><?php echo $row["object"]; ?></li>
<?php } while ($row = mysql_fetch_assoc($recordset)); ?>
</ol>
Im trying to display a few rows of data for each <h3><?php echo $name; ?></h3> item that appears in the loop.
With the current code it only shows one row for each item <h3><?php echo $name; ?></h3>
I have this in my functions.php file
$newdb = new wpdb('login', 'pass', 'db', 'host');
<?php $result=$newdb->get_results('select tbl1.name, tbl2.col1, tbl2.col2, tbl2.col3 from tbl1, tbl2 where tbl1.name=tbl2.tbl1_name');
$names=array();
foreach($result as $row): ?>
<?php $names[$row->name][]=$row;
endforeach; ?>
<?php foreach($names as $name=>$info): ?>
<h3><?php echo $name; ?></h3>
<table>
<tr><th>col1</th><th>col2</th><th>col3</th></tr>
<?php foreach($info as $n):?>
<tr>
<td><?php echo $n->col1; ?></td>
<td><?php echo $n->col2; ?></td>
<td><?php echo $n->col3; ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php endforeach; ?>
So the loop displays the heading followed by a few rows of records, not just one.
<h2>Name</h2>
<table>
<tr><th>col1</th><th>col2</th><th>col3</th></tr>
col1-value1 col2-value1 col3-value1
col1-value2 col1-value2 col1-value2
etc.
</table>
<h2>Name</h2>
<table>
<tr><th>col1</th><th>col2</th><th>col3</th></tr>
col1-value1 col2-value1 col3-value1
col1-value2 col1-value2 col1-value2
etc.
</table>
<h2>Name</h2>
<table>
<tr><th>col1</th><th>col2</th><th>col3</th></tr>
col1-value1 col2-value1 col3-value1
col1-value2 col2-value2 col3-value2
etc.
</table>
.....`
It's possible using your idea but you can do it using one query like
global $wpdb;
$result=$wpdb->get_results('select a.col, b.col1, b.col2, b.col3 from a,b where a.col=b.col5');
Assume that you have tbl1 table and it has a name field and tbl2 table and it has a field for example tbl1_name which has the name value of tbl1 name field and other fields, (with no duplicates) so you can join both tables like
$result=$wpdb->get_results('select tbl1.name, tbl2.col1, tbl2.col2, tbl2.col3 from tbl1, tbl2 where tbl1.name=tbl2.tbl1_name');
$names=array();
foreach($result as $row): ?>
$names[$row->name][]=$row;
<?php endforeach; ?>
foreach($names as $name=>$info):
echo $name;
?><table><?php
foreach($info as $n):
?>
<tr>
<td><?php echo $n->col1; ?></td>
<td><?php echo $n->col2; ?></td>
<td><?php echo $n->col3; ?></td>
</tr>
<?php
<?php endforeach; ?>
?></table><?php
<?php endforeach; ?>
Also remember $wpdb is a global object and available through the template files so you dont need to use new to make an instanse, just use global keyword as I wrote in my answer.
Class Reference/wpdb and sql join and this one.