How can I will use substr in detail field?
This is my code:
<td><?php echo $newses['details']; ?></td>
If $newses['details'] is type of string just use:
<?php echo substr($newses['details'], 0, 10); ?>
But if you want to do it in CakePHP way, use truncate() method of TextHelper.
you can use this
echo $this->Text->truncate(
$newses['details'],
10
);
Related
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!
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.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm recently started to learn php & mysql,
i wanna know what's wrong with this
function show(){
$query=mysql_query(" SELECT * FROM family ");
if (!$query) {
die("invalid query ".mysql_error());
}
while ($row=mysql_fetch_array($query)) {
echo "<tr>
line 24 ===><td><?php echo $row['id']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['lname']; ?></td>
</tr>";
}
}
as you can see i have a function for show my data fields,
and i have a table in another page that i want to by just including & calling the function,my variables appear in the table,but i keep getting this stupid error:
help plz
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\php\lib.php on line 24
for those who wanna suggest this below code:
echo "<tr>
<td>". $row['id'] ."</td>
<td>". $row['name'] ."</td>
<td>". $row['lname'] ."</td>
</tr>";
i did try this and it works but it wont show my date in the table rows
my purpose of this is that i want it to show my each data variables in a table row, any other good way you know?
Change <td><?php echo $row['id']; ?></td> to <td>".$row['id']."</td>
You're trying to bring php code inside a string, which won't work. Just concatinate the strings using the 'dot' operator. Take a look here for more information.
Edit as requested:
echo "<table>";
while ($row=mysql_fetch_array($query)) {
echo "<tr>
<td>".$row['id']."</td>
<td>".$row['name']."</td>
<td>".$row['lname']."</td>
</tr>";
}
echo "</table>";
Instead of echoing, you need to just close and reopen your PHP tags:
function show(){
$query=mysql_query(" SELECT * FROM family ");
if (!$query) {
die("invalid query ".mysql_error());
}
while ($row=mysql_fetch_array($query)) {
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['lname']; ?></td>
</tr>
<?php
}
}
Alternately, without opening and closing:
function show(){
$query=mysql_query(" SELECT * FROM family ");
if (!$query) {
die("invalid query ".mysql_error());
}
while ($row=mysql_fetch_array($query)) {
echo "<tr>
<td>". $row['id'] ."</td>
<td>". $row['name'] ."</td>
<td>". $row['lname'] ."</td>
</tr>";
}
}
try this
function show()
{
$query = mysql_query("SELECT * FROM `family`");
//check if query failed
if (!$query) {
die("invalid query ".mysql_error());
}
//if there are more than 0 rows in table, we create the table
if (mysql_num_rows($query) > 0)
{
echo "<table>";
//loop thru array and create table rows
while ($row = mysql_fetch_array($query))
{
echo "<tr>
<td>". $row['id'] ."</td>
<td>". $row['name'] ."</td>
<td>". $row['lname'] ."</td>
</tr>";
}
echo "</table>";
}
else //no rows, we display an error
{
echo 'Table is empty';
}
}
also use mysqli_* because mysql_* is depreciated
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.