Displaying the text in the multiple lines when retrieving from database - php

Hi
I have a table in which my row contains the text which i retrieve from the database.But i have a small width of row and the data i retrieve is large.And the text exceeds the width of my row so i want to break the data i retrieve into multi lines inside the table row.How can i do it.
My code is here:
$list = $mfidao1->fetchMfi($_GET['id']);
//print_r($list);
//die;
if(!empty($list))
{
foreach($list as $menu)
{
?>
<tr style="border:none; background-color:#FBFBFB;" >
<td class="topv">Social Mission</td>
<td class="topm" ><div class="txt"><?php echo $menu->mfi_1_a;?></div></td>
</tr>
<tr bgcolor="#E8E8E8">
<td class="topv">Address</td>
<td class="topm"><?php echo $menu->mfi_ii_c;?></td>
</tr>
<tr bgcolor="#FBFBFB">
<td class="topv">Phone</td>
<td class="topm"><?php echo $menu->mfi_ii_e;?></td>
</tr>
<tr bgcolor="#E8E8E8">
<td class="topv">Email</td>
<td class="topm"><?php echo $menu->mfi_ii_d;?></td>
</tr>
<tr bgcolor="#FBFBFB">
<td class="topv">Year Established</td>
<td class="topm"><?php echo $menu->mfi_i_c;?></td>
</tr>
<tr bgcolor="#E8E8E8">
<td class="topv">Current Legal Status</td>
<td class="topm"><?php echo $menu->mfi_i_d;?></td>
</tr>
<tr bgcolor="#FBFBFB">
<td class="topv">Respondent</td>
<td class="topm"><?php echo $menu->mfi_ii_a;?></td>
</tr>
<?php
}
}
?>
</table>

Set width of <td>. I think this is the best way to do this rather than word_wrap().

In your css for the table, use "table-layout:fixed" - This fixes the td elements width according to the way you want.
" word-wrap: break-word; " - this breaks the text in it so that it doesnt go beyond the boundary of the box.

You need to wrap the text in your td tags. Here is a link to a similar question

You could use the function wordwrap().
It wraps a string to a given number of characters using a string break character.

you can either use the php function
php wordwrap
or styling the td with css so that it uses the word-wrap attribute
css wordwrap

Not sure if this is what you want, but sound like you could use chunk_split()

Related

How to get strings with Regex

I want to get strings between td's but one of the td has not close tag. How can I get from this tag with other string.
<tr>
<td class="exclass">Text 0
<td class="exclass">Text 1</td>
<td class="exclass">Text 2</td>
<td class="exclass3" >Text</td >
<td class="exclass"> Text </td>
<td class="exclass3">Text</td>
<td class="exclass">Text</td>
<td class="exclass">Text</td><td class="exclass">Text</td>
<td class="exclass2">Text</td>
<td class="exclass">Text</td>
<td class="exclass" width="20"><img src="exampleSrc"></td>
</tr>
As you can see below code, I want to get Text 0 and the other strings with PHP.
So far, I tried to:
<td.+?>([\w\W]*?)<\/td.+?|<td
I assume because one of the td doesn't have close tag, that's why you can't use the DOM parser.
Here is my regex solution
(?<=>)([\s\w\n]+)(?=<)
https://regex101.com/r/BRaJAu/1

mixing html code with php code

I am trying to use tcpdf library to generate pdf. I have a php file which contains variables like name,company name etc. But for displaying the products I am passing the array to php. Now I want to display each element of array in a table row for that I have to write the php code but somehow I am having problem mixing PHP code with html code.Here is the part whihch contains the problem
$html .= '<br><br>
<table border="1" cellpadding="5">
<tr>
<td colspan="3">Invoice # {invoice_ref_id}</td>
</tr>
<tr>
<td><b>Product</b></td>
<td><b>Quantity</b></td>
<td align="right"><b>Amount (Rs.)</b></td>
</tr>'.
foreach($item as products): .' //This part contains error
<tr>
<td>'echo products['item']'</td>
<td>'echo products['quantity']'</td>
<td align="right">75</td>
</tr>
<tr>
<td colspan="3" align="right"><b>Total: 375</b></td>
</tr>'
endforeach;
'</table>';
$html .= '<br><br>Some more text can come here...';
Instead of concatenating your HTML in a string that you will then need to echo, I would go to something like this :
<br><br>
<table border="1" cellpadding="5">
<tr>
<td colspan="3">Invoice # {invoice_ref_id}</td>
</tr>
<tr>
<td><b>Product</b></td>
<td><b>Quantity</b></td>
<td align="right"><b>Amount (Rs.)</b></td>
</tr>
<?php foreach($item as products){ ?>
<tr>
<td><?php echo products['item'] ?></td>
<td><?php echo products['quantity'] ?></td>
<td align="right">75</td>
</tr>
<tr>
<td colspan="3" align="right"><b>Total: 375</b></td>
</tr>
<?php> } //ending the foreach ?>
</table>
<br><br>Some more text can come here...
Notice how even here HTML code is still correctly highlighted? It will probably be the same in your editor of choice. I find it much more readable, and you even avoid possible character escaping issues.
NOTE : I didn't fix your HTML, but there are several bad practices in it regarding semantics or even use of obsolete/deprecated tags. Here are a few:
Don't use anything changing layout in your HTML, this is what CSS are for. For example, don't use border or cellpadding attributes on your table, use table {border: 1px solid #ccc;} (you can of course change color, that's an example) and table td {padding: 5px;} instead.
Semantic best practices also imply not using <br> tag. Better define top or bottom margins to put some space between elements. (I must admit that's probably the only example where I value ease over semantic and sometimes use it myself though)
<b> tag should be use only in very specific cases, cfr this article. In this specific case you can achieve the same effect (bold text) by using font-weight: bold on the desired cells, either by giving them a specific CSS class, either by targetting them with a CSS selector like for example : tr td:nth-child(3) {font-weight: bold;}}
similarily, don't use align attribute, same thing, target the desired cell and use CSS property text-align: right; instead.
You can't continue the html with a concatenation straight after the foreach. You have to do $html .= again.
This
</tr>'.
foreach($item as products): .' //This part contains error
<tr>
should be this
</tr>';
foreach($item as products): $html .= ' //This part contains error
<tr>
The same goes at the end of the foreach:
</tr>';
endforeach;
$html .= '</table>';
You are doing it wrong way. This should work -
$html .= '<br><br>
<table border="1" cellpadding="5">
<tr>
<td colspan="3">Invoice # {invoice_ref_id}</td>
</tr>
<tr>
<td><b>Product</b></td>
<td><b>Quantity</b></td>
<td align="right"><b>Amount (Rs.)</b></td>
</tr>';
foreach($item as products) { //This part contains error
$html .= '<tr>
<td>'. products['item']. '</td>
<td>'. products['quantity']. '</td>
<td align="right">75</td>
........ ';
}
$html .= '</table>';
$html .= '<br><br>Some more text can come here...';
thie right way of doing something like this
$html .= '<br><br>
<table border="1" cellpadding="5">
<tr>
<td colspan="3">Invoice # {invoice_ref_id}</td>
</tr>
<tr>
<td><b>Product</b></td>
<td><b>Quantity</b></td>
<td align="right"><b>Amount (Rs.)</b></td>
</tr>';
foreach($item as products):
$html .=' //This part contains error
<tr>
<td>'echo products['item']'</td>
<td>'echo products['quantity']'</td>
<td align="right">75</td>
</tr>
<tr>
<td colspan="3" align="right"><b>Total: 375</b></td>
</tr>';
endforeach;
$html .= '</table>';
$html .= '<br><br>Some more text can come here...';

Jquery change table cell value if other cell contains word

I have a basic table and need to change a word if one of the other cells in that row contains a word.
<table>
<tr class="veh-row">
<td class="vehicle_desc">RED CAR</td>
<td>4000 miles</td>
<td class="veh-trans">Manual</td>
<td>Petrol</td>
</tr>
<tr class="veh-row">
<td class="vehicle_desc">RED CAR</td>
<td>4000 miles</td>
<td class="veh-trans">Manual</td>
<td>Petrol</td>
</tr>
<tr class="veh-row">
<td class="vehicle_desc">RED CAR AUTO</td>
<td>4000 miles</td>
<td class="veh-trans">Manual</td>
<td>Petrol</td>
</tr>
</table>
So I need if td.vehicle_desc contains the word AUTO then Manual will change to Automatic in td.veh-trans. How can I do this and only effect that row and not all other rows?
You can use :contains
$('td.vehicle_desc:contains(AUTO)').siblings('.veh-trans').text('Automatic')

Layout problems (php,html)

I made some images which i need, currently i have :
$output .= "
<tr>
<td align='center'><b>{$name}</b></td> </tr>
<tr>
<td align='center'><img src='$avatar'/></td> </tr>
<td align='center'><b>Points</b>: {$points}</td> </tr>
<tr>
<td align='center'><b>Status</b>:<b><font color='green'> {$misc['text_status']}</font></b></td> </tr>
<tr>
<td align='center'><a href='".$link."'><font color='red'><b>See more statistics</b></font></a><hr></td></tr>
";
with script i get this(ie image) http://img717.imageshack.us/img717/7885/thisdn.png .
Now i need to output something like this http://img703.imageshack.us/img703/171/thatq.png (ie image) without mysql. May i have some examples of yours?
move <tr> before your for loop and </tr> after you for loop
or better one, place individual tables with float:left for each member
You could try to wrap every profile information (photo, points etc) in a div and not use tables at all. Then float these div-s to the right or left. Note that every div must have the same class.

Is there a way to sync column widths in an html table?

If I have these two tables:
<table>
<tr>
<td>Small Length Content</td>
</tr>
</table>
<table>
<tr>
<td>Dynamic Content Goes Here And It's Longer Than The TD Above</td>
</tr>
</table>
How can I make it so that the two columns have the same width?
I can't combine the tables so thats not an option. I also can't use fixed widths since its dynamic content. Any ideas? Perhaps something in javascript to have the top columns match the width of the lower table? I'm no js expert so I have no idea if thats possible or how to do it. Php is an option on the table as well if theres a way to use that to solve it as well.
Are you able to define css for this dynamic content? Suppose these tables were nested inside a div like so:
<div id="content">
<table>
<tr>
<td>Small Length Content</td>
</tr>
</table>
<table>
<tr>
<td>Dynamic Content Goes Here And It's Longer Than The TD Above</td>
</tr>
</table>
</div>
I would write some css like this:
#content table td { width: 80%; }
I would use a percentage-based width on the 'flowing' column, and buffer it with fixed-width columns if necessary. ie.:
<table style="width: 100%;">
<tr>
<td style="width: 80%;">Small Length Content</td>
</tr>
</table>
<table style="width: 100%;">
<tr>
<td style="width: 80%;">Dynamic Content Goes Here And It's Longer Than The TD Above</td>
</tr>
</table>
You can use CSS to accomplish this. You will have to have the longer content wrap.
td{
width:80%;
}
Try
<table>
<tr>
<td style="width:200px">Small Length Content</td>
</tr>
</table>
<table>
<tr>
<td>Dynamic Content Goes Here And It's Longer Than The TD Above</td>
</tr>
</table>
or add a class to name to the td element and define the style somewhere else like an external file or in header style

Categories