get single data from multiple data with jquery - arrays

i have table view like below
<table>
<tr><th>Username</th>
<th>Departemen</th><th>Created By</th><th>Created Date</th><th>Last Update By</th><th>Last Update Date</th><th>Aksi</th></tr>
<?php
$sql = "SELECT TOP 20 * FROM tblMstUser where CompanyDeptID ='11' or CompanyDeptID ='12' order by LoginID";
$tampil = mssql_query($sql) ;
while($r=mssql_fetch_array($tampil)){
echo "<tr><td>$r[LoginID]</td>
<td>$r[LoginName]</td>
<td>$r[CreatedBy]</td>
<td>$r[CreatedDate]</td>
<td>$r[LastUpdatedBy]</td>
<td>$r[LastUpdatedDate]</td>
<td>
<button id='edit' onclick=\"popup_window_show('#sample', { pos : 'tag-right-down', parent : this});\"'><image src='images/Edit.png'/>Edit</button> |
<button id='delete'><image src='images/delete.png'/>Hapus</button>
</td>
</tr>";
$no++;
}
?>
</table>
my purpose when user click "edit" all of field in popup will filled by related data using LoginID as parameter in my sql. i use ms sql 2008 as mya database server.
my problem how i can get a single data from array "$r[LoginID]" using Jquery for each row.

pass LoginID to the function as parameter along with button onClick, eg.
<button id='edit' onclick=\"popup_window_show('#sample', '$r[LoginID]' ,{ pos : 'tag-right-down', parent : this});\"'>
and fire ajax call with jQuery to a page, the page returns data related to LoginID and fill all editable fileds in the edit form.

Related

How to display multiple selected value from db based of their ID in Laravel

I want to show array of data based on their id. I have two tables.
first one is "languages"
Other is "user"
each user has one or more languages.
so I have stored languages id in user table in array form.
now I want to show languages in- show user detail page-.
I used the following controller:
``` public function show()
{
$user=auth()->user()->Consult;
$languagess=Lang::all();
$selected = explode(",", $con->languages);
$collection = [];
foreach($selected as $r){
$collection[] = DB::table('language')->where('id', $r['languages'])->first();
}
dd($collection);
return View('consultacy.showPro',compact('user','languages'));
}```
I used following view :
<span >{{ $languagess['name']}}</span>
#endforeach
the error :
Illegal string offset 'languages'
Any tutorial or method to do this

Wordpress addon to add data to a database and then call the data

I know this question is probably going to get downvoted and I will probably get into trouble but I am hoping someone may be able to help me with my situation.
On my site I use json to download data from an external source, and then I style it beautifully.
Within the json data is an individual ID for each data set.
What I want to accomplish is to have a database where I can insert the ID and a url link.
I have created the table within the wordpress database via phpMyAdmin, but I want to create a page within the admin section where I can simply add the data in.
For displaying the json data I use a php insert addon, within that php clip i want to do a piece of code that checks the database for the id within my custom database and displays the link.
I will be honest I don't know where to start on this, even if its just a link to a source that shows me how to create an admin page and submit data to the database within wordpress dashboard.
I really appreciate any help given and like I say I know I should try harder, but when ever I do a search all I get is 100's of references to add an admin to the database manually.
Thanks,
Adam
Edit I just realized I never put any table information in my question.
The table name within wordpress is called: wp_home_tickets
within that are 3 fields: id (auto increasement), gameid (numeric) and ticketlink (text)
thanks.
For adding a custom settings page in your admin, use the Settings API https://codex.wordpress.org/Settings_API
Here is a nice tutorial using it https://deliciousbrains.com/create-wordpress-plugin-settings-page/#wp-settings-api
To fetch data from your custom table, use the wpdb class https://developer.wordpress.org/reference/classes/wpdb/. More specifically, you can use wpdb::get_results if you will have multiple rows sharing the same id https://developer.wordpress.org/reference/classes/wpdb/get_results/
Or wpdb::get_row if you will ever only have one https://developer.wordpress.org/reference/classes/wpdb/get_row/
Hope this helps you out!
For anyone wishing to see how it was done, here is how I did it.
I created a file in my theme called db_admin_menu.php and added the following to it:
<?php
function ticket_admin_menu() {
global $team_page;
add_menu_page( __( 'Tickets', 'sports-bench' ), __( 'Tickets', 'sports-bench' ), 'edit_posts', 'add_data', 'ticket_page_handler', 'dashicons-groups', 6 ) ;
}
add_action( 'admin_menu', 'ticket_admin_menu' );
function ticket_page_handler() {
$table_name = 'wp_home_tickets';
global $wpdb;
echo '<form method="POST" action="?page=add_data">
<label>Team ID: </label><input type="text" name="gameid" /><br />
<label>Ticket Link: </label><input type="text" name="ticketlink" /><br />
<input type="submit" value="submit" />
</form>';
$default = array(
'gameid' => '',
'ticketlink' => '',
);
$item = shortcode_atts( $default, $_REQUEST );
$gameid = $item['gameid'];
if ($wpdb->get_var("SELECT * FROM wp_home_tickets WHERE gameid = $gameid ")) { echo 'Ticket already exists for this game.'; goto skip; }
if (!empty($_POST)) { $wpdb->insert( $table_name, $item ); }
skip:
}
?>
I then put this code in my script that fetches and displays the json:
$matchid = $match['id'];
$ticket_url = $wpdb->get_var("SELECT ticketlink FROM wp_home_tickets WHERE gameid = '$matchid' ");
if ($ticket_url) { echo 'Get Tickets'; }
I hope someone does find it of use, i did have to use a wordpress plugin called `Insert PHP Code Snippet' by xyzscripts to be able to snippet the php to a shortcode, but that is not the purpose of this post.
Thanks again for your help.

Pagination using PageObject Watir Webdriver [duplicate]

Using page-object and watir-webdriver how can I click a link in a table, based on the row text as below:
The table contains 3 rows which have names in the first column, and a corresponding Details link in columns to the right:
DASHBOARD .... Details
EXAMPLE .... Details
and so on.
<div class="basicGridHeader">
<table class="basicGridTable">ALL THE DETAILS:
....soon
</table>
</div>
<div class="basicGridWrapper">
<table class="basicGridTable">
<tbody id="bicFac9" class="ide043">
<tr id="id056">
<td class="bicRowFac10">
<span>
<label class="bicDeco5">
<b>DASHBOARD:</b> ---> Based on this text
</label>
</span>
</td>
<td class="bicRowFac11">
....some element
</td>
<td class="bicRowFac12">
<span>
<a class="bicFacDet5">Details</a> ---> I should able click this link
</span>
</td>
</tr>
</tbody>
</table>
</div>
You could locate a cell that contains the specified text, go to the parent row and then find the details link in that row.
Assuming that there might be other detail links you would want to click, I would define a view_details method that accepts the text of the row you want to locate:
class MyPage
include PageObject
table(:grid){ div_element(:class => 'basicGridWrapper')
.table_element(:class => 'basicGridTable') }
def view_details(label)
grid_element.cell_element(:text => /#{label}/)
.parent
.link_element(:text => 'Details')
.click
end
end
You can then click the link with:
page.view_details('DASHBOARD')
Table elements include the Enumerable module, and I find it very useful in cases like these. http://ruby-doc.org/core-2.0.0/Enumerable.html. You could use the find method to locate and return the row that matches the criteria you are looking for. For example:
class MyPage
include PageObject
table(:grid_table, :class => 'basicGridTable')
def click_link_by_row_text(text_value)
matched_row = locate_row_by_text(text_value)
matched_row.link_element.click
#if you want to make sure you click on the link under the 3rd column you can also do this...
#matched_row[2].link_element.click
end
def locate_row_by_text(text_value)
#find the row that matches the text you are looking for
matched_row = grid_table_element.find { |row| row.text.include? text_value }
fail "Could not locate the row with value #{text_value}" if matched_row.nil?
matched_row
end
end
Here, locate_row_by_text will look for the row that includes the text you are looking for, and will throw an exception if it doesnt find it. Then, once you find the row, you can drill down to the link, and click on it as shown in the click_link_by_row_text method.
Just for posterity, I would like to give an updated answer. It is now possible to traverse through a table using table_element[row_index][column_index].
A little bit more verbose:
row_index could also be the text in a row to be matched - in your case - table_element['DASHBOARD']
Then find the corresponding cell/td element using either the index(zero based) or the header of that column
table_element['DASHBOARD'][2] - Selecting the third element in the
selected row.
Since you do not have a header row (<th> element) you can filter the cell element using the link's class attribute. Something like this
table_element['DASHBOARD'].link_element(:class => 'bicRowFac10').click
So the code would look something like this:
class MyPage
include PageObject
def click_link_by_row_text(text_value)
table_element[text_value].link_element(:class => 'bicRowFac10').click
end
end
Let me know if you need more explanation. Happy to help :)

Getting current page in CakePHP pagination

On one of my webpage, I show a list of customer details with default pagination [Paginator helper]. Each customer row has a corresponding 'edit' button which when clicked shows a DIV populated with that customer information. [This DIV has textboxes etc. where I can change customer info] After re-entering/modifying customer details, when I click on "Save" button, 2 ajax calls are made..
First one to save the edited record
The second one Updates the customer Listing on the same page with modified information
My problem : If I am on page 3 and edit one customer record, the 2nd ajax call refreshes the list but does not go to the page 3. It starts from page 1.
Please help.
You can get your current page here:
<?php echo $this->Paginator->counter(array(
'format' => ('{:page}')
)); ?>
This is part of the solution. :)
You can get your current page here:
$this->request->params['named']['page']
Did you try to use the link from Paginator? It maintains the page # to the controller.
Something like
// same parameters as $this->Html->link
<?php echo $this->Paginator->link( ... ) ?>
Check also the reference documentation for the Paginator Helper
I use jquery / javascript to store the page on a cookie and then read it from the controller.
// -------------------------------------------------------------------------
// on action click remember current page
$('td.actions').click( function( event )
{
var page = $('li.active a').html();
var name = window.location.href.split('-').join('_').split('/').pop();
$.cookie.raw = true;
$.cookie( 'CakeCookie[' + name + '_page]', page, { expires: 365, path: '/' } );
});

jquery ui autocomplete database

I'd like to use jQuery UI autocomplete in order to load a list from my database but I don't know wich method I should use to do so.
I tried to use the "Remote datasource" method http://jqueryui.com/demos/autocomplete/#remote, but it obviously doesn't work.
I have the following code :
js:
$(function() {
$("#client").autocomplete({
source: "nom.php",
minLength: 2,
select: function(event, ui) {
alert(ui);
}
});
});
html :
<label for="client">Client</label>
<input name="client" id="client" class="ui-autocomplete ui-widget-content ui-corner-all" />
php:
$query = "SELECT nom from personne";
$result = mysql_query($query, $db);
while($row = mysql_fetch_assoc($result)) {
foreach($row as $val)
$tab[] = $val;
}
print json_encode($tab);
It does show all the values no matter what I enter, but when I copy the result of nom.php and past it next to source: it does work...
thank you for your helm
The problem is that you are not filtering the results server side.
When you use a local collection, the local collection gets automatically filtered by autocomplete.
However, when using a remote source, the source is supposed to filter. I guess this is to save bandwidth so that the server only send the matching items, and not all items and let the browser filter at it's end.
When calling your server side method, autocomplete also sends a parameter called term that you can use to filter.
You can get hold of the entered value like this in your php script:
$term = trim(strip_tags($_GET['term']));
Then in your foreach, only add the items matching the filter to your collection before you send it back again.

Resources