my code is below.it show the output in table format having no problems.
But when the particular tr gets long output from database then the table break.
Now how can i fixed the tr width strictly?let say i want each td cannot be more than 100px.
How can i do it?
Note: Here table means html table,not the database table.
if ($query->num_rows() > 0)
{
$output = '';
foreach ($query->result() as $function_info)
{
if ($description)
{
$output .= ''.$function_info->songName.'';
$output .= ''.$function_info->albumName.'';
$output .= ''.$function_info->artistName.'';
$output .= ''.$function_info->Code1.'';
$output .= ''.$function_info->Code2.'';
$output .= ''.$function_info->Code3.'';
$output .= ''.$function_info->Code4.'';
$output .= ''.$function_info->Code5.'';
}
else
{
$output .= ''.$function_info->songName.'';
}
}
$output .= '';
return $output;
}
else
{
return 'Result not found.';
}
thanks
riad
You can either do it in the HTML...
<td style="width: 100px">
Or you can try using wordwrap.
Related
I am trying to echo the data from the following table titled sectionamain, however I am only getting the data from the first row (TitleID = 1)
|TitleID | MainTitle |
|1 |This is a title |
|2 |This is another title |
The below is the PHP code i am using:
function get_practices_titles() {
global $connection;
$query = "SELECT * ";
$query .= "FROM sectionamain ";
$query .= "ORDER BY TitleID ASC";
$A_list = mysqli_query($connection, $query);
confirm_query($A_list);
return $A_list;
}
function practices_titles() {
$output = "<div class=\"container inner\">\n";
$output .= "<div class=\"wrap\">\n";
$A_set = get_practices_titles();
while ($list_A = mysqli_fetch_assoc($A_set)) {
$output .= "<h1 class\=showcontent\" id=";
$output .= htmlentities($list_A["TitleID"]);
$output .= ">";
$output .= htmlentities($list_A["MainTitle"]);
$output .= "</h1>";
mysqli_free_result($A_set);
$output .="</div>\n</div>";
return $output;
};
}
I thank you all in advance for your help.
I believe you need to move mysqli_free_result($A_set); to outside of your while loop.
You are getting rid of your results before you are done looping through them. Move it to after your while loop is finished.
From the docs: http://php.net/manual/en/mysqli-result.free.php
You should always free your result with mysqli_free_result(), when
your result object is not needed anymore.
But you still need it - you are freeing the memory after looping through only one result.
Remove the following 3 lines from the loop to the end of the function :
mysqli_free_result($A_set);
$output .="</div>\n</div>";
return $output;
so your function will be something like this:
function practices_titles() {
$output = "<div class=\"container inner\">\n";
$output .= "<div class=\"wrap\">\n";
$A_set = get_practices_titles();
while ($list_A = mysqli_fetch_assoc($A_set)) {
$output .= "<h1 class\=showcontent\" id=";
$output .= htmlentities($list_A["TitleID"]);
$output .= ">";
$output .= htmlentities($list_A["MainTitle"]);
$output .= "</h1>";
};
mysqli_free_result($A_set);
$output .="</div>\n</div>";
return $output;
}
I am successfully generating a ms-word document in php.
I am inserting in this document the html code I get from a rich text editor (tinyMCE). But I'm getting some extra unexpected caracters so I guess it is an encoding problem.
Here is the php code :
$content = $_GET['content'];
$filename = './cases/mydocument.htm';
$output = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'>";
$output .= "<head><title>Mon document</title>";
$output .= "<!--[if gte mso 9]>";
$output .= "<xml><w:WordDocument><w:View>Print</w:View><w:Zoom>100</w:Zoom><w:DoNotOptimizeForBrowser/></w:WordDocument></xml>";
$output .= "<![endif]-->";
$output .= "<link rel=File-List href=\"mydocument_files/filelist.xml\">";
$output .= "<style><!-- ";
$output .= "#page";
$output .= "{";
$output .= " size:21cm 29.7cmt; /* A4 */";
$output .= " margin:1cm 1cm 1cm 1cm; /* Margins: 2.5 cm on each side */";
$output .= " mso-page-orientation: portrait; ";
$output .= " mso-header: url(\"mydocument_files/headerfooter.htm\") h1;";
$output .= " mso-footer: url(\"mydocument_files/headerfooter.htm\") f1; ";
$output .= "}";
$output .= "#page Section1 { }";
$output .= "div.Section1 { page:Section1; }";
$output .= "p.MsoHeader, p.MsoFooter { border: none; }";
$output .= "--></style>";
$output .= "</head>";
$output .= "<body>";
$output .= "<div class=Section1>";
$output .= $content;
$output .= "</div>";
$output .= "</body>";
$output .= "</html>";
file_put_contents($filename, $output);
class mime10class
{
private $data;
const boundary='----=_NextPart_ERTUP.EFETZ.FTYIIBVZR.EYUUREZ';
function __construct() { $this->data="MIME-Version: 1.0\nContent-Type: multipart/related; boundary=\"".self::boundary."\"\n\n"; }
public function addFile($filepath,$contenttype,$data)
{
$this->data = $this->data.'--'.self::boundary."\nContent-Location: http://www.monsite.com/dev1/cases/".preg_replace('!\\\!', '/', $filepath)."\nContent-Transfer-Encoding: base64\nContent-Type: ".$contenttype."\n\n";
$this->data = $this->data.base64_encode($data)."\n\n";
}
public function getFile() { return $this->data.'--'.self::boundary.'--'; }
}
$doc = New mime10class();
$doc->addFile('mydocument.htm','text/html; charset="utf-8"',$output);
$output_encoded = $doc->getFile();
$filename = './cases/mydocument.doc';
file_put_contents($filename, $output_encoded);
For ex, my editor returns :
<p>test <em>italique</em></p>
I have checked and $content contains exactly this html part.
But when I perform the first file_put_content, I get this :
test  italique
I have tried to apply utf8_encode on $output before the file_put_contents, then I get it even worst:
test Â,Ã italique
My notepad++ is configured in utf8 without BOM
Any idea?
whenever using tinymce, try to apply,
stripslashes($_POST['content']);
I want to use the image reference I made in the database as a background: url. I've made the design already => http://i49.tinypic.com/30ihudz.png In my current code I use div style in which I retrieve the image, but that doesn´t show up no image. Could somebody please guide me? Thanks in advance.
public function displayProduct()
{
$product = $this->db->query("SELECT id, title, description, price, filename FROM trips ORDER BY id");
while ($row = $product->fetch_assoc())
{
$output .= '<div class="reisbox">';
$output .= '<div id="reis_insidebox1" style="background: url(\'img/content/'.$row['filename'].'\')" width="1000" height="500">';
$output .= '<div class="reis_textbox">';
$output .= '<h2>'.ucfirst($row['title']).'</h2>';
$output .= '<article>';
$output .= ucfirst($row['description']);
$output .= '</article>';
$output .= '</div>';
$output .= '<div class="rightboxx">';
$output .= '<div class="reis_price_box">';
$output .= '<div class="reis_price_box_text">';
$output .= '€'.$row['price'];
$output .= '</div>';
$output .= '<div class="more_box">';
$output .= '<p>Lees meer..</p>';
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
$output .='<br />';
$output .= '<div id="add">';
$output .='<p>Add to cart</p>';
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
}
return $output;
}
C:/ is not an URL since it has no protocol (like file: or http:). Make the path point towards a file inside the htdocs folder like
"http://localhost/images/"
or whatever.
I want to use the image reference I made in the database as a background: url. I've made the design already => [IMG]http://i49.tinypic.com/30ihudz.png[/IMG]. In my current code I use div style in which I retrieve the image, but that doesn´t show up no image. Could somebody please guide me? Thanks in advance.
public function displayProduct()
{
if($product = $this->db->query("SELECT id, title, description, price, filename FROM trips ORDER BY id"))
{
while ($row = $product->fetch_assoc())
{
$output .= '<div class="reisbox">';
$output .= '<div id="reis_insidebox1" style=" background: url("C:/xampp/htdocs/webshop/public/img/content/"'.$row['filename'].' ") width="1000" height="500">';
$output .= '<div class="reis_textbox">';
$output .= '<h2>'.ucfirst($row['title']).'</h2>';
$output .= '<article>';
$output .= ucfirst($row['description']);
$output .= '</article>';
$output .= '</div>';
$output .= '<div class="rightboxx">';
$output .= '<div class="reis_price_box">';
$output .= '<div class="reis_price_box_text">';
$output .= '€'.$row['price'];
$output .= '</div>';
$output .= '<div class="more_box">';
$output .= '<p>Lees meer..</p>';
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
$output .='<br />';
$output .= '<div id="add">';
$output .='<p>Add to cart</p>';
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
}
return $output;
}
}
If you really want to fetch the file from "C:/xampp/.../" you should add a file:/// infront but I guess you simply want to use a relative path, such as "img/content/andthefilenamefromdatabase.png"
And to continue, you are actually closing your style-tag with the " in your CSS background, you might want to use ' there or simply skip the string literal completely
With all this is mind, it could look like so:
$output .= '<div id="reis_insidebox1" style="background: url(\'img/content/'.$row['filename'].'\')" width="1000" height="500">';
Note that I am escaping the ' in the CSS here, using a backslash.
If so.... any idea how?
You might be interested in this post about adding sessions to the profiler Basically it works by creating a MY_Profiler.php file and copy and pasting this code:
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class MY_Profiler extends CI_Profiler {
/**
* Adds session data to the profiler
* Adds a table row for each item of session data with the key and value
* Shows both CI session data and custom session data
*/
function _compile_session() {
$output = "\n\n";
$output .= '<fieldset style="border:1px solid #009999;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
$output .= "\n";
$output .= '<legend style="color:#009999;"> '.'SESSION DATA'.' </legend>';
$output .= "\n";
if (!is_object($this->CI->session)) {
$output .= "<div style='color:#009999;font-weight:normal;padding:4px 0 4px 0'>".'No SESSION data exists'."</div>";
} else {
$output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' width='100%'>\n";
$sess = get_object_vars($this->CI->session);
foreach ($sess['userdata'] as $key => $val) {
if ( ! is_numeric($key)) {
$key = "'".$key."'";
}
$output .= "<tr><td width='50%' style='color:#000;background-color:#ddd;'>$_SESSION[".$key."] </td><td width='50%' style='color:#009999;font-weight:normal;background-color:#ddd;'>";
if (is_array($val)) {
$output .= "<pre>" . htmlspecialchars(stripslashes(print_r($val, true))) . "</pre>";
} else {
$output .= htmlspecialchars(stripslashes($val));
}
$output .= "</td></tr>\n";
}
$output .= "</table>\n";
}
$output .= "</fieldset>";
return $output;
}
function run() {
$output = "<div id='codeigniter_profiler' style='clear:both;background-color:#fff;padding:10px;'>";
$output .= $this->_compile_uri_string();
$output .= $this->_compile_controller_info();
$output .= $this->_compile_memory_usage();
$output .= $this->_compile_benchmarks();
$output .= $this->_compile_get();
$output .= $this->_compile_post();
$output .= $this->_compile_queries();
$output .= $this->_compile_session();
$output .= '</div>';
return $output;
}
}
Of course you can, just create a MY_profiler and add two methods: run() and _compile_session()
run() is the same as the parent just copy the code & add the _compile_session at the end and _compile_session could have the same code as _compile_post, just change $_POST to $_SESSION