help w/ MS access database to <table>.... with a twist - html

I am trying to more easily manage my table with an access database rather than manually entering data into a <table>.
I have laid out the basic idea but I don't know exactly how to perfect it. Also what do I do if one of my table rows (specifically the last one) doesn't have exactly 3 cells?
This is what I have laid out so far:
<table class="tablecenter" cellspacing="30">
<tbody>
<%
sql()
SQL = Select * From Database
DR = DataReader (SQL)
While Not DR.EOF
x = 1
If x < 4 Then %>
<td><img src="avatar-blank.jpg" alt="headshot"/><br /><p>dr("Name") <br />Hometown: VarAddress <br /> Class: VarClass</p></td>
<% Else
x = 0 %>
</tr>
<tr>
<td><img src="avatar-blank.jpg" alt="headshot" /><br /><p>VarName<br />Hometown: VarAddress<br />Class: VarClass</p></td>
<% End If
x = x + 1
DR.moveNext
Wend %>

It depends on why there are fewer than 3 cells. If it is just missing data, then insert an empty <td> element.

Related

get column data and insert into a row with id given in another column - sql nodejs

I have made a certain form with a table layout
the table is kind of like this below:
UAN NAME DESIGNATION No. of Days Present
87982 JOHN SALESMAN 25
now, the columns uan name and designation are already given (taken from the database) and the user only needs to put in the attendance.
the number of days will then be inserted into the database
in the row where UAN = 87892
The problem is that I am unable to figure out how to get the value of UAN from the page and use it to enter the number of days in the database.
could you give some idea how to accomplish this using nodejs??
I am using the ejs templating system and mysql database.
that's not the only problem.
I also want to enter the number of days present for all the different employees
where the number of days gets added to the row with their UAN number.
how am I supposed to do that?
any ideas??
here's the code for the attendance page
<!DOCTYPE HTML>
<html>
<head><title>attendance for employees</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div>
<table>
<tr>
<th>Serial No.</th>
<th>UAN</th>
<th>Name</th>
<th>Designation</th>
<th>Attendance</th>
</tr>
<form action="/attendance-data" method="post">
<% var i=0 %>
<% rows.forEach(function(item){ %>
<% i=i+1 %>
<tr>
<td><%= i+"." %></td>
<td id="uan<%= i %>"> <%= item.uan %> </td>
<td><%= item.name %></td>
<td><%= item.designation %></td>
<td><input type="text" name="attendance <%= i %>" ></td>
</tr>
<% }); %>
</form>
</table>
</div>
<div>
<input type="button" value="submit" />
</div>
</body>
</html>
In order to get the data from the page and insert it into your database:
WHERE uan = '[data_from_html]', you will need to reference it by name. This can be accomplished when the user enters into the form how many days of attendance. The biggest issue you will have is that forms are tough to get working in correspondence to a table. You can put an entire table inside of a form but not the other way around necessarily.
Inside of your last td tag it would be best to place the entire form there with only one field visible and the rest hidden(you can still display as you were, just leave the other fields out of the form:
<td>
<form action='/attendance-data' method='post'>
<input type='hidden' id='uan<%= i %>' name='attendance' value ='<%= i %>'/>
<input type='hidden' name='item_name' value ='<%= i %>'/>
<input type='hidden' name='designation' value ='<%= item.designation %>'/>
<input type='text' name='attendance' value ='<%= i %>'/>
<input type="submit" value="Submit" />
</form>
</td>
Then inside of your routes in express:
app.post('/attendance-data', function(req, res) {
var uan = req.body.uan
var item_name = req.body.item_name
var designation = req.body.designation
var attendance = req.body.attendance
// Make sure they all contain some sort of value
var connString = new ConnectionString(
config.mysql.host,
config.mysql.port,
config.mysql.username,
config.mysql.password,
config.mysql.default_db
)
var MySqlConn = new MySqlConnection(connString)
// Proceed to do an update/insert into your db
MySqlConn.Connection.query("insert into [your_table] " +
"values(uan, item_name, designation, attendance) where uan='" + uan + "'",
function (err)
{
if (err)
{
console.log(err.stack)
throw err
}
// Otherwise success
res.status(200).send('blah')
})
}

Can I web scrape for a particular style in VBA?

I have been looking everywhere for any possible workaround to this issue.
All of the data at my company is accessed via a web portal that produces static HTML pages. Unfortunately our department cannot be given direct access to the Server which would make my life easy so I need to page scrape this portal to find the data that I need. My navigation is fine and i am quite experienced with scraping where elements are named or given an ID, however this does not have either.
Anyway, background out of the way.
I want to grab a table from the page that has a unique style of "empty-cells: show;":
<TABLE cellspacing=10 cellPadding=10 border="1" style="empty-cells: show;">
</TABLE>
Or failing that there is a heading in the first row which always contains the same text string. Once I have that table I can manipulate the data I need from it. Hugely sensitive data here guys, so I can't provide the full page code unfortunately.
I know that there have been many posts regarding GetElementByRegex but I cannot find a post or website that actually explains how to use it. Instead they all want me to install their add-on which isn't an option (I need to learn this to sate my thirst for knowledge).
To help I have added the full table code below removing the sensitive data:
<TABLE cellspacing=10 cellPadding=10 border="0" width=100%>
<tr>
<td>
<TABLE cellspacing=10 cellPadding=10 border="1" style="empty-cells: show;">
<TR class="row0">
<TD style="width: 25%; background-color: #A3DCF5;"><strong>TITLE:</strong></TD>
<TD>LINE1</TD>
</TR>
<TR class="row1">
<TD> </TD><td>LINE2</td>
</TR>
<TR class="row0">
<TD> </TD><td>LINE3</td>
</TR>
<TR class="row1">
<TD> </TD><td>LINE4</td>
</TR>
<TR class="row0">
<TD> </TD><td>LINE5</td>
</TR>
</TABLE>
</td>
</tr>
</TABLE>
There are many other tables though so using a Len check will not help me top sift through the TD tags.
Dim tbls, tbl, tr, j, td, row, sht
Set tbls = IE.document.getElementsByTagName("table")
For Each tbl in tbls
'item indexes are zero-based (AFAIR)
If tbl.Rows(0).Cells(1).innerText = "LINE1" Then
'EDIT: extracting the table contents
Set sht = ActiveSheet
row = 3
For Each tr In t.getelementsbytagname("TR")
j = 1
For Each td In tr.getelementsbytagname("TD")
sht.Cells(row + 1, j).Value = td.innerText
j = j + 1
Next
row = row + 1
Next
Exit For 'stop looping
End If
Next
Answer by Glitch_Doctor edited out of question:
Thank you for all the help Tim!
The below worked perfectly for me:
Dim tbls, tbl
Dim L1, L2, L3, L4, L5 As String
Set tbls = IE.Document.getElementsByTagName("table")
For Each tbl In tbls
If tbl.Rows(0).Cells(0).innerText = "Card Address:" Then
On Error Resume Next
L1 = tbl.Rows(0).Cells(1).innerText
L2 = tbl.Rows(1).Cells(1).innerText
L3 = tbl.Rows(2).Cells(1).innerText
L4 = tbl.Rows(3).Cells(1).innerText
L5 = tbl.Rows(4).Cells(1).innerText
Exit For
End If
Next
Worksheets("Sheet2").Range("A1").Value = L1
Worksheets("Sheet2").Range("A2").Value = L2
Worksheets("Sheet2").Range("A3").Value = L3
Worksheets("Sheet2").Range("A4").Value = L4
Worksheets("Sheet2").Range("A5").Value = L5
End Sub

While not EOF in another while not EOF not working in ASP CLASSIC

The below code breaks when I place a while not EOF in another while not EOF.
Is this illegal in ASP Classic code? How do I fix it?
<table cellspacing = "0" cellpadding = "3" class = "horiz ">
<tr>
<th width = "20%">Acronym</th>
<th width = "50%">Meaning</th>
<th width = "30%">Source</th>
</tr>
<%
count = 0
pletter = "z"
fletter = left(con("acronym"),1)
%>
<% while (NOT con.EOF) %>
<tr>
<td colspan = "3" ><h2><a name="A">A</a></h2></td>
</tr>
<% while (NOT con.EOF) %>
<tr>
<td><%=con("acronym")%></td>
<td><%=con("meaning")%></td>
<td><%=con("source")%></td>
</tr>
<%
con.MoveNext()
Wend
%>
<%
con.MoveNext()
Wend
%>
</table>
Why not have a single while loop. Add an if statement to determine if the first character has changed (E.g., from A to B). If the character changes, add a TR to display the character.
dim lastCharacter = ""
while (not con.EOF)
dim firstLetterOfAcronym = left(con("acronym"),1)
if lastCharacter <> firstLetterOfAcronym then
rem show TR of firstLetterOfAcronym
lastCharacter = firstLetterOfAcronym
end if
<tr>..... show row as usual </tr>
con.MoveNext()
wend
Assuming you have your recordset sorted on the Acronym .
This is exactly like #Valamas his solution, meaning a single loop, but a bit more complete example.
<table cellspacing = "0" cellpadding = "3" class = "horiz">
<tr>
<th width = "20%">Acronym</th>
<th width = "50%">Meaning</th>
<th width = "30%">Source</th>
</tr>
<%
mainletter = ""
While (NOT con.EOF)
letter = Left(con("acronym")
If mainletter <> letter Then
%>
<tr>
<td colspan = "3" ><h2><a name="<%=letter%>"><%=letter%></a></h2></td>
</tr>
<%
mainletter = Left(con("acronym"),1)
End If
<tr>
<td><%=con("acronym")%></td>
<td><%=con("meaning")%></td>
<td><%=con("source")%></td>
</tr>
<%
con.MoveNext()
Wend
%>
</table>
Once you get to the end of the recordset (via the loop) it does not reset back to the start (unless you tell it too) so once you get to the end of the recordset in the first loop when the second loops start it is already at the end.
I would rewrite your code as it is not really logical but if you want your code to work as is add a movefirst after the loop ends to go back to the start of the recordset.
...
</tr>
<%
con.MoveNext()
Wend
con.movefirst
con.MoveNext()
Wend
%>
</table>
Edit: Actually you'll end up in a loop if you do this, clone the recordset before the first loop and loop two different recordsets with the same data. Otherwise re-write to be a little cleaner.

Assign value to HTML textbox from JSP

Hello I am creating a web page to add some information about given product.I need to enter id,name,description and image as information.I need the id to be auto generated.I am using jsp and database as access.I am fetching the count(*)+1 value from database and assigning to my html text box but its showing as null.can i get some help?
Code:
<body>
<%#page import="java.sql.*"%>
<%! String no; %>
<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:pd");
ResultSet rs = null;
Statement st = con.createStatement();
String sql = ("select count(*)+1 from products");
st.executeUpdate(sql);
while (rs.next()) {
no=rs.getString("count(*)+1");
}
rs.close();
st.close();
con.close();
}
catch(Exception e){}
%>
<Form name='Form1' action="productcode.jsp" method="post">
<table width="1024" border="0">
<tr>
<td width="10"> </td>
<td width="126">Add Product: </td>
<td width="277"> </td>
<td width="583"> </td>
</tr>
<tr>
<td> </td>
<td>Product Id:</td>
<td><label>
<input type="text" name="id" value="<%= no%>"/>
</label></td>
<td> </td>
.... and so on
{..}.executeQuery("Select max(id) from tablename");
This will return the ID with the largest number. Its more efficient than select * from tablename order by id desc limit 1.
However, it looks like your trying to guess/generate an ID of an object which doesn't yet exist in the database. This isn't the best way, and you may find that the ID your generating may be different to that generated by your DB. It could also cause duplication errors if two people are trying to create two new objects at the same time.
I would suggest that you don't provide a product id until the "create product" button has been pressed. Use ##IDENTITY; in your SQL command to set the new ID to your product safely.
You wrote a query to get the data like this
String sql = ("select count(*)+1 from products");
st.executeUpdate(sql);
The statement
executeUpdate()
only used to do the operations like INSERT,UPDATE
try
rs=st.executeQuery(sql);
instead of executeUpdate()

Ruby/Rails/HTML - Create New Table Row After X cells from loop

I'm using Rails to display a set of data. The problem is that data is so large I dont really do the usually for each loop since I creates this insanely long list.
My solution would be to create some form of table where after 10 records create a new cell and after 5 cells create a new row. I'm not really that comfortable with for loops in rails so I figured throw the question out.
Right now I have...
<strong> Person Data Set: </strong><br />
<% for person in #persons %>
<%= interest.name %> <br />
<% end %>
So I can I create a loop similar to this?
<strong> Person Data Set: </strong><br />
<table>
<tr>
*****for each 5 cells???? *****
<td>
*****For each 10 records?? ***
</td>
</tr>
</table>
Has anyone had to deal with an issue like this before?
There is an each_slice method. With HAML (I really don't like ERB but the idea is the same):
%strong
Person Data Set:
%br
%table
- #persons.each_slice(10) do |ten_people|
%tr
- ten_people.each_slice(5) do |five_people|
%td
- five_people.each do |person|
%p= person.name