Jump to content

Yahweh

Members
  • Posts

    186
  • Joined

  • Last visited

Everything posted by Yahweh

  1. 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.
  2. 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)%>
  3. Yahweh

    SELECT problem

    SELECT d.nameFROM Doctor dLEFT JOIN Patient p ON (d.name = p.name)WHERE d.specialization = p.illness
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. 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.
  9. 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
  10. 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.
  11. 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%>
  12. Oops, that should have said:Set Matches = regex.Execute(data) Matches is an object, so you have to use "Set" with it.
  13. 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.
  14. I found a nice article on 4Guys which explains how you can create your own custom control for rollover images.
  15. 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
  16. 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 "%".
  17. 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']
  18. Yahweh

    sql editor

    NotepadOr, if you're a little more adventurous:Notepad++ - I use this one all the time.
  19. 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.
  20. 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;
  21. The WHERE clause is superfluous increases unnecessary overhead if you're trying to select all records. Do this instead:SELECT * From Unsnooped ORDER BY Sitecode ASC I don't use Access a lot, but I'm pretty sure your problem traces back to MS Access' handling of nulls. A null is not the same as an empty string, so if one of your RegionCode, ClinicGroup, or Snooped fields contains null data, it won't be returned in your dataset.
  22. 1. You can't change a page on your computer and hope that the page on your webserver is changed with it, you have to save your new page on top of your old page.Or, if you write database driven websites, such as a blog, then changes to your site occur automatically as you alter your database, so you can make changes to your site without having to upload new pages all the time.2. The best tool is a text editor. Notepad is the canonical tool among web developers (it was the first tool I ever used), but I like Notepad++ which is strictly a text editor with a few widgets like syntax highlighting, auto-indent, and tabbed browsing for editing multiple files at the same time.If you're building a site in .Net, then you must use Visual Web Developer. Otherwise, .Net is going to be really really hard.3. Brinkster is a good free Windows host, although they make their free hosting very difficult to find on their page. I don't know of any good free PHP hosts.You should know ahead of time that virtually all "free" hosts will put ads on your site. You will not find a decent free host that is ad free.If you want good hosting, you have to pay for it. But, until you actually know what you're doing and your website starts getting popular, then Brinkster free hosting will work just fine.Fortunately, the difference between free hosting and pay hosting is extremely cheap. With free hosts, you're lucky to get 100 MB of space and 1 GB of bandwidth, you'll have ads or popups inserted into your pages, and the URL to your page will look something like http://username.somehost.com. For $5 a month, you can get 200 GB of space, 3000 GB of bandwidth, no ads, a domain name, all sorts of add-ons like free support and databases, etc. Free hosts are essentially worthless compared to what you can get for a trivial $5 or $10 a month.4. There isn't one. The best free forum is the one that you can write yourself. I wrote my own software and couldn't be happier with it. Some people suggest PHPbb, but I hate PHPbb with a passion, it embodies everything in shoddy web design.I recommend avoiding forums for now. First, because if you don't even know how to upload pages to a server, and don't know anything about programming server side languages, then you're going to have a helluva time administrating a forum. What would you do when MySQL starts generating inexplicable glitches as it frequently does? What do you do when someone wants you to change some code? Second, because free hosts don't give you the amount of space or bandwidth needed to run a successful forum.
  23. The best way to learn to program is picking up a book and going through examples page by page.I learned Visual Basic 5 a long time ago by flipping through a textbook, I learned the language in less than a month. I didn't learn the language especially well because the book wasn't comprehensive, it didn't cover many important things like API calls and it didn't make things object abstraction seem very important.I learned HTML the same way, by picking up a book and going through it page by page. I picked up the language in a couple days, mastered it in a week or so.I learned ASP and SQL by trial and error, by reading tutorials on the internet. That was a bad idea. I was very fortunate to already know the VB language, but it literally took me years to become proficient at ASP. I learned ASP by setting my goals too high: I downloaded an ASP messageboard and modified the contents, and I picked up A LOT of bad programming habits because the board I modified was very poorly written. I know ASP as well as any professional, but it took me MUCH longer to learn the language than if I'd picked up a book.I learned VB.Net/C#t in the process of getting my degree in Computer Science. I learned next to nothing in my classes, it was a review of Visual Basic. I learned trivial things like connecting I learned the String.Format method, but I learned those from other students. I've been learning ASP.Net, which is distinct enough from application programming that its rightfully considered its own language, but I've not been able to find any comprehensive books on the subject, so I'm learning by trial and error, and although I'm very good at it, I think it will be a long time before I'm proficient.I learned Java and C++ from college, and my experience in college was invaluable because I would have never learned the languages by guess-and-test.More than anything I recommend borrowing a book from the library and learning how to program on your own. Books of those sorts gently guide you into a subject in and organized way than most internet tutorials. Additionally, when you have to type code from a book to your computer, you're actually internalizing the language rather than being a copy/paste script kiddy. Its possible learn things from the internet and become very good, but unless you're already a seasoned pro and just looking up a new technique for building tree data with SQL or dumping the results of a query into an array, then you're only going to slow yourself down by trying to learn a language from the internet.
  24. Yahweh

    PHP vs ASP.NET

    I programmed in PHP a long time ago, back in the early days of PHP3 and PHP4.PHP is good because its easy to install, its cross-platform compatible, and its free.It lets newbies connect to a database in a single line of code with its mysql_* family of functions, but as a consequence it lacks a data abstraction layer such as ADODB or <asp:sqlsource> found in other languages (I don't consider that good programming practice). It has some nuances that encourage bad programming habits, such as not requiring variable declaration before using them, lacking datatypes. It has some odd features like magic_quotes and register_globals that reduce code portability and open security holes. It also has some unintuitive typecasting, for instance:if ((string)"false" == (int)0) echo "true\n";// returns true for some reason To fix that problem, you have to use the triple equality operator, ===, which is just strange syntax.I made the switch from PHP to Classic ASP for a few reasons:- PHP variable don't need to be initialized before use. With ASP, you can force variable declaration by including <% Option Explicit %> at the top of every page. With .Net, you're required to declare variables before use.- PHP arrays are very slow, and software I write tends to be very array dependent. I learned a while ago that PHP arrays are really balanced trees that emulate an associative array, its a very different data structure than a linear array. An array is really a key/value pair, and $array[1] isn't the first element in an array, its a key/value pair where the key is "1". I consider that a disadvantage for two reasons. You get a little flexibility out of PHP's "array" syntax, but you pay a performance penalty. In Big O notation, php "arrays" execute in O(log n) time for any array lookup, whereas arrays in every other program execute in O(1) time (<--- best case performance). ASP and .Net arrays are linear arrays, so lookups occur in O(1) time.- Regex in ASP is easier.PHP has some major advantages over ASP when it comes to important functions like sending mail, uploading, manipulating images. With Classic ASP, you need to use COM objects for those purposes, which means you either have to buy those objects or hope they are included with your host. PHP's has those functions built in.I made the switch from ASP to ASP.Net for lots of reasons:- Code behind rocks. Less spaghetti code.- Compiled code helps to hide your source code from other developers who use your product. Compiled code also runs faster.- I write about 90% less code than I did before. Especially with VS.Net, I can create entire database-driven, AJAX-enabled sites without having to write a single line of code, those functions are encapsulated in the .Net controls.- Regex is EXTREMELY powerful: balanced expressions and named captures are a godsend. If you don't have a lot of experience working with Regex, or you've never tried to parse text with nested code, then you can't appreciate just how powerful the regex engine is.- Good XML support.- Try/Catch blocks are MUCH better than "on error resume next".- Lots and lots of namespaces for handling common functions like MD5 and SHA512 hashing, generic functions (similar to C++ template<t> structure).- Some web controls intrinsically support membership. The most challenging part of programming large websites is handling user accounts, user roles, security; .Net does it for you, and it saves you A LOT of time.- Very good object-oriented language, and the controls respond to events (like "click" events, "state changed" events, etc.).ASP.Net lets you use VB.Net, C#, J#, and a lot of other languages, but I prefer the Visual Basic flavor as my default language because blocks of code are easier to read than curly braces. A "}" can mean "end while", "end if", "end sub", "end function", but but "end if" only means "end if". Also, C#, for whatever reason, doesn't allow programmers to functions with optional / default parameters; that ability is maintained in VB.net. I like being able to declare optional parameters rather than a bunch of overloaded functions, so I stick VB.net for convenience and readability.There are a lot of plusses to ASP.net, and the future of all web development is moving in a .Net direction. So, saying that you know PHP and .Net looks good on a resume, but I generally think .Net is the best choice for developers.
  25. Yahweh

    URLEncode

    Ick. Double ick.Before you do anything else, learn to write HTML and ASP by hand. WYSIWYG editors are notorious for creating ugly, bloated code (and code, mind you, that doesn't format correctly in non-IE browsers). And don't use Access if you plan to have more than 5 users connected to your site at any given time, and don't use Frontpage if you plan to do any kind of serious web development. Apart from the 90% of useless junk generated by frontpage, nothing is wrong with the fragment you've posted.Two things come to mind:1) Check your database. If the data in your database is URLEncoded, then you have a problem with record input, not record output.2) Check your code. According to your code, you're displaying fields like this:<a href="http://<%=FP_FieldURL(fp_rs,"www")%>"> The function FP_FieldURL is outputting your data, its the piece of code that's formatting your data incorrectly. Find that function and comment out any line of code that says "someVariable = Response.URLEncode(someVariable)". That will format everything correctly, but just be aware that doing so is a security issue, it leaves you open to XSS attacks.If you don't want to edit your function, then here is a possible solution:The variable fp_rs is most likely a recordset. In that case, you can access your field directly. Try modifying your code to look something like this: <a href="http://<%=fp_rs("www")%>"> If that doesn't work, you have to edit your functions. If you're still having problems, post the code for function FP_FieldURL, and any other functions called from it.
×
×
  • Create New...