I am displaying a table values by using jsp in that i hv JDBC code to display the table data.
pls see the code below.
<table cellspacing="0" cellpadding="0">
<tr>
<th>USN</th>
<th>Name</th>
<th>Semister</th>
<th>Mobile No.</th>
<th>Email</th>
</tr>
<!-- all you need with Tablecloth is a regular, well formed table. No need for id's, class names... -->
<%
PreparedStatement s = con.prepareStatement("select * from sttable");
ResultSet es = s.executeQuery();
while(es.next())
{
%>
<tr>
<td><%=es.getString(2) %></td>
<td><%=es.getString(1) %></td>
<td><%=es.getString(3) %></td>
<td><%=es.getString(4) %></td>
<td><%=es.getString(5) %></td>
</tr>
<%} %>
</table>
The above code displays values in the table ,what i want to do is select a particular value
by a giving a link to it as show below.
<td><a href="#"<%=es.getString(2) %></a></td>
by clicking particular value i want to retrive that value details from the table
for Eg.USN is the primary key and by clicking on it i want to get the data associated with that USN,Help me out in this...
Let's assume that es.getString(0) is the location of the primary key. You can do something like:
<tr>
<% if(myCondition == true) { %>
<td><%=es.getString(2)%></td>
<% } else { %>
<td><%=es.getString(2) %></td>
<% } %>
<td><%=es.getString(1) %></td>
<td><%=es.getString(3) %></td>
<td><%=es.getString(4) %></td>
<td><%=es.getString(5) %></td>
</tr>
Related
On my index page, I succeeded in listing all of my 'games' in a table, unfortunately, another list, that isn't part of my index.html.erb file code also appears, above my table.
I don't understand how this is possible as my html file doesn't contain any element at the place the list appears on the browser... If someone has an idea that would be very nice !
Here's a photo of what appears on the browser :
browser problem snapshot
Here's my index.html.erb code :
<div class="container full-height">
<div class="abs-center">
<table class="table">
<thead>
<tr>
<td colspan="6">GAMES</td>
</tr>
</thead>
<tbody>
<%= #games.reverse.each do |g| %>
<tr>
<td><%= g.id %></td>
<td><%= g.score_1 %></td>
<td><%= g.score_2 %></td>
<td><%= g.created_at %></td>
<td><%= link_to 'see game', game_path(g) %></td>
<td><%= link_to 'modify', edit_game_path(g) %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
My game controller index method :
def index
#games = Game.all
end
Thanks a lot !
Remove = before <%= #games.reverse.each do |g| %>. = renders a result of an expression, in your case, it is each method, that returns the collection.
Must look as this <% #games.reverse.each do |g| %>
i am trying to make a transaction details page, how can i make the new input table row on the transactions table sort before the previous one? I use node, mongo, mongoose and javascript and ejs
<section id="transactions">
<div class="mx-5 my-5">
<table>
<tr>
<th>Transaction ID</th>
<th>Beneficiary Details</th>
<th>Timestamp</th>
<th>More</th>
</tr>
<% transactions.forEach(function(transaction) { %>
<tr>
<td><%= transaction._id %></td>
<td> <%= transaction.beneficiaryName %> <%= transaction.beneficiaryBank %> <%= transaction.beneficiaryAccountNumber %> <%= transaction.transferAmount %></td>
<td><%= transaction.time %></td>
<td></td>
</tr>
<% }) %>
</table>
</div>
If you are generating the list from transactions, and I guess it's an array of objects, you can use:
transactions.unshift({<newObject>})
to add it to the beginning of the array
And if you want to do it with JQuery, use:
$('table > tbody > tr:first').before('<tr><td>Stuff</td></tr>');
I just made a table and I have three records that I'm trying to display. It successfully displays the information but it crams it all in one row. When I want it to display over three rows. I'm doing something obvious wrong but I still need some help. Here is my code:
HTML
<table>
<tr>
<th>Name</th>
<th>Manage</th>
</tr>
<tr>
<% #assignments.each do |assignment| %>
<td><%= link_to assignment.name, account_assignment_path(assignment) %></td>
<td><%= link_to "Delete", account_assignment_path(assignment), method: :delete %></td>
<% end %>
</tr>
</table>
Screen Shot:
As you can see they all try to fit in one column. How can I fix this so they spread out?
I'm not familiar with the templating language you're using, but this is likely due to not including the <tr> element in your loop.
<table>
<tr>
<th>Name</th>
<th>Manage</th>
</tr>
<% #assignments.each do |assignment| %>
<tr>
<td><%= link_to assignment.name, account_assignment_path(assignment) %></td>
<td><%= link_to "Delete", account_assignment_path(assignment), method: :delete %></td>
</tr>
<% end %>
</table>
I am creating a Blog as my college project. Now i have a table named blogs and there are 5 attributes in the table.
blog_name, blog_user, blog_id, blog_date & blog_text
Now there are saveral entries in the blog.
I need a way to fetch the whole table and show the list of blog on a single page.
That is need a way to select the whole table and print the blog names using a while loop.
This is what you're looking for:
<% Blog.all.each do |blog| %>
# code
<% end %>
I'd also advice you learning some Ruby/Rails basics.
You can do like this
In your Controller
def index
#blog = Blog.all
end
In your view(index.html.erb)
<table border=1>
<tr>
<th>Blog Name</th>
<th>Blog User</th>
<th>Blog ID</th>
<th>Blog Date</th>
<th>Blog Text</th>
</tr>
<% #blog.each do |b| %>
<tr>
<td><%= b.blog_name %></td>
<td><%= b.blog_user %></td>
<td><%= b.blog_id %></td>
<td><%= b.blog_date %></td>
<td><%= b.blog_text %></td>
</tr>
<% end %>
</table>
So,for every blog entry you will be getting all the details populated in a table view.
I'd like to view data from different database-tables in a view with tables like this picture shows:
I'm familiar with HTML tags <table>, <td> and <tr>, but I'm having trouble with multiple queries in a column.
<table>
<tr>
<th>Skills </th>
<th>Expected-qualifications</th>
<th>Current-qualifications</th>
</tr>
<% #employee.position.skills.each do |skill| %><% #employee.position.expected_qualifications.each do |expected_qualification| %><% #employee.current_qualifications.each do |current_qualification| %>
<tr>
<td><%= skill.kategorien %></td>
<td><%= expected_qualification.sollqualifikation %></td>
<td><%= current_qualification.istqualifikation %></td>
</tr>
<% end %><% end %><% end %>
</table>
This code looks like this:
As you can see, the skills, expected-qualifications, and current-qualifications repeat.
My question: How should the codes be ordered in the table so it will look the way I want it to?
Try zip:
<% #employee.position.skills.zip(#employee.position.expected_qualifications,#employee.current_qualifications).each |skill expected_qualification current_qualification| %>
<tr>
<td><%= skill.kategorien %></td>
<td><%= expected_qualification.sollqualifikation %></td>
<td><%= current_qualification.istqualifikation %></td>
</tr>
<% end %>
if there is REALLY can be more than one skill, expected_qualification and current_qualification so you use has_many assosiation forposition
<tr>
<td><%= #employee.position.skills.map(&:kategorien).join(", ") %></td>
<td><%= #employee.position.expected_qualifications.map(&:sollqualifikation).join(", ") %></td>
<td><%= #employee.current_qualifications.map(&:istqualifikation).join(", ") %></td>
</tr>
Otherwise you should use has_one association