Saturday, November 27, 2004

How do I schedule the server to generate static HTML files from other dynamic web pages?

Some people would use Perl or PHP to grab data from the database and generate the HTML when the scripts are executed. I'm just too lazy to write another script for a dynamic web page which is already written in languages such as PHP, Perl, ASP, JSP, ColdFusion, etc.


What I do is create a shell script file and utilize OS' pipe function and a text browser to create the HTML file.


For example: create a text file called generate.sh

lynx -source http://someURL.com/yourCode.asp > yourStaticASP.html
lynx -source http://someURL.com/yourCode.php?Var=123 > yourStaticPHP.html

and do a chmod on the file, make sure it is executable, e.g., chmod u+x generate.sh

You may then schedule this script file in your cron table ;-)

How do I use a hyperlink to POST form variable?

How do I use a hyperlink to POST form variable?

<form name="aform" action="somewhere.php" method="post">

<input type="hidden" name="firstName" value=" <?php echo $firstName ; ?> ">

<input type="hidden" name="lastName" value=" <?php echo $lastName ; ?> ">

<input type="hidden" name="section" value="0">

</form>


Simply add a little JavaScript somewhere in the <head> ... </head> part of your page and we're done. The JavaScript would look something like this...



function clickpost(param)

{

document.forms.aform.elements .section.value = param;

document.forms.aform.submit;

return true;

}

Javascript download script

<script language="JavaScript" type="text/javascript">

<!--

function beginDownload() {

idl = -1;

idl = location.search.indexOf("idl=n");

if (idl < 0) document.write('<iframe height="0" width="0"

src="PUT_URL_FOR_DOWNLOAD_FILE_HERE"></iframe>');

}

window.onLoad=beginDownload();

//-->

</script>

Some useful regular expressions...

e-mail (?:(?:\b([_a-z0-9-]+(?:\.[_a
-z0-9-]+)*)@([_a-z0-9-]+(?:\.[_a-z0-9-]+)*)\.(?:[a-z]{2,3})\b))

HTML tag (?:(?:<[^>]+>))
HTML start (?:(?:<[^//][^>]*>))
[HTMLEndTag] (?:(?:]+>))

[QuotedString] (?:(?:[\"](?:(?:[\\][\"])|[^\"]){1,}[\"]))
IP addr
(?:(?:\b([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\b))

Credit Card (?:(?:(\d{3,4})[- ]?(\d{4})[- ]?(\d{4})[- ]?(\d{4})))
HyperLink
(?:(?:(ftp|http|https|telnet|gopher|nntp)://([_a-z\d\-]+(?:\.[_a-z\d\-]+)+)((?:[_a-z\d\-\\\./]+[_a-z\d\-\\/])+)*))

How Do I get row number with SQL commands in MySQL?

Let's suppose we have a table look like this



Name PhoneNumber
-------------- --------------------
Peter        415-895-5689
John         408-854-4587
Louis        408-975-5986


And now I want to issue a SQL command which gives back a row number for each record which would look like this


RowNumber Name PhoneNumber
----------------- -------------------- ---------------------
1   Peter        415-895-5689
2   John         408-854-4587
3   Louis        408-975-5986


Under Oracle, this would be simple task, just issue the following SQL command
SELECT rownum, Name, PhoneNumber from table;
However, MySQL does not offer such convinience as rownum. In MySQL, we need to do the following instead.

mysql> SET @rownum := 0;

mysql> SELECT @rownum := @rownum + 1 AS RowNumber, Name, PhoneNumber from table;

Hope this tip can help you solve your current problem :)