dman Posted July 24, 2005 Share Posted July 24, 2005 (edited) Yes, you are better spending time up front with db rather than waste hours editing html pages.Here is update for the stats to give you a little more example on things you can do. This includes total downloads and sorts by most downloads.<head> <title>File Download Statistics</title></head><body><?php// Connecting, selecting database$link = mysql_connect('localhost', 'root', '') or die('Could not connect: ' . mysql_error());mysql_select_db('dbname') or die('Could not select database');// Performing SQL query for total downloads$query = 'SELECT sum(count) as dlcount FROM dl_count';$result = mysql_query($query) or die('Query failed: ' . mysql_error());echo "<b>Total Downloads " . mysql_result($result,0,"dlcount") . "</b>\n";// Free resultsetmysql_free_result($result);// Performing SQL query for individual downloads$query = 'SELECT file, count FROM dl_count order by count desc';$result = mysql_query($query) or die('Query failed: ' . mysql_error());$num=mysql_numrows($result);// Printing results in HTML$i=0;echo "<table><tbody>\n";echo "<tr><th>Individual Downloads</th></tr>\n";while ($i < $num) { $fname=htmlspecialchars(mysql_result($result,$i,"file")); $fcount=trim(mysql_result($result,$i,"count")); echo "\t<tr>\n"; echo "\t\t<td>$fname</td>\n"; echo "\t\t<td>$fcount</td>\n"; echo "\t</tr>\n"; $i++;}echo "</tbody></table>\n";// Free resultsetmysql_free_result($result);// Closing connectionmysql_close($link);?> </body></html>Next question, one step at a time. First decide what info about the files you would like to present or track, eg. name, category, size, publisher, etc. Then we can make the database to reflect this data. That needs to be done before you can move on to the PHP. Edited July 24, 2005 by dman Link to comment Share on other sites More sharing options...
Xable Posted July 24, 2005 Author Share Posted July 24, 2005 thats good, not sure what Individual Downloads are?Name, Version and size thats all.got to go now though, need some sleep. I`ll be on 2morowseriously dman can`t thank you enough, your a star. Link to comment Share on other sites More sharing options...
dman Posted July 24, 2005 Share Posted July 24, 2005 not sure what Individual Downloads are? just something to call the list of files as opposed to the sum total. Call it anything you want.get some sleep Link to comment Share on other sites More sharing options...
Xable Posted July 24, 2005 Author Share Posted July 24, 2005 lol i see now it`s game over see ya Link to comment Share on other sites More sharing options...
dman Posted July 24, 2005 Share Posted July 24, 2005 (edited) Add this table to your databaseCREATE TABLE 'dlls' ('file' VARCHAR( 128 ) NOT NULL ,'size' VARCHAR( 20 ) ,'version' VARCHAR( 20 ) );If you want to make the size and version mandatory add NOT NULLIf you have a list of your files attach it and I will write a little util to convert it into SQL INSERT statements to load up the database. Edited July 24, 2005 by dman Link to comment Share on other sites More sharing options...
Xable Posted July 24, 2005 Author Share Posted July 24, 2005 (edited) Fully rested now, 1. What is a table? do the numbers define the widths of the cells?CREATE TABLE 'dlls' ('file' VARCHAR( 134 ) NOT NULL ,'version' VARCHAR( 138 ) NOT NULL ,'size' VARCHAR( 128 ) NOT NULL);2. What format does the list need to be in? Edited July 24, 2005 by Neanderthal Link to comment Share on other sites More sharing options...
dman Posted July 24, 2005 Share Posted July 24, 2005 (edited) a table is a database entity that is a group of related data items, like the file info all relates to the file. A database can have many tables, like yours will now have one for files to download, and one for download stats. Think of an HTML table with columns and rows... the columns are the data items you want to track, one row in the table for each record. hope this is clear, you could try reading mysql docs.a table column can have different data types. varchar is for strings, that is most common. could also be number, logical, date, etc. Yes, the number is the max amount of characters that column will hold. my numbers were just guesses, make it appropriate for your data.the list can be any text format, i will write util to read it. do you have a list, or still need to make one? Edited July 24, 2005 by dman Link to comment Share on other sites More sharing options...
Xable Posted July 24, 2005 Author Share Posted July 24, 2005 thats a little clearer thanx i will dive into the mysql docs when i get chance, i need to learn as much as i can.So if i use CREATE TABLE 'dlls' ('file' VARCHAR( 134 ) NOT NULL ,'version' VARCHAR( 138 ) NOT NULL ,'size' VARCHAR( 128 ) NOT NULL);the table will be the same as this Sorry i mean, like the format,like this; name, version, sizeAAAAMON.DLL 5.1.2600.0 25OrAAAAMON.DLL,5.1.2600.0,25Or (the easyest to put together)NameVersionSizeA3D.DLL2.9.0.096 Link to comment Share on other sites More sharing options...
dman Posted July 24, 2005 Share Posted July 24, 2005 (edited) The comma seperated values (name, version, size) would be easiest, but the sequential row listing would work also. (I use visual foxpro for this kind of thing, it has super file and string handling functions)Think maybe we should change "size" to numeric field so you can use it in stats for total bytes downloaded. The usual rule is to make numbers that will never need math done on them as varchar fields, like the version. Even though it is a number there is no math you can do on it. The size we can use to tally stats, so that can be numeric.CREATE TABLE 'dlls' ('file' VARCHAR( 134 ) NOT NULL ,'version' VARCHAR( 138 ) NOT NULL ,'size' INT( 11 ) NOT NULL); this will create numeric field of type "Integer" (whole numbers)run "drop table 'dlls'; if you already created it, this will delete current structure Edited July 24, 2005 by dman Link to comment Share on other sites More sharing options...
Xable Posted July 24, 2005 Author Share Posted July 24, 2005 visual foxpro! can`t find download link. is it just for msdn subscribers.i think it has to be the sequential row listing if you don`t mind, otherwise it`s a manual copy paste for each file.i`ll pm you a link to the list in about 10min. Link to comment Share on other sites More sharing options...
dman Posted July 24, 2005 Share Posted July 24, 2005 You have to buy VFP. It is great language, but MS is trying to kill it in favor of .NET. They are letting it die slowly by not porting it to 64 bit, but it is still very useful.If you already have the list in that format that is fine, I can read it. Link to comment Share on other sites More sharing options...
Xable Posted July 24, 2005 Author Share Posted July 24, 2005 sent check your pmbtw, i submitted the sql request it returnes this#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''dlls' ('file' VARCHAR( 134 ) NOT NULL ,'version' VARCHAR( 138 ) NOT NULL ,' at line 1 Link to comment Share on other sites More sharing options...
dman Posted July 24, 2005 Share Posted July 24, 2005 your list doesn't have version or size. need them too. Link to comment Share on other sites More sharing options...
Xable Posted July 24, 2005 Author Share Posted July 24, 2005 (edited) oops wrong one, try again. Edit,what about thisCREATE TABLE 'dlls' ('file' VARCHAR( 134 ) NOT NULL ,'version' VARCHAR( 138 ) NOT NULL ,'size' INT( 11 ) NOT NULL);is it right? Edited July 24, 2005 by Neanderthal Link to comment Share on other sites More sharing options...
dman Posted July 24, 2005 Share Posted July 24, 2005 (edited) not sure why thats not working. might have something to do with the quotes.try this (I tested this time). we are adding a primary key field, dont ask why yet, but we will use it to relate our different tables to one another.CREATE TABLE `dlls` (`pk` INT( 5 ) NOT NULL AUTO_INCREMENT ,`file` VARCHAR( 134 ) NOT NULL ,`version` VARCHAR( 138 ) NOT NULL ,`size` INT( 11 ) NOT NULL ,PRIMARY KEY ( `pk` )) Edited July 24, 2005 by dman Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now