Text misalignment in HTML table output by PHP and displayed in Browser - php

function my_fav_quote_show_optin_form() {
if (!empty($_POST['my_fav_quote_email'])) {
my_fav_quote_opt_in();
}
$out2 = '';
$out = '<form action="" method="post" id="requestQuote">';
$out .= '<table style="padding="0px" width="40px">';
$out .= '<tr><td>Name:*</td><td><input type="text" name="my_fav_quote_name" id="my_fav_quote_name"/></td></tr>';
$out .= '<tr><td colspan=1></td></tr>';
$out .= '<tr><td>Email:*</td><td><input type="text" name="my_fav_quote_email" id="my_fav_quote_email"/></td></tr>';
$out .= '<tr><td colspan=2></td></tr>';
$out .= '<tr><td>Message:</td><td><textarea cols=20 rows=5 wrap="hard" name="my_fav_quote_message" id="my_fav_quote_message"></textarea></td></tr>';
$out .= '<tr><td colspan=2></td></tr>';
$out .='<tr><td colspan="2">';
if ( function_exists( 'my_fav_quote_display' ) ){
$out .= my_fav_quote_display();
}
the thing is that this is a plugin of wordpress which i am modifying for my need their is misalignment of the word "message" i.e is it is appearing too low with respect to text areabox and also cols and row syntax are not working have tried applying style top ,bottom and also tried margin but the message word is not moving from the place .please click on add to quote for seeing the widget where the problem is a link

<td style="vertical-align: top;">Message</td>

Related

How to place foreach loop inside a <td> tag [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
How do you place a foreach loop inside a tag?
here's the code:
foreach( $designer_posts as $designer_post ) {
$tags = get_the_tags($designer_post->ID);
$imageThumb = get_the_post_thumbnail( $designer_post->ID, "thumbnail" );
$html .= '<tr>';
$html .= '<th scope="row">View</th>';
$html .= '<td><p>'.$designer_post->post_title.'</p></td>';
$html .= '<td>'FOREACH LOOP HERE!!!'</td>';
$html .= '<td>'.$imageThumb.'</td>';
$html .= '</tr>';
}
I keep getting an error. Could you help me with the PROPER syntax?
foreach( $designer_posts as $designer_post ) {
$tags = get_the_tags($designer_post->ID);
$imageThumb = get_the_post_thumbnail( $designer_post->ID, "thumbnail" );
$html .= '<tr>';
$html .= '<th scope="row">View</th>';
$html .= '<td><p>'.$designer_post->post_title.'</p></td>';
$html .= '<td>';
foreach() {
$html .= 'The rest of the HTML code';
}
$html .= '</td>';
$html .= '<td>'.$imageThumb.'</td>';
$html .= '</tr>';
}
I think you want to do this :
foreach( $designer_posts as $designer_post ) {
$tags = get_the_tags($designer_post->ID);
$imageThumb = get_the_post_thumbnail( $designer_post->ID, "thumbnail" );
$html .= '<tr>';
$html .= '<th scope="row">View</th>';
$html .= '<td><p>'.$designer_post->post_title.'</p></td>';
$html .= '<td>';
foreach($designer_post as $test) {
$html .= 'what you want fraté';
}
$html .= '</td>';
$html .= '<td>'.$imageThumb.'</td>';
$html .= '</tr>';
}
<?php
foreach( $designer_posts as $designer_post ) {
$tags = get_the_tags($designer_post->ID);
$imageThumb = get_the_post_thumbnail($designer_post->ID,"thumbnail");
?>
<tr>
<th scope="row">View</th>
<td><p> <?php print $designer_post->post_title; ?></p></td>
<td>
<?php foreach($array_data as $data) {
print $data;
} ?>
</td>
<td> <?php print $imageThumb; ?></td>
</tr>
<?php } ?>

PHP Foreach with two queries

Ok i have one query in codeigniter where i select all data
function get_story()
{
$this->db->select('*');
$this->db->from('stories');
$query = $this->db->get();
return $query;
}
then i make another query with data from another table
function get_stories()
{
$this->db->from('stories');
$this->db->join('stories_to_categories', 'stories.id = stories_to_categories.story');
$this->db->join('categories', 'stories_to_categories.category = categories.id');
$query = $this->db->get();
return $query;
}
Then i am trying to create table with data from two queries. Making one query with another JOIN its not option. I created foreach
foreach($story->result() as $row)
{
echo '<tr>
<td>'.$row->title_english.'</td>
<td>'?????????????????????????????????????????????????????</td>
<td align="center">
<img src="'.site_url('admin/images/icons/pencil.png').'" class="tooltip" title="'.lang('edit').'" />
<img src="'.site_url('admin/images/icons/minus-circle.png').'" class="tooltip" title="'.lang('delete').'" />
</td>
</tr>
';
echo '<div id="delete_'.$row->id.'" style="display: none;">
<h1>'.lang('client_delete').'</h1><br />
'.lang('story_confirm_delete').'
<br /><br />
<span><span>'.lang('yes').'</span></span>
<span><span>'.lang('no').'</span></span>
<br /><br />
</div>';
}
In td tag where is ???? i need results from second query, i have no idea how to insert data from second query into foreach??? Does somebody have idea, helpe is really needed?
If I understand your question, I think you just need to use string concatenation. Prepare your HTML output into a variable and print it later.
$html = '<table>';
foreach($story->result() as $row)
{
$html .= '<tr>';
$html .= '<td>'.$row->title_english.'</td>';
$html .= '<td>';
foreach($stories->result() as $row2){
// display your second query result here
$html .= '?????????????????????????????????????????????????????';
}
$html .= '</td>';
$html .= '<td align="center">';
$html .= '<img src="'.site_url('admin/images/icons/pencil.png').'" class="tooltip" title="'.lang('edit').'" />';
$html .= '<img src="'.site_url('admin/images/icons/minus-circle.png').'" class="tooltip" title="'.lang('delete').'" />';
$html .= '</td>';
$html .= '</tr>';
$html .= '<div id="delete_'.$row->id.'" style="display: none;">';
$html .= '<h1>'.lang('client_delete').'</h1><br />';
$html .= lang('story_confirm_delete');
$html .= '<br /><br />';
$html .= '<span><span>'.lang('yes').'</span></span>';
$html .= '<span><span>'.lang('no').'</span></span>';
$html .= '<br /><br />';
$html .= '</div>';
}
$html .= '</table>';
echo $html;

Broken HTML-Mail because of space character

Here is a small snippet of the PHP-Code I use to create a HTML e-mail:
$tmpl = '<table border="0" width="100%";><tr><td>%title%</td></tr><tr><td>%text%</td></tr></table>';
$html = '<table border="0" width="100%";>';
$html .= '<td width="20%" style="padding:0;">';
if(isset($var)) {
$html .= 'Value: '.$object->val;
}
$html .= '</td>';
$html .= '</table>';
$tmpl = str_replace('%text%', $html, $tmpl);
$mail->setBody( $tmpl );
$mail->send();
Sometimes the mail in the HTML view when viewed inside an email program is broken because there is a space character inside an opening TD-Element. Like this:
< td width="20%" style="padding:0;">
Where is this space character coming from?
Had the same issue with php mail() function, my html styling was broken by seemingly random spaces. Using wordwrap() on the message before sending it with mail sorted out the problem.
$message = wordwrap($message, 70);
mail("person#example.com","Some subject",$message);
www.w3schools.com explanation, example
See this line here?
$html = '<table border="0" width="100%";>';
after width="100%" you do not need this symbol -> ;
Try removing it.
Markup has errors
$tmpl = '<table border="0" width="100%";><tr><td>%title%</td></tr><tr><td>%text%</td></tr></table>';
Notice the ; in border="0" width="100%";>
You're not concatenating $html
The following line overwrite the table built up earlier
$html = '</table>';
You need to change that to;
$html .= '</table>';
Suggested actions
I would suggest echoing the body of the mail, and validating it with w3.
Have a read...
Concatenating
Validate your markup
<?php
$tmpl = '
<table border="0" width="100%">
<tr>
<td>%title%</td>
</tr><tr>
<td>%text%</td>
</tr>
</table>';
$html = '<table border="0" width="100%">';
$html .= '<td width="20%" style="padding:0;">';
if(isset($var)) {
$html .= 'Value: '.$object->val;
}
$html .= '</td>';
$html .= '</table>';
//Debug:
// echo $html;
$tmpl = str_replace('%text%', $html, $tmpl);
$mail->setBody( $tmpl );
$mail->send();

Get individual form collection elements ZF2

I need to use collections to make dynamic inputs, but needed to pull out the individual elements to integrate them into a Bootstrap layout.
Unfortunately I can't find any documented way of doing this.
Could someone help-me?
Here is my form: http://pastebin.com/JGy7JEJk Fieldset used in form:
http://pastebin.com/VBbG1yyb
Form HTML: http://pastebin.com/HHaZZKsB
Form View Helper: http://pastebin.com/x7B9aPWG
You can see this in action http://protesto21.com.br/cadastro/encargo-vigencia/atualizar/2/
User admin, password p21
Thanks for all and sorry for my english
Problem solved
public function renderCollection($element)
{
$return = '';
if (count($element->getMessages()) > 0) {
$return .= '<div class="form-group has-error">';
} else {
$return .= '<div class="form-group">';
}
foreach ($element->getIterator() as $field) {
$label = ($this->isView) ? '<strong>' . $element->getLabel() . '</strong>' : $element->getLabel();
$return .= '<label class="col-md-3 control-label">' . $label . '</label>';
$return .= '<div class="col-md-8" style="margin-bottom: 20px;">';
foreach ($field->getElements() as $inputs) {
$return .= '<div style="float: left; margin-right: 20px;">';
$return .= $inputs->getLabel();
$return .= $this->renderInput($inputs);
$return .= '<div style="min-width: 265px;">';
foreach ($inputs->getMessages() as $mensagem) {
$return .= "<span class='help-block'>" . $mensagem . "</span>";
}
$return .= '</div>';
$return .= '</div>';
}
$return .= '</div>';
$element->setLabel('');
}
$return .= '</div>';
return $return;
}

Table max 3 <td> loop in other tr

How to make it like only 3 offers in row NOW I have one row and all offer is in one line I just want to to show max 3 td in tr and loop.
if(count($offer_list['item']) > 0)
{
$main_content .= '<table cellspacing="2" cellpadding="2" width=30>';
foreach($offer_list['item'] as $item)
{
$main_content .= '<td class="shop">
<a class="shop" style="display: block;" href="/shop/item/id/'.$item['id'].'">
<center><img src="item_images/'.$item['item_id'].'.gif"><br><font color="white"><b>'.$item['name'].'</font></b><font color="red"> <b> '.$item['points'].' points</font></b>';
if(!$logged)
{
$main_content .= '<p><b>[Login to buy]</b>';
}
else
{
$main_content .= '<br><b><font size=1 color="white">Your points balance is: '.$user_premium_points;
$main_content .= '<br><font color="white"> <fieldset class="shop"><legend>DESCRIPTION</legend>'.$item['description'].'</fieldset></font><br><font color="white"><b> [Click to buy] </b></font></form> </a></center></td>';
}
$main_content .= '';
}
$main_content .= '</tr></table>';
}
$row_count = 1;
$main_content .= '<table cellspacing="2" cellpadding="2" width=30>';
foreach($offer_list['item'] as $item) {
// Check, if we are at position "1". If so, start new row
if ($row_count === 1) { $main_content .= '<tr>'; }
$main_content .= '<td class="shop"><a class="shop" style="display: block;" href="/shop/item/id/'.$item['id'].'">
<center><img src="item_images/'.$item['item_id'].'.gif"><br><font color="white"><b>'.$item['name'].'</font></b><font color="red"> <b> '.$item['points'].' points</font></b>';
if(!$logged) {
$main_content .= '<p><b>[Login to buy]</b>';
}
else {
$main_content .= '<br><b><font size=1 color="white">Your points balance is: '.$user_premium_points;
$main_content .= '<br><font color="white"> <fieldset class="shop"><legend>DESCRIPTION</legend>'.$item['description'].'</fieldset></font><br><font color="white"><b> [Click to buy] </b></font></form> </a></center></td>';
}
// Check, if we we are at position "3". If so, end row. (set position back to 1)
// Otherwise increase position with one level.
if ($row_count === 3) {
$row_count = 1;
$main_content .= '</tr>';
}
else {
$row_count++;
}
} // end foreach
// This is code for filling the "blank" table cells, if you don't have exactly some item count / 3 = 0
if ($row_count !== 3) {
for ($i=0; $i<=(3-$row_count); $i++) {
$main_content .= '<td> </td>';
}
$main_content .= '</tr>';
}
$main_content .= '</table>';
PS: <center> is deprecated or more to say not valid HTML anymore.

Categories