dman Posted July 24, 2005 Share Posted July 24, 2005 (edited) Here is link to sql insert file.This is Foxpro code I used to convert, just in case you are interested...fh = Fopen("c:\list.txt")strout = ""Do While !FEOF(fh) strtmp = "INSERT INTO dlls (file, size, version) VALUES ('" strtmp = strtmp + Fgets(fh) + "', '" strtmp = strtmp + Fgets(fh) + "', '" strtmp = strtmp + Fgets(fh) + "');" + Chr(13) + CHR(10) strout = strout + strtmpEnddoFclose(fh)Strtofile(ALLTRIM(strout),"c:\dllinsert.sql") 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 nice thanxs, i would love to get my hands on Foxpro and have a fiddle.I hope you are going to let me know what i do with this file Link to comment Share on other sites More sharing options...
dman Posted July 24, 2005 Share Posted July 24, 2005 (edited) what are you using to administer your db? I am using phpmyadmin. Just open the file and select all/copy and paste into sql window and run, same way as you are creating the tables. or use "browse" button and select the file and run. 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 Ok done, yes phpmyadmin aswell. had never seem phpmyadmin untill last week. It all looks very complicated. Link to comment Share on other sites More sharing options...
dman Posted July 24, 2005 Share Posted July 24, 2005 (edited) It all looks very complicatedStart Small... Evolve. It all becomes very simple, you just need to reach critical mass and it will all make sense.Now look at the count.php page. Your list code will be very similar to this... open db, get recordset, loop through records creating a table row once per loop. that is basics, then we add the links for each letter, finally the paging code to show limited number of records per page... Edited July 24, 2005 by dman Link to comment Share on other sites More sharing options...
dman Posted July 25, 2005 Share Posted July 25, 2005 (edited) Just one quick note...You do not want to put any of this code on your live server until it is hardened up. Functionality first, then we harden it up, both the database and the PHP. Yes, believe it or not there are evil people out there that would love nothing better than to submit a SQL Injection attack and erase your database just for laughs, so test on local machine until it's done! If you do put it live make sure to back up often. Edited July 25, 2005 by dman Link to comment Share on other sites More sharing options...
dman Posted July 25, 2005 Share Posted July 25, 2005 (edited) This should get you started...<head> <title>Freedll.xyz</title></head><body><h1>Freedll.xyz</h1><?php// Connecting, selecting database$link = mysql_connect('XXX', 'XXX', 'XXX') or die('Could not connect: ' . mysql_error());mysql_select_db('XXXX') or die('Could not select database');// Performing SQL query$query = 'SELECT file, version, size FROM dlls order by file';$result = mysql_query($query) or die('Query failed: ' . mysql_error());$num=mysql_numrows($result);// Printing results in HTML$i=0;echo "<table border=\"1\"><tbody>\n";echo "<tr><th>File</th><th>Version</th><th>Size in kb</th></tr>\n";while ($i < $num) { $file=htmlspecialchars(mysql_result($result,$i,"file")); $version=trim(mysql_result($result,$i,"version")); $size=trim(mysql_result($result,$i,"size")); echo "\t<tr>\n"; echo "\t\t<td>$file</td>\n"; echo "\t\t<td>$version</td>\n"; echo "\t\t<td>$size</td>\n"; echo "\t</tr>\n"; $i++;}echo "</tbody></table>\n";// Free resultsetmysql_free_result($result);// Closing connectionmysql_close($link);?> </body></html>look at the code and read the docs about the various functions, soon you will see how to extend it.EDIT: don't know why the code always loses it's indents when I paste into forum code tag? Edited July 25, 2005 by dman Link to comment Share on other sites More sharing options...
Xable Posted July 25, 2005 Author Share Posted July 25, 2005 ye i did wonder about security, there are some pathetic idiots out there.gonna give that code a try now... Link to comment Share on other sites More sharing options...
Xable Posted July 25, 2005 Author Share Posted July 25, 2005 i`m a bit lost here mate, can`t find any docs to do with any of the functions! Link to comment Share on other sites More sharing options...
dman Posted July 25, 2005 Share Posted July 25, 2005 Here is PHP Manual. Else just google the function, you will turn up lots of hits. Did you get it to work? Link to comment Share on other sites More sharing options...
Xable Posted July 25, 2005 Author Share Posted July 25, 2005 it returns this when i open it;\n"; echo "FileVersionSize in kb\n"; while ($i < $num) { $file=htmlspecialchars(mysql_result($result,$i,"file")); $version=trim(mysql_result($result,$i,"version")); $size=trim(mysql_result($result,$i,"size")); echo "\t\n"; echo "\t\t$file\n"; echo "\t\t$version\n"; echo "\t\t$size\n"; echo "\t\n"; $i++; } echo "\n"; // Free resultset mysql_free_result($result); // Closing connection mysql_close($link); ?>i`ve been trying to find info on the functions to figure out if i have to configure something. the info in the link will help a lot i think. got to go for bout half hour, will check it out then. Link to comment Share on other sites More sharing options...
dman Posted July 25, 2005 Share Posted July 25, 2005 (edited) You shouldn't have to configure anything (assuming PHP is working) except change XXX to correct values and name the file "something.php"seems like it is not processing the PHP and just returning text. I just tried copying from forum and pasting into new file and it is working OK. Edited July 25, 2005 by dman Link to comment Share on other sites More sharing options...
Xable Posted July 25, 2005 Author Share Posted July 25, 2005 (edited) you are right it works, i was running it localy.but, the Version is showing under Size in kb and vice-versa. Also the versions are showing like this6instead of6.0.7.1709think it stops reading after the full stop. Edited July 25, 2005 by Neanderthal Link to comment Share on other sites More sharing options...
dman Posted July 26, 2005 Share Posted July 26, 2005 sorry, got the columns backwards. The version is getting cut off because it is trying to go into an integer column which doesn't accept decimal values. Fixed and reposted. Link to comment Share on other sites More sharing options...
dman Posted July 26, 2005 Share Posted July 26, 2005 (edited) OK, hopefully you got the db straightened out and had a chance to peek at the code a little. Here is next phase, alphabetical menus and page menus. I tried to put a lot of comments in the code, but if something is unclear I will add more.<head><title>Freedll.co.uk</title></head><body><?php// Create letter links// we are going to build a string that consists of the HTML needed to make our alphabet menu, then we are going// to output it to the HTTP stream using the PHP "echo" command$alphamenu="<table align=\"center\">\n<tr>\n";// this loop will repeat 26 times, one for each letter of the alphabet. each time through we use the chr() function// to create a letter, starting with chr(65), which is the ASCII code for capital "A".// The ".=" means append the string to the current string, $i++ tells the $i variable to increment once each loop// the "\t" and "\n" in the strings are not actually part of the code, they are used// to add a tab or newline to the output so the HTML output code looks pretty.for ($i = 1; $i <= 26; $i++){ $letter=chr($i+64); $alphamenu .= "\t<td><a href=\"index.php?folder=" . $letter . "&pidx=1\">" . $letter . "</a> | </td>\n";}// lastly we add the link for 0-9$alphamenu .= "\t<td><a href=\"index.php?folder=0&pidx=1\">0-9</a></td>\n";$alphamenu .= "</tr>\n</table>\n";// and finally write the string to the HTTP streamecho $alphamenu;// this value sets the number of rows we want to show on each page$pagesize=25;// now we make a connection to our MySQL database server$link = mysql_connect('XXX', 'XXX', 'XXX') or die('Could not connect: ' . mysql_error());// and open our databasemysql_select_db('XXX') or die('Could not select database');// next line checks if a "get" parameter was passed to the script. If it was, we set a variable named $folder to the value// of the dlls folder, and $pageindex to our starting point// If not it means someone has just entered the site and we set the page to "A-1"if (isset($_GET['folder'])){ $folder=$_GET['folder']; $pageindex=$_GET['pidx'];} else { $folder="A"; $pageindex=1;}// now we see if dll starts with a letter or 0-9 and set our SQL query to match.// We have set the parameter for 0-9 to "0" in our menu link// the query will give us a count of how many rows match the letter or 0-9 we use this to determine how// many pages worth there are to displayif ($folder=="0") { $whereclause = " LEFT(file,1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')";} else { $whereclause = " LEFT(file,1)='" . $folder . "'";}// and now we set up our query with the proper where clause inserted$query = "SELECT file FROM dlls WHERE " . $whereclause . " ORDER BY file";// now we run the query on the database$result = mysql_query($query) or die('Query failed: ' . mysql_error());// get the count from the recordset for the total number of rows$num=mysql_numrows($result);// now we divide the number of rows by our page size and round it up with the ceiling function to get number of pages$numpages=ceil($num / $pagesize);// here we start to build our output HTML string for our page menu// we loop here once for each page. each time through the loop we add the first three characters// of the file name at the top of the page to our menu.// the first line tells us not to create a page menu if there is only one pageif ($num > $pagesize){ $menucap = substr(mysql_result($result,1,"file"),0,3); $pagemenu="<table align=\"center\">\n<tr>\n"; $pagemenu .= "\t<td><a href=\"index.php?folder=" . $folder . "&pidx=1" . "\">" . $menucap . "</a></td>\n"; for ($i = 1; $i < $numpages; $i++) { $pos=($i*$pagesize)+1; if ($pos>=$num) { break; } $menucap = substr(mysql_result($result,$pos,"file"),0,3); $pagemenu .= "\t<td><a href=\"index.php?folder=" . $folder . "&pidx=" . $pos . "\">" . $menucap . "</a></td>\n"; } $pagemenu .= "</tr>\n</table>"; // write the page menu to HTTP stream echo $pagemenu;}// release the result set so we can use it for next querymysql_free_result($result);// now we set up the main query to retrieve our page worth of dlls$query = "SELECT file, version, size FROM dlls WHERE " . $whereclause . " ORDER BY file LIMIT " . $pageindex . "," . $pagesize;// now we run the main query on the database$result = mysql_query($query) or die('Query failed: ' . mysql_error());// and get the count$num=mysql_numrows($result);// create our main output string for the list table$i=0;$htmlout = "<table align=\"center\" border=\"1\"><tbody>\n";$htmlout .= "<tr>\n<th>File</th><th>Version</th><th>Size in kb</th>\n</tr>\n";while ($i < $num) { $file=htmlspecialchars(mysql_result($result,$i,"file")); $version=trim(mysql_result($result,$i,"version")); $size=trim(mysql_result($result,$i,"size")); $htmlout .= "<tr>\n"; $htmlout .= "\t<td>$file</td>\n"; $htmlout .= "\t<td>$version</td>\n"; $htmlout .= "\t<td>$size</td>\n"; $htmlout .= "\t</tr>\n"; $i++;}$htmlout .= "</tbody></table>\n";// write the table to HTTP streamecho $htmlout;// Free resultsetmysql_free_result($result);// Closing connectionmysql_close($link);// write the menus at the bottom of the pageecho $pagemenu;echo $alphamenu;?></body></html>Next we will add the links and the download code, then harden it up and finally make it all pretty.This page will then replace all of your HTML pages, along with the nightmare of keeping them updated and sorted correctly. All you need to do is make sure the data in your DB is correct and the code will take care of building the pages. EDIT: the CODE tag is stripping the indents out of the code making it much harder to read. BUG FIX: added break out of loop when last page is a full size page of data to prevent eof condition Edited July 28, 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