by John Avis | March 28, 2017 | web+db Web Development
<?
DECLARE @page INT = CAST(REQUEST.GET("page") AS int);
IF @page < 0 THEN @page = 1;
DECLARE @rowsperpage = 10;
DECLARE @count INT = SELECT
COUNT(*)
FROM tablea
INNER JOIN tableb ON tablea.id = tableb.tableaid
WHERE tablea.deleted = 0;
IF @page > (@count / @rowsperpage) THEN @page = (@count / @rowsperpage);
DECLARE @result RESULTSET = SELECT
tablea.field1, tableb.field2
FROM tablea
INNER JOIN tableb ON tablea.id = tableb.tableaid
WHERE tablea.deleted = 0
ORDER BY tableb.field2
LIMIT (@page - 1) * @rowsperpage, @rowsperpage;
?>
<table>
<tr>
<th>Column A</th>
<th>Column B</th>
</tr>
<? WHILE (@result <> NULL) BEGIN ?>
<tr>
<td><?= @row.field1 ></td>
<td><?= @row.field2 ></td>
</tr>
<? @result.MOVENEXT() ?>
<? END ?>
</table>
<p>Showing page <?= @page ?> of <?= (@count / @rowsperpage) ?>
<?
DECLARE @id INT;
DECLARE @title VARCHAR(50);
DECLARE @error VARCHAR = '';
IF NOT REQUEST.POST BEGIN
@id = CAST(REQUEST.GET("id") AS int);
IF @id != 0 BEGIN
DECLARE @row RESULTSET = SELECT title FROM tablea WHERE id = @id;
IF (@row == NULL)
@error = '<li>Row not found</li>';
ELSE
@title = @row.title;
ELSE BEGIN
@title = '';
END
END
ELSE BEGIN
@id = CAST(REQUEST.POST("id") AS int);
@title = REQUEST.POST("title");
IF (TRIM(@title)) = '' @error += '<li>Title is a required field</li>';
IF @error = 0 BEGIN
DECLARE @rowsaffected int;
IF @id != 0 BEGIN
@rowsaffected = UPDATE tablea SET title = @title WHERE id = @id;
END
ELSE BEGIN
@rowsaffected = INSERT INTO tablea (title) VALUES (@title);
END
IF @rowsaffected != 1
@error += '<li>There was an error when saving record</li>';
ELSE
RESPONSE.REDIRECT REQUEST.URL;
END
END
?>
<form action="<?= REQUEST.URL ?>" method="post">
<? IF @error != '' BEGIN ?>
<p>Errors:</p>
<ul><?= @error ?></ul>
<? END ?>
<label>Title</label>
<input name="title" type="text" value="<?= HTMLENCODE(@title) ?>" />
<input type="submit" value="SUBMIT" />
</form>
DECLARE @keywords VARCHAR = REQUEST.GET('keywords');
DECLARE @keyword LIST(VARCHAR) = SPLIT(@keywords, ' ');
DECLARE @query QUERY = SELECT tablea.column1 FROM tablea INNER JOIN tableb ON tablea.id = tableb.tableaid;
FOREACH (DECLARE @word IN @keyword) BEGIN
@query += WHERE tablea.column2 LIKE %@word%;
END
IF @order = 1
@query += ORDER BY tablea.column1 ASC;
ELSE
@query += ORDER BY tablea.column2 ASC;
DECLARE @result RESULTSET = @query.GO();
by John Avis | November 4, 2019
As support ends for Microsoft Windows Server 2008 I have recently gone through migrating some websites to a new server running Windows Server 2016 and IIS 10 but some of the websites did not work.
by John Avis | October 15, 2019
For a website project I needed a way to enter multiple tags. I just wanted something simple that I could easily modify to suit my own needs, so I wrote my own.
by John Avis | September 1, 2019
I rediscovered a bug in ASP.NET that affects RadioButtons inside repeaters. Here is my solution to the problem.
...random postings about web development and programming, Internet, computers, electronics and automotive topics.
Get the latest posts delivered to your inbox.
Comments
There are no comments yet. Be the first to leave a comment!