I want to display the student names from db and two buttons for each students.
In my code i am using ajax function.
controller
function get_sib_filter()
{
$list_id= $this->input->post('id2');
if(($list_id)==1)
{
$filtered_students = $this->home_model->filter_by_sibling();
$new_string = "";
foreach($filtered_students->result() as $detail)
{
$new_string.=$detail->applicant_first_name;
$new_string=$new_string.'Selected For Interview';
$new_string=$new_string.'Rejected</br>';
}
echo $new_string;
}
}
But i got the last name only(last name and two buttons)
I want list all name and all name having two buttons
Plzz give suggetions..
Like mentioned in the comments above, here are the issues found:
you never defined $new_string
you are overwriting $new_string
you are not concatenating the base_url the right way
Also, since you are using base_url you should be loading the URL helper in your controller ($this->load->helper('url')) or autoloading it in autoload.php
Try this:
$students = $filtered_students->result();
$string = "";
foreach ($students as $student) {
$string .= $student->applicant_first_name . " ";;
$string .= "<a href='" . base_url() . "home/change_filter_status_green/$student->applicant_id' class='btn green button_style' title='Filter'>Selected For Interview</a> | ";
$string .= "<a href='" . base_url() . "home/change_filter_status_red/$student->applicant_id'' class='btn red but_style' title='Rejected'>Rejected</a><br/>";
}
echo $string;
You are overwriting the string here. Please make some changes as shown below.
$new_string = ""; // Define $new_string..
foreach($filtered_students->result() as $detail){
$new_string.=$detail->applicant_first_name;
$new_string.='Selected For Interview';
$new_string.='Rejected<br />';
}
And also make sure what are you getting from this variable: $filtered_students.
You can check it by print_r($filtered_students);
Try the following code:
function get_sib_filter()
{
$list_id= $this->input->post('id2');
if($list_id == 1)
{
$filtered_students = $this->home_model->filter_by_sibling();
$new_string = "";
$count = 0;
foreach($filtered_students->result() as $detail)
{
if($count == 0){
$new_string = "<a href='".base_url('home/change_filter_status_green/').$detail->applicant_id."' class='btn green button_style' title='Filter'>Selected For Interview</a><a href='".base_url('home/change_filter_status_red').$detail->applicant_id."' class='btn red but_style title='Rejected'>Rejected</a>";
$count++;
}else{
$new_string .= $new_string."<a href='".base_url('home/change_filter_status_green/').$detail->applicant_id."' class='btn green button_style' title='Filter'>Selected For Interview</a><a href='".base_url('home/change_filter_status_red').$detail->applicant_id."' class='btn red but_style title='Rejected'>Rejected</a>";
}
}
echo $new_string;
}
}
change your model like this:
function filter_by_sibling()
{
$this->db->select('applicant_id,applicant_first_name');
$this->db->from('student_application');
$this->db->order_by('sib_count','desc');
$result = $this->db->get()->result_array();
return $result;
}
Modify your controller function like this:
function get_sib_filter()
{
$list_id= $this->input->post('id2');
if(($list_id)==1)
{
$filtered_students = $this->home_model->filter_by_sibling();
$new_string = "";
foreach($filtered_students as $detail)
{
$new_string .=$detail['applicant_first_name'];
$new_string .='Selected For Interview';
$new_string .='Rejected<br />';
}
echo $new_string;
}
}
Related
I am using this code for explode and show GET variables. But I would like remove current query in the link:
My explode code:
$k = $_GET['sef'];
$s_explode = explode("-",$k);
foreach($s_explode as $q) {
if($q==$s_explode[0]) {
echo '<a class="active" href="/category/'.$q.'">'.$s_explode[0].' <span class="dismiss">×</span></a>';
} else {
echo ''.$q.' <span class="dismiss">×</span>';
}
}
If I using GET
website.com/?sef=game-book-video
Print is:
<a class="active" href="/category/game">game</a>
book
video
I would like if I using GET
website.com/?sef=game-book-video
<a class="active" href="/category/book-video">game</a>
book
video
I hope I can explain good sorry for my bad English.
Your code would be like this:
$k = $_GET['sef'];
$s_explode = explode("-", $k);
//game-book-video
foreach($s_explode as $i => $q) {
$parts = $s_explode;
if(($key = array_search($q, $parts)) !== false) {
unset($parts[$key]);
}
$class = ($i == 0 ? "class='active'" : '');
echo '<a ' . $class . ' href="/category/'.implode('-', $parts).'">'.$q.' <span class="dismiss">×</span></a>';
}
I have this little function running at my wordpress site. But I need to add a bit of data to it. Hope I can get help.
Function array_to_comma($data)
{
if (is_array($data) and count($data) > 0)
{
$data = implode(', ', $data);
return $data;
}
}
Which outputs this:
Some Data, Some Data, Some Data
But I want to add some html code to it, a span, but I do not know how. So that it would appear like this in the source code of a rendered page. I see that it already adds a comma, but I cannot figure out to get to add more data then just the comma to appear at start and end. like this:
<span special="codes">Some Data</span>, <span special="codes">Some Data</span>, <span special="codes">Some Data</span>
Thank you in anticipation of a great help!. I am a php noob :)
EDIT: I have successfully used this code below. from the answer from elclanrs.
function array_to_comma($data)
{
if (is_array($data) and count($data) > 0) {
$data = '<span special="code">'
. implode('</span>,<span special="code">', $data)
.'</span>';
return $data;
}
}
This should work:
$result = '<span>'. implode('</span>,<span>', $data) .'</span>';
You can do this to add attributes:
$span = '<span special="codes">';
$result = $span . implode('</span>,'. $span, $data) .'</span>';
Edit: It could be abstracted more to be reused:
function wrapInTag($arr, $tag='span', $atts='', $sep=',') {
return "<$tag>". implode("</$tag>$sep<$tag $atts>", $arr) ."</$tag>";
}
// Printing a list
echo '<ul>'. wrapInTag(['one','two','three'], 'li', 'class="item"') .'</ul>';
First add the string:
foreach ($data as $key=>$val){
$data[$key] = '<span special="codes">'.$val.'</span>';
}
then perform your implode to get the commas in place.
Or you can fix it after you implode:
Function array_to_comma($data)
{
if (is_array($data) and count($data) > 0)
{
foreach($data as $elem)
{
$elem = "<span special=\"codes\">" . $elem . "</span>"
}
$data = implode(', ', $data);
return $data;
}
}
i have a problem and i can't explain it ,,
first this is my function
function list_countries($id,$name=null,$result=null){
$countries = 'countries.txt';
$selected = '';
echo '<select name="'.$name.'" id="'.$id.'">';
echo '<option disabled>طالب الغد</option>';
if(file_exists($countries)){
if(is_readable($countries)){
$files = file_get_contents($countries);
$files = explode('|',$files);
foreach($files AS $file){
$value = sql_safe($file);
if(strlen($value) < 6){
echo '<option disabled>'.$value.'</option>';
}else{
if($value == $result){
$selected = ' selected="selected" ';
}
echo '<option value="'.$value.'".$selected.'>'.$value.'</option>';
}
}
}else{
echo 'The file is nor readable !';
}
}else{
echo "The file is not exist !";
}
echo '</select>';
}
Now the explain
i have a text file includes a countries names separated with "|"
In this file there is a heading before the countries ,, i mean Like this
U|United Kingdom|United State|UAE etc ..
L|Liberia|Libya etc ..
Now what the function Do is Disabled the Heading , and it's always one character ..
but the strlen function the minimum number that it's give to me is 5 not one .. " This is the first problem
The second one in the $result never equaled the $value and ether i don't know why ??
You need to split twice the file, one for the lines, one for the countries.
Also, since your "country header" is always the first item of each row, you do not need to check using strlen. Just shift out the first item of each row set: that one is the header, the following ones are the countries.
Something like this.
Note that in your code there is a syntax error in the echo that outputs the value, the > symbol is actually outside the quotes.
function list_countries($id,$name=null,$result=null){
$countries = 'countries.txt';
$selected = '';
$text = '<select name="'.$name.'" id="'.$id.'">';
$text .= '<option disabled>ﻁﺎﻠﺑ ﺎﻠﻏﺩ</option>';
if(file_exists($countries)){
if(is_readable($countries)){
$list = file($countries);
foreach($list as $item){
$item = trim($item);
$opts = explode('|', $item);
// The first item is the header.
$text .= "<option disabled>$opts[0]</option>";
array_shift($opts);
foreach($opts as $opt)
{
$value = sql_safe($opt);
$text .= '<option';
if($value == $result)
$text .= ' selected="selected"';
$text .= ' value="'.$value.'"';
$text .= '>'.$value."</option>\n";
}
}
}else{
$text .= "The file is not readable!";
}
}else{
$text .= "The file does not exist!";
}
$text .= '</select>';
return $text;
}
I have slightly modified your code so that the function actually returns the text to be output instead of echoing it; this makes for more reusability. To make the above function behave as yours did, just replace the return with
echo $text;
}
and you're good.
i need to sort some strings and match them with links, this is what i do:
$name_link = $dom->find('div[class=link] strong');
Returns array [0]-[5] containing strings such as NowDownload.eu
$code_link = $dom->find('div[class=link] code');
Returns links that match the names from 0-5, as in link [0] belongs to name [0]
I do not know the order in which they are returned, NowDownload.Eu, could be $code_link[4] or $code_link [3], but the name array will match it in order.
Now, i need $code_link[4] // lets say its NowDownload.Eu to become $link1 every time
so i do this
$i = 0;
while (!empty($code_link[$i]))
SortLinks($name_link, $code_link, $i); // pass all links and names to function, and counter
$i++;
}
function SortLinks($name_link, $code_link, &$i) { // counter is passed by reference since it has to increase after the function
$string = $name_link[$i]->plaintext; // name_link is saved as string
$string = serialize($string); // They are returned in a odd format, not searcheble unless i serialize
if (strpos($string, 'NowDownload.eu')) { // if string contains NowDownload.eu
$link1 = $code_link[$i]->plaintext;
$link1 = html_entity_decode($link1);
return $link1; // return link1
}
elseif (strpos($string, 'Fileswap')) {
$link2 = $code_link[$i]->plaintext;
$link2 = html_entity_decode($link2);
return $link2;
}
elseif (strpos($string, 'Mirrorcreator')) {
$link3 = $code_link[$i]->plaintext;
$link3 = html_entity_decode($link3);
return $link3;
}
elseif (strpos($string, 'Uploaded')) {
$link4 = $code_link[$i]->plaintext;
$link4 = html_entity_decode($link4);
return $link4;
}
elseif (strpos($string, 'Ziddu')) {
$link5 = $code_link[$i]->plaintext;
$link5 = html_entity_decode($link5);
return $link5;
}
elseif (strpos($string, 'ZippyShare')) {
$link6 = $code_link[$i]->plaintext;
$link6 = html_entity_decode($link6);
return $link6;
}
}
echo $link1 . '<br>';
echo $link2 . '<br>';
echo $link3 . '<br>';
echo $link4 . '<br>';
echo $link5 . '<br>';
echo $link6 . '<br>';
die();
I know they it finds the link, i have tested it before, but i wanted to make it a function, and it messed up, is my logic faulty or is there an issue with the way i pass the variables/ararys ?
I don't know why you pass $i as reference since you use it just for reading it. You could return an array contaning the named links and using it like so :
$all_links = SortLinks($name_link,$code_link);
echo $all_links['link1'].'<br/>';
echo $all_links['link2'].'<br/>';
You will have to put your loop inside the function, not outside.
I have a PHP script that pulls keywords from a MySQL database and I need help with figuring out how to link each word.
An example MySQL entry:
cow moo white black
Need to output in link form:
<a href=word.php?word=cow>cow</a> <a href=word.php?word=moo>moo</a>, etc.
Thank you
Try this:
$output = "";
$mysql_str = "cow moo white black";
$keywords = explode(" ", $mysql_str);
foreach ($keywords as $keyword) {
$output .= "".$keyword." ";
}
echo $output;
If $row["entry"] is the entry, then as follows:
$fieldArray = split(" ", $row["entry"]);
foreach($fieldArray as $item) {
echo "" . $item . "";
}