Jump to content

Yahweh

Members
  • Posts

    186
  • Joined

  • Last visited

Everything posted by Yahweh

  1. Is 51,5100 a floating point number? (Is it equal to 51 + 51/100?)If so, you can get the format like this:System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-DE");help = String.Format("{0:#.##}", 51.5100);label3.Text = help; You can format to a specific culture with this handy dandy culture chart.
  2. Yahweh

    Replace " with '

    No, you use a double-quote twice like this:response.write (replace(var1, """", "'"))
  3. Yahweh

    Replace " with '

    HTMLEncode it instead:<input type="text" name="something" value="<%=Server.HTMLEncode(var1)%>" />
  4. Yahweh

    Using Random Strings

    Its a lot easier to work with an ArrayList, and a lot more efficient because you only have to loop through the elements of the ArrayList once to generate a random sentence.Here's some code that will do the job:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim cArray As New Collections.ArrayList Dim sBuilder As New System.Text.StringBuilder For Each sItem As String In ListBox1.Items cArray.Add(sItem) Next Dim iCounter As Integer, iIterations As Integer Dim myRandom As New Random, iRnd As Integer iIterations = cArray.Count - 1 For iCounter = 0 To iIterations iRnd = myRandom.Next(0, cArray.Count) sBuilder.Append(cArray(iRnd)).Append(" ") cArray.RemoveAt(iRnd) Next Label1.Text = sBuilder.ToString End Sub It works like this:- All the elements from the listbox are shoved into an ArrayList.- The program loops through the ArrayList, selects a random item, appends it to a stringBuilder, then removes that item from the ArrayList.-- Because I'm using an ArrayList, the array indexes are automatically "reset" whenever I remove an item, so there aren't any gaps in list when I remove something from the middle of the list.- After looping through everything, the stringBuilder is printed to screen.
  5. Yahweh

    ASP / PHP

    No offense, but those are hysterically awful criticisms of ASP. Believe me, there are a lot of good reasons to criticize ASP, such as its lack of Try-catch blocks for error handling, absense of namespaces, dependence on COM objects for important tasks like file uploading and encryption, pathetic OOP support, inadequate support for dynamically including files, absence of datatypes, and the fact that its a dead language, but the authors of those sites evidently have no idea what they are talking about.Just a few random samples from the first link: Really? Fortunately, ASP programmers aren't forced to learn C# when they make the switch to ASP.net, they can use VB.net instead. C# and VB.Net are identical languages, built on the same framework, but they have a slightly different syntax; C# has the familiar C-syntax, VB.Net has the familiar BASIC syntax. Its up to the programmer which one they prefer... actually they could mix C# and VB.net classes in the same application if they wanted.I regularly program in both syntaxes: I use VB.Net for web development, and C# for XBox 360 development. I have a preference for VB.net because its a little easier to read, and it lets me declare functions with optional parameters. Unless the author has a different definition of "native support" than I do, he is absolutely and totally wrong. ASP actually doesn't "natively" support any databases, it connects to databases through a middle-tier language called ADO using ODBC drivers, which allows it to connect to literally hundreds and hundreds of databases, it can even connect to Excel documents and flat files. Yes, Access is terrible, but what does that have to do with ASP? Wouldn't the same criticisms apply to PHP if people wrote PHP applications with an Access backend? The truth is, the quote above is a non-criticism, because Microsoft does not expect anyone to actually develop large websites with Access, and there is no formal requirement to use SQL Server. In fact, major ASP and ASP.Net hosts like Brinkster.com and M6.net offer MySQL as a database option; usually, if you're willing to pay $2 a month more for hosting, you can upgrade to an SQL Server database.While the author is very enthusiastic about MySQL, I think its a terrible database. I don't like it because it requires more maintanence than any other database I've ever used: MySQL servers are notorious for going offline, MySQL frequently corrupts table indexes. Its a good database for small to medium-sized sites, but its unsuitiable for sites with more than 20,000 hits per day. Its not as fast as Oracle and SQL Server.If you want MySQL for large-scale projects and high traffic websites like Wikipedia, then you have to pay $$$$$ for a MySQL AB or MySQL Enterprise license (both of which are closed-source and roughly the same cost as SQL Server). I've written scripts in ASP and PHP, and PHP seems a little faster. Both ASP and PHP seem to produce database output at the same pace, with minor edge given to PHP. ASP is definitely superior at processing large arrays because it uses traditional sequentially indexed arrays, but PHP doesn't actually use real arrays, its actually uses an associative array where each element in the array is actually a key/value pair. Long story short, it means ASP can perform array lookups in O(1) time, and PHP "arrays" perform lookups in about O(log n) time.Generally, ASP applications aren't written very efficiently, especially when it comes to pumping out information from a database. A typical ASP application looks something like this:Dim Conn, RSSet Conn = Server.CreateObject("ADODB.Connection")Set RS = Server.CreateObject("ADODB.RecordSet")Conn.Open some_connection_stringRS.Open "Select * from table", conn, 1, 1 do until rs.eof Response.write RS("field1") Response.write RS("field2") Response.write RS("field2") rs.movenext loopRS.CloseConn.Close That's extremely slow, especially if you need to perform things like random access.However, ASP lets you dump the results of a database query into an array, which is MUCH faster to process than using the recordset object: Dim Conn, RS, arrDataSet Conn = Server.CreateObject("ADODB.Connection")Set RS = Server.CreateObject("ADODB.RecordSet")Conn.Open some_connection_stringRS.Open "Select * from table", conn, 1, 1 arrData = rs.getRows()RS.CloseConn.CloseDim IFor I = 0 to uBound(arrData, 2) response.write arrData(0, I) response.write arrData(1, I) response.write arrData(2, I)Next The code looks a little more complicated, but its about 1.5x faster than the first method. Another method, the getString() method, is about 3x faster, but its not as easy to use. Both getRows and getString methods outperforms PHP's capacity to churn out database results, and they DEFINITELY outperforms PHP's capacity dump database contents into an array and print them to screen.Unfortunately, you never see tutorials on using the getString and getRows methods, because those techniques aren't very newbie friendly, but if you use them, then your ASP applications process as fast or faster than any equivalent PHP applications.On the second link, most of the criticisms are identical to the criticisms above (so I won't bother to repeat everything I've said above), but it makes one remark that deserves comment: VBScript is the default syntax for Classic ASP, but ASP programmers can use the C-like JavaScript syntax if they like by adding the <%@ Language="JavaScript" %> directive to the top of their page.I generally agree with people that PHP is a better language than Classic ASP, but you won't find an explanation for why PHP is better in the articles posted above. At the moment they said ASP only supports Access and SQL Server, it became readily evident that the authors don't actually have a lot of experience programming in ASP, if any at all. Anyone can use MySQL and ASP perfectly fine, a lot of websites already do, including my own website (FSTDT.com) which is written in ASP and uses a MySQL backend.
  6. Yahweh

    ASP / PHP

    None, really. The major advantage of PHP is its cross-platform support and builtin functions for MD5 hasing, file uploading, image manipulation, etc. ASP doesn't have native support for any of those, instead it relies on the use of COM objects which are developed by independent programmers. Although most COM objects cost $$$$$, all major ASP hosts include at least the following COM objects for free:- ASPUpload, used for uploading files.- ASPImage, used for dynamically generating and manipulating images on the fly.- ASPHttp, used for sending HTTP requests and generating custom headers. (I'm not sure what the advantage is to using ASPHttp over XMLHttp that's is included by default in all ASP installations)- ASPEmail, helps to send emails.- ASPEncrypt, generates MD5, SHA1, SHA512, hashes and PGP encryptions.Fortunately, ASP.Net includes namespaces for all of those functions lacking in Classic ASP. If you have to make a choice between PHP and Classic ASP, choose PHP; if you have to make a choice between ASP.Net and anything else, choose ASP.net.ASP and PHP can do basically the same things with the same efficiency. There are some considerations to make:- ASP is only supported on Windows, but PHP has cross-platform support with Windows and Linux. For most web developers, that doesn't make a difference, because they are hosted by 3rd parties like Brinkster and GoDaddy, so they never have to touch the servers. However, if you do have to touch the servers and configure them yourself, then I recommend using Windows for its user-friendly interface. Configuring servers in Linux, especially in command line, is extremely difficult. I'd also recommend IIS for the sake of being able to run .Net applications in addition to Unix applications as wel.- Unless you are purchasing your own servers, it doesn't make a difference that Windows costs $$$$ and Unix is free. Generally, in ASP vs PHP discussions, people like to bring up the fact Linux servers are free, but the vast majority of web developers don't own their servers, most web developers contract to a 3rd party host. For people who own their own servers and who actually intend to service 100s or 1000s of concurrent connections a day, the real cost of web hosting has nothing to do with the software, the cost has everything to do with renting OC-3 cable for $2000/month.- ASP doesn't actually cost money in and of itself, it comes packaged with Windows. If you're smart, you can actually develop with ASP and ASP.Net without ever having to pay a single penny for software. The latest version of the .Net framework is available for free on Microsoft.com, and all of the "express" editions of Windows software are free, which include Visual Web Developer, C# Express, VB.Net Express, C++ Express, J# Express, SQL Server Express, and a few others.Visual Studio.Net costs about $200, but theres no point buying it when the express editions are available for free. I've used VS.net and the express editions extensively, and they are identical. (There is only a single difference: the express editions only let you create applications in a single language, so if you wanted to create something in C#, then you have to open C# Express; if you want to create something in VB.net, then you have to open VB.Net Express. VS.net is nothing more than all the express editions rolled up into a single piece of software, it lets you create applications in any of the .Net languages; if you want to create something in C#, then click "Create a new C# application"; if you want to create something in VB.net, you click "Create a new VB.Net application".)- Although people like to poke fun at Microsoft for security issues and stability issues, those criticisms are a holdover from IIS 5 (which is about 10 years outdated). The latest Windows server is IIS 6, which is widely recognized as one of the most secure and stable servers in the world, even surpassing Apache. If you don't believe me, you can look at the figures yourself:-- Apache 1.3 - 19 vulnerabilities since 2003, 1 still open-- Apache 2.0 - 33 vulnerabilities since 2003, 3 still open-- Apache 2.2 - 3 vulnerabilities since 2003, 1 still open-- IIS 5.x - 14 vulnerabilities since 2003, 2 still open-- IIS 6.0 - 3 vulnerabilities since 2003, 0 still open- In terms of script security, some sites are made insecure by poor programming. But PHP seems to invite security problems, and it has a notorious history of security holes, especially with newbie friendly features like register_globals and "magic quotes". Somes web hosts even ban the use of PHPbb forums due to persistent security problems.In my opinion, between learning Classic ASP and PHP, the only smart move to make is to learn PHP which is still being actively developed and used today, while Classic ASP is basically a dying language.
  7. VB6 and Classic ASP use different syntax for opening files. To open a file in ASP, use this code:<%dim fs,f,xset fs=Server.CreateObject("Scripting.FileSystemObject") set f=fs.OpenTextFile(Server.Mappath("aaa.dat"),1,false)x=f.ReadAllf.close Response.Write("The text in the file is: " & x)%>
  8. Yahweh

    SELECT problem

    SELECT d.nameFROM Doctor dLEFT JOIN Patient p ON (d.name = p.name)WHERE d.specialization = p.illness
  9. Yahweh

    Small Asp Error

    Either your database, or the folder where your database is located doesn't have write permissions. CHMOD both of those to drwx------ (700).If you can't CHMOD them, go into IIS and set the file permissions for yourself, or ask your host to do it for you.
  10. Rand() and Limit 5 are specific to MySQL.The equivalent query in SQL server looks like this: That method isn't very efficient if you have 100s of 1000s of records, because it will have to create a NewID() for each record before returning the top 5.To return a single record, there's a little more efficient way:- Get the maximum uniqueID in your table, store that information in a variable called MaximumID- Multiply MaximumID * rnd(), store that information in a variable called RandomID- Select the first record with an ID >= RandomIDIn T-SQL:declare @MaximumID int = Select Max(ID) from table1declare @RandomID int = Rand() * MaximumIDSelect Top 1 * From table1 where ID >= MaximumID Or, you can always do what Microsoft suggests and create a table with random columns already in the table definition.
  11. Officially, it doesn't really matter where you put the code. It can be above all other HTML, after all other HTML, or at any arbitrary point in between. However, as an unwritten rule of thumb, its best to group all of your ASP code into functions at the top of the page to seperate code logic from presentation and prevent excessive spaghetti code. My best advice is this: don't learn Classic ASP. Its a dead language now. Learn ASP.Net because the future of all web development is moving in a .Net direction, .Net is 10000000x more powerful than ASP*, and you'll waste too much time struggling in the future if you don't learn ASP.Net as soon as possible.* Classic ASP is really lacking in many important features, such as being able to generate MD5 hashes, file uploading, and image manipulation; to be able to get any of those functions, you have to write 100s of lines of custom code. ASP.net natively supports all of those functions (and 1000s more) in various namespaces, you can invoke any of those functions in 1 or 2 lines of code. ASP.net also has real datatypes, real page and control events, native support for XML and user memberships, etc.
  12. Yahweh

    sql question

    vit4ek,The error doesn't occur on index.php, because none of the queries on index.php correspond to the error message. The error is located somewhere on one of the include files.I hate to say it, but I don't think anyone is going to be able to help you. Its notoriously difficult to fix problems by copy/pasting an error without seeing the code, its even more difficult to diagnose the error without any line numbers, its even more difficult when 100s of lines of code for an entire page are copy/pasted without formatting or indentation, and its outright impossible to fix errors without seeing the code for right page where the error actually occurs.In spite of all of that, I think I know the cause of the error: There is a column in the table called "Date", but date() is a reserved word in MySQL. MySQL can't tell the difference between a column called date and the date() function; it presumes that the author wanted to use the date() function, but without the parentheses on "date()", MySQL throws a syntax error.To tell MySQL to assume "date" is a column rather than a function, you have to surround the column name by a pair of "`" marks, or write out the fully-qualified name of the column in [table].[column] format, like this:Select * from some_table where `date` + interval 7 day > now();-- alternativelySelect * from some_table t where t.date + interval 7 day > now(); Its up to you to find all the instances of the "date" column appearing without "`" marks and fixing it. Start here and here.
  13. If you need the HTML before processing the ASP, then you can read a text file stored on your server with a FileSystemObject:<%Set fs=Server.CreateObject("Scripting.FileSystemObject")Set f=fs.OpenTextFile(Server.MapPath("some_file.asp"), 1)Response.Write(f.ReadAll)f.CloseSet f=NothingSet fs=Nothing%> If you need the HTML after processing the ASP (I presume that's what you mean by "output source"), then you can read any web page with a an XMLHTTP object: <% Dim objXMLHTTP, xml Set xml = Server.CreateObject("Microsoft.XMLHTTP") xml.Open "GET", "http://www.somewebsite.com/" xml.Send Response.Write xml.responseText Set xml = Nothing%> Rather than response.writinging the data to the screen, you can save it in a variable and work with it some more.
  14. Yahweh

    ASP and XML

    You have to create an XMLDOM object. Learning how to use it is a bit involved, but a good tutorial on reading XML with ASP is available here:http://www.15seconds.com/issue/990527.htm
  15. Step 1: Create a piece of software that crawls pages on the internet.Its probably easiet to create some kind of desktop application to do this. A crawler basically looks at the HTML of a page, indexes the page, extracts all of the URLs, and repeats the process indefinitely. In .Net, you can create a crawler in a few lines of code.Step 2: After creating your crawler, you have to index your data. You can store the data in a database, flat files, or other storage medium. You should choose whether you index the entire page, specific keywords or other information.Step 3: Write server-side backend to execute search queries on your index and display the results.That's the gist of it for a very simple search engine. You can write all of the necessary software for your search engine in less than 400 lines of code (~120 for the crawler and indexer, ~300 for the search page). It won't be any good, but it'll be a genuine search engine.If you don't know how to write desktop software or server-side languages like PHP or ASP.Net, then you won't be able to create a search engine.
  16. ASP Fundamentals:Anything wrapped in the <% ... %> tags is processed server side, that's where all of your form processing takes place. Anything outside is printed to screen, just like a normal HTML document: <%' stuff in this block will be processed by the server%><!-- stuff outside of the block is boring old HTML --> Conditionals in ASP look like this: <% If condition = true then'... do stuffEnd if %> To read form data, use: Request("someFormData") So, putting it all together: <%if Request("frm_toemail") <> "" then ' do all of your form processing here%> Put all of your HTML here.<%else 'abort page%> Put an error message here.<%end if%>
  17. Oops, that should have said:Set Matches = regex.Execute(data) Matches is an object, so you have to use "Set" with it.
  18. Yahweh

    ASP wierdness

    I've had strange experiences with ASP as well: in one case, the code was perfectly fine, but it wouldn't retrive values from the database. I fixed the problem by saving the data into a new file, and mysteriously the identical code would work just fine.For your example, I don't see anything out of the ordinary with the code, unless you've misspelled a variable somewhere (I would imagine that you are like me, and use <% Option Explicit %> at the top of every page). I think the obvious difference between the loop and your code is scope: the loop uses the recordset in global scope, and the variables are assigned from functions which make a reference to your recordset (I assume fromrs and cb_fromrs are functions). You can check if that's the case by assigning your variables directly from your recordset:FORMS_RECORDSET.open("select * from content where cid = '" & fromget("cid") & "'")cid = FORMS_RECORDSET("cid") 'don't need to use fully qualified rs.fields(something).valuetitle = FORMS_RECORDSET("title")description = FORMS_RECORDSET("description")tid = FORMS_RECORDSET("tid")'... That's just my guess, but if that works correctly, then maybe the error in your code is a variable scope issue.
  19. I found a nice article on 4Guys which explains how you can create your own custom control for rollover images.
  20. Odds are, there is some kind of buffer limit, probably 64kb, that you can write to a text file at any given time. If that is the case, then the simple solution to your problem is writing your data is smaller chunks, rather than all at once. You can split your data into fixed-sized chunks using a simple regular expression, then you can write your data chunk by chunk as you loop through the matches collection:Dim regex, match, matches 'regex variablesdim fs, f 'text file vars'creating a text fileset fs=Server.CreateObject("Scripting.FileSystemObject") set f=fs.CreateTextFile(Server.Mappath(someFileName),true) 'create regexp object and set properties set regex = new regexp regex.IgnoreCase = True regex.Global = True regex.Pattern = "[\s\S]{1,10000}" 'matches *at most* 10000 characters at a time 'I'm using "[\s\S]" rather than "." as a convenient way to match newline characters. 'Create matches collection to parse data into managable 10000-character chunks Matches = regex.Execute(data) 'Loop through matches collection for each match in matches 'writing each chunk to the file f.write(Match.Value) nextf.close'cleaning upset regexp = nothingset f=nothingset fs=nothing
  21. Just wondering, but in what context would you ever need to execute a query like that?First, to speed up your query, you probably shouldn't use "Select *" unless you actually need to return all the columns in your table. If your table has 12 columns, but you only need to use 1 or 2 of thsoe columns, then you're just wasting processing time. You should directly specify which columns you intend to use, that way you return the minimal of data.In any case, I think the query could be speed up with some slighly convoluted programming work-arounds. Generally, in order of speed, the % operator is the slowest (especially on integers, because it has to cast integers as a string before they can be compared), followed by the > and < operators, followed by the BETWEEN operators, and finally the = operator. Based on your query, your best bet to improve the speed is creatively using the BETWEEN operator.If you know how many records are in your database, then you know how many digits you have to work with, then you can pad your search string with 0s until it matches the number of digits in your records. For example, because 137827 contains 6 digits, you would pad 05 with 0s until to match 6 digits resulting in 050000. Now, you can run your query in one of two ways:-- First method, just find all records with an ID greater than some valueselect * from MyTable where id >= 050000;-- Second method, the BETWEEN operator is slightly faster than the the ">" operator,-- so you can specify finding any records between a minimum value and an-- arbitrarily large value.select * from MyTable where id BETWEEN 050000 AND 99999999; Either of those optimizations should be significantly faster than using a "%".
  22. I don't know exactly what you're trying to do, but it looks like you're trying to check that your record exists before you update it. You don't need to do that, its a superfluous step. Also, you don't need to use the strtolower function, because MySQL is case-insensitive by default.The entire block of code in your opening post can be replaced by executing this SQL statement:UPDATE `Checking` set `Site` = `Site` + 1 WHERE `Site` = $_Post['site'] If you only want your Site column to equal 0 or 1, then you can alter your query very slightly with MySQL's built-in Sign() function: UPDATE `Checking` set `Site` = Sign(`Site` + 1) WHERE `Site` = $_Post['site']
  23. Yahweh

    sql editor

    NotepadOr, if you're a little more adventurous:Notepad++ - I use this one all the time.
  24. Yahweh

    Table - one or more

    That's really a trivially small amount of data. Just for comparison, 800+ records are added to one of my tables on one of my sites everyday, and as of right now it contains 207000+ records. Queries on that table using the primary key execute in a few microseconds, queries using a fulltext index execute in 4 or 5 seconds. MySQL can handle 650 rows, believe me. Its best to put all of your related data in a single table, rather than creating multiple tables, simply for the sake of being able to run queries and generate reports much more easily.As long as you know how to create your table properly, and make efficient use of indexes, then you shouldn't have any problem with your table even with millions and millions of rows in it.
  25. I recommend method 1, even if it means having redundant data, because if you wanted to display a user and the last login time in the same query, you'd need a really awkward join:Select u.user_id, u.user_name, Max(l.last_login)FROM User_table uLEFT JOIN Login_table l ON (u.user_id = l.user_id)GROUP BY u.user_id, u.user_name Aggregate functions and joins on huge tables are murder on a database, and your site will begin to slow down over time to the point where it no longer wants to function at all.I have a website that works somewhat like a blog: articles are posted, and people can make comments to the article. Articles are stored in their own table, comments are stored in another. I wanted to include a link to the most recent comment, so I had to use a join somewhat like the one above, but after 20 000+ articles, and 100 000+ comments, queries kept timing out. I eventually added a "last_comment" field on my table, and it *dramatically* increased the speed of my queries.If you just add another field, you gain a lot of performance: SELECT user_id, user_name, user_last_loginFROM user_table;
×
×
  • Create New...