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;
}
Related
I need a little help on getting a rule in to output something else if a certain variable is called.
To break it down I have the following listed:
private $zebra_moto_symbol = array
( "ES400", "MC9500", "MC9200", "MC9190", "MC9094", "MC9090", "MC9097", "MC9060",;
and using this code it pulls the models into the page in a list:
public function manufacturer_models_list() {
$manu_name = $this->manufacturer_name;
$output = "<ul>";
sort($this->$manu_name);
foreach($this->$manu_name as $model) {
$output .= "<li>" . "" . $model . "</li>";
}
$output .= "</ul>";
$output .= "<p class=\"clear\"></p>";
$output .= "Arrange A Repair";
return $output;
}
On all but two of these, I need it display the repair.php link, however on two these need to be different. What would I need to input to make this happen?
Thanks in advance (sorry, this one stumped me).
:)
You can use a switch statement for this.
<?
public function manufacturer_models_list() {
$manu_name = $this->manufacturer_name;
$output = "<ul>";
sort($this->$manu_name);
foreach ($this->$manu_name as $model) {
switch($model) {
//Output NOT repair.php on this list of strings
case "ES400":
case "MC9500":
$output .= "<li>DIFFERENT OUTPUT</a></li>";
break;
//default is the action that happens if none of the previous conditions are met
default:
$output .= "<li>" . "" . $model . "</li>";
break;
}
}
$output .= "</ul>";
$output .= "<p class=\"clear\"></p>";
$output .= "Arrange A Repair";
return $output;
}
?>
Read more about Switch Statements
If I understood correctly, what you want is to have a different output on certain values.
I would think about have another array to hold the values that you want a different output and you can do something like this:
$different_output_array = ['ES400', 'MC9500']; # you can add new elements any time
and just modify your function to something like this:
public function manufacturer_models_list() {
$manu_name = $this->manufacturer_name;
$output = "<ul>";
sort($this->$manu_name);
foreach($this->$manu_name as $model) {
if(in_array($model,$different_output_array))
{
$output .= "<li>" . "" . $model . "</li>";
}
else
{
$output .= "<li>" . "" . $model . "</li>";
}
}
$output .= "</ul>";
$output .= "<p class=\"clear\"></p>";
$output .= "Arrange A Repair";
return $output;
}
Hope this can help.
I'm pretty new to php and I can't figure out why 'testimonial_text' is not being wrapped within the 'testimonial-text' class. For some reason, it's outputting 3 elements and one of them is "testimonial text" but it's not within the "testimonial-text". "testimonial_author" is being correctly wrapped in "testimonial-author". Any ideas?
<?php
$rows = get_field('testimonials');
if($rows) {
foreach($rows as $row) {
$output = "<div class = 'testimonial-container'>";
$output .= "<p class = 'testimonial-text'>".$row['testimonial_text'] . "</p>";
$output .= "<p class = 'testimonial-author'>".$row['testimonial_author'] . "</p>";
$output .= "</div>";
echo $output;
}
}
?>
Following the image showing the contents of $rows in the comments it looks like the data you are returning has extra code and/or quotes in it. So I would recommend doing something like..
if($rows) {
$output = '';
foreach($rows as $row) {
$output .= "<div class = 'testimonial-container'>";
$output .= "<p class = 'testimonial-text'>" . strip_tags ($row['testimonial_text']) . "</p>";
$output .= "<p class = 'testimonial-author'>" . strip_tags ($row['testimonial_author']) . "</p>";
$output .= "</div>";
}
echo $output;
}
To remove any stray code that is getting output.
Worth noting #Naumov said to use strip_tags as well :)
I have created a plugin and have done so many times but for some reason I can not seem to get a navigation to the plugin settings page on the admin menu.
The following code I have used is:
// create custom plugin settings menu
add_action('admin_menu', 'uubba_categories_addmenus');
function uubba_categories_addmenus() {
//create new top-level menu
add_menu_page('Check My Stats', 'CMS Page', 'manage_options', 'uubbacmspage', 'uubba_cms_players_page', '', 6);
}
I have also created a settings page but for some reason that is not echo'ing anything what so ever either. The code is as follows:
function uubba_cms_players_page(){
global $wpdb;
//get the players information needed
$getinfo = $wpdb->get_results("SELECT username FROM uubba_userstats");
$output = '<style>';
$output .= '.uubbahr{margin:25px 0px;}';
$output .= '.uubba-button-green,.uubba-button-green:visited{padding:8px 14px;background-color:#8FE485;color:white;}';
$output .= '.uubba-button-green:hover{background-color:#79DC6E;color:white;}';
$output .= '.uubba-button-red,.uubba-button-red:visited{padding:8px 14px;background-color:#F56A6A;color:white;}';
$output .= '.uubba-button-red:hover{background-color:#E34747;color:white;}';
$output .= '<style>';
$output .= '<div class="wrap">';
$output .= '<h1>Check My Stats Players</h1>';
$output .= '<hr class="uubbahr">';
$output .= '<table>';
$output .= '<tr>';
$output .= '<th scope="col"><h5 class="font12">Users Name</h5></th>';
$output .= '<th scope="col"><h5 class="font12">Actions</h5></th>';
$output .= '</tr>';
foreach($getinfo as $gi){
$output .= '<tr>';
$output .= '<td><h3>'.$gi->username.'</h3></td>';
$output .= '<td>View Statistics Delete User</td>';
$output .= '</tr>';
}
$output .= '</table>';
$output .= '</div>';
echo $output;
}
I have no idea why this would not work, I have used this method a lot in the past and for some reason it just does not work on this plugin.
If anyone could shed some light on it, I would be most appreciated indeed :)
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
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.