numbering in column and the other column get data from database - html

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>

Related

How associated products attribute display on product page (Grouped product)

I need to show my associated products custom attribute like size,color under Grouped product. Inside the below table code. I am a beginner in magento project. Please give a solution.
<?php foreach ($_associatedProducts as $_item): ?>
<?php $_finalPriceInclTax = $this->helper('tax')->getPrice($_item, $_item->getFinalPrice(), true) ?>
<tr>
<td><!--Color--></td>
<td><!--Size--></td>
I found the below code which solved my problem.
<td><?php echo $this->htmlEscape($_item->getAttributeText('shirtcolor')); ?></td>
<td><?php echo $this->htmlEscape($_item->getAttributeText('shirtsize')); ?></td>
If anybody tried solution for my question Thank You!

Dispay parent name in child id..instead of child id in codeigniter

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; ?>

How to fectch data from table in cakephp

Hi i have one table in my database which has list of states and i want to fetch this data from the table but my query is not executing properly it gives me some error
<?php
require_once('../Config/database.php');
$result1=$this->Signup->query("SELECT * FROM states");
//echo $popular;
while($post = mysql_fetch_array($result1))
{ ?>
<table width="380">
<tr>
<td class="table_txt"><a class="thickbox tn" href="demo.php?state_name=<?php echo $post['state_name']?>&state_id=<?php echo $post['state_id']?>&height=430&height=430&width=700&inlineId=myOnPageContent"><?php echo $post['state_name']?></a></td>
</tr>
</table>
<?php }
?>
But it gives me error
Warning (512): Method SignupHelper::query does not exist [CORE\Cake\View\Helper.php, line 192
Warning (2): mysql_fetch_array() expects parameter 1 to be resource, null given
Please read the documentation first.
It seems you are trying to get the states, inside the View, with a query.
You need to separate the view from the model.
Create a State model.
Use something like this in your controller:
$this->loadModel('State');
$states = $this->State->find('list'); // this will create a key => value array with the IDs and names
$this->set('states', $states);
In your view, use
<table width="380">
<tr>
<?php foreach ($states as $stateId => $stateName) {
<td class="table_txt"><a class="thickbox tn" href="demo.php?state_name=<?php echo $stateName?>&state_id=<?php echo $stateId?>&height=430&height=430&width=700&inlineId=myOnPageContent"><?php echo $stateName ?>></a></td>
<?php } ?>
</tr>
You might still need some changes, but this is the main idea.

Nested queries using wpdb

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.

How to display Serial Numbers with mysql query result?

I have a script that displays information of these fields- batchname, class, batchinstructor from the table "batch". But I want to display dynamically generated serial number on the left side when I show the data. For example:
Serial Number BatchName Class Batch Instructor
1. Solar Class Five John
2. Lunar Class six Bon Jovi
I have tried a lot but its not working. Would you please kindly help me to solve this? Please note that these serial number are not from database.
Here's my Controller:
<?php
class Batchlist extends CI_Controller{
function index(){
$this->load->library('pagination');
$config['base_url'] = base_url().'batchlist/index';
$config['total_rows'] = $this->db->get('batch')->num_rows();
$config['per_page'] = 20;
$config['num_links'] = 20;
$config['full_tag_open'] = '<div class="pagination" align="center">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$this->load->model('mod_batchlist');
$data['records']= $this->mod_batchlist->batch_list($config['per_page'],$this->uri->segment(3));
$data['main_content']='view_batchlist';
$this->load->view('includes/template',$data);
}
}
?>
Here's my Model:
function batch_list($perPage,$uri) {
$this->db->select('*');
$this->db->from('batch');
$this->db->join('teacher', 'batch.batchinstructor = teacher.teacherid');
$this->db->order_by('batchid','DESC');
$getData = $this->db->get('', $perPage, $uri);
if($getData->num_rows() > 0)
return $getData->result_array();
else
return null;
}
Here's my View
<h1>Batch List </h1>
<?php if(count($records) > 0) { ?>
<table id="table1" class="gtable sortable">
<thead>
<tr>
<th>Batch Name</th>
<th>Class</th>
<th>Batch Instructor</th>
<th>Edit/Delete</th>
</tr>
</thead>
<tbody>
<?php foreach ($records as $row){ ?>
<tr>
<td><?php echo $row['batchname'];?></td>
<td><?php echo $row['class'];?></td>
<td><?php echo $row['teachername'];?></td>
<td> <img src="<?php echo base_url(); ?>support/images/icons/edit.png" alt="Edit" />
<img src="<?php echo base_url(); ?>support/images/icons/cross.png" alt="Delete" />
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
<div class="tablefooter clearfix">
<div class="pagination">
<?php echo $this->pagination->create_links(); ?>
</div>
</div>
Maybe I misunderstood, but...what about a simple counter?? (after you ordered your records in SQL).
You need to pass to the view the number of items per page (in this snippet: $per_page), then you retrieve the current page from the URI ($this->uri->segment(n)).
At page 1, counter starts from (20*0)+1, i.e. 1. At page 2, starts from (1*20)+1 ie 21, at page 3 from (2*20)+1 ie 41 and so on...
<?php
$cur_page = $this->uri->segment(n) ? intval($this->uri->segment(n)) : 1;
$i = (($cur_page-1) * $per_page) +1;
foreach ($records as $row) :
?>
<tr>
<td><?php echo $i;?>.</td>
<td><?php echo $row['batchname'];?></td>
<td><?php echo $row['class'];?></td>
<td><?php echo $row['teachername'];?></td>
<td> <img src="<?php echo base_url(); ?>support/images/icons/edit.png" alt="Edit" /><img src="<?php echo base_url();?>support/images/icons/cross.png" alt="Delete" />
</td>
</tr>
<?php
++$i;
endforeach;
?>
You can place the counter wherever you want, I added a column for simplicity but if you want it somewhere else just place the counter there.
You said the serial numbers are not from the database. Where are they from then? If you want the database to generate them you can create a column named id and set it as the primary key and have it auto increment.