A Real Challenge For Real PHP Programmers
<?php /* A challenge to every PHP programmer.The one who's gonna solve this problem would be deemed as
PSP(PHP Supreme Programmer).The problem is this : You have to write a script that displays a list of
categories and subcategorieslike this one:
<select name="category"> <option value="1">Main</option> <option value="2">Main > Computers</option> <option value="4">Main > Computers > Hardware </option> <option value="8">Main > Computers > Hardware > PC</option> <option value="7">Main > Computers > Hardware > Mac</option> <option value="9">Main > Computers > Hardware > Atari</option> <option value="11">Main > Computers > Hardware > PC > History of Pc</option> <option value="">etc...</option> </select>
The categories and subcategories details are stored in these two tables in a MySQL database. -categories : the categories names and ids. -cat_relations : the relations between categories.It shows which subcategory belongs to which category. The belongings between categories can go very deep and the number of categories is unlimited. This script will create the two tables and fill them with sample data. All you need to do is to change the four variables below. You can send the script back to this email : yasbergy@yahoo.com. */
//Here starts the script. Please change the values of these variables to fit your settings $user = "prospective_PSP"; $database = "db"; $server = "localhost" ; $pwd = "" ; //Connection to the database that you created mysql_connect($server,$user,$pwd) ; mysql_select_db($database); //Creation of the two tables : categories and cat_relations $categories = " CREATE TABLE `categories` (`id` INT not null AUTO_INCREMENT, `name` VARCHAR(100) not null , PRIMARY KEY (`id`), INDEX (`id`), UNIQUE (`id`)) comment = 'The categories details' "; mysql_query($categories) ; $cat_relations = "CREATE TABLE `cat_relations` (`id` INT not null AUTO_INCREMENT, `daughter_id` INT not null, `mother_id` INT not null , PRIMARY KEY (`id`), INDEX (`id`), UNIQUE (`id`)) comment = 'Which category is the daughter of which category'"; mysql_query($cat_relations) ;
//Filling the two tables with sample data $cats = array('Main','Computers','Countries','Hardware','S oftware','Programming languages','Mac','PC','Atari','Winamp','History of the PC','IBM','Components','High level','USA','NYC','LA','Manhattan','India','Winzi p'); for ($i=0;$i<count($cats);$i++){ $sql = mysql_query("insert into categories (name) values('".$cats[$i]."')"); } mysql_query("insert into cat_relations (daughter_id,mother_id) values (2,1),(3,1),(4,2),(5,2),(6,2),(7,4),(8,4),(9,4),(1 1,8),(12,8),(13,8),(10,5),(20,5),(14,6),(15,3),(16
,15),(17,15),(18,16),(19,3)"); //Now you can have a look on them through phpMyAdmin ?>
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Getting The REAL Directory?
Is there any way to get the directory/path of the file running the script, not the directory you're inside (Via dir())? I'm allowing the user to navigate through directories, and that part works great - but whenever I attempt to used getcwd(), it returns the directory the user is in - not the directory of the php file - is there any way to get the directory of the .php file the user is using?
Real-time Output?
I'm a relative PHP newbie, so I apologize if this is a simple question. Anyway, here's my problem. I'm using a PHP script to pre-render a bunchload of insert files for an HTML page. Right now there's about 1,600, but that number could get much, much higher when the site goes live. I'll only need to re-render the whole batch once or twice a year (if that) but it's still something I'd like to be able to do in case I have to move the site to a different server, or there's a hard drive crash or etc. Basically what the script does is grab a whole bunch of information from a database and write the insert file. It does this for every single one. The problem of course, is that PHP by default does all this server-side, and then sends it to the browser. Because this process takes like ten or twenty minutes to do, the browser times out long before it's finished. Is there a way to get progressive output with PHP? Or do I need to re-do this in another language like Perl?
Real Length Of Arrays
Sometimes, I want to know how many elements are really in an array (php3). The count() and sizeof() functions apparently return the number of non-empty array elements, and if you do a while loop checking for empty will stop on the first empty element. I have been using the following function: function truecount($theArray) { if (is_array($theArray)) { end($theArray); return key($theArray); } } but if the key is non-numeric, won't that trip me up? Anyone have a better solution?
Md5 / Sha1 - Any Real Difference?
I use md5 hash with some of my cookies and occassionally a hidden form field - I know the physical data on my network is insecure (unless being served via https) but I was wondering if there are any advantages to using md5 over sha1 or versa vicea... I know md5 gives me a unique 32bit hash while sha1 I've read is 'secure' (?) and gives a 40bit hash... Since The technical webpage on sha1 is lengthy and for the most part over my head... and other than today, I've never heard of it before... I was wondering if anyone could offer any comments on it...
Real Time Chat
There's anyone out there that can give me a light on real time chat using sockets. I've seen some using push technics but they all hang up after an elapsed amount of time.
Htmlspecialchars/real Escape
I'm creating a BBCode parser, and everything's working but one thing; I need code tags, but I will need to real_escape/htmlspecialchars the post to make sure it isn't malicious. The only problem is if I real_escape with code tags that contain php, the php will be removed. If I specialchars the post with php, I can't have syntax highlighting (or, not easily). How do I get round this?
Real IP Address From Behind Proxy Or NAT
How to get the real IP address of a user, not that of their proxy server or the external NAT address. I was quite sure that this wasn't possible without some kind of process getting the address on the client machine. I have suggested that these sites could be using Java to get the real IP address, however, I could be wrong and for me the script that I found always returns 127.0.0.1 . This suggests to me that any script attempting to obtain the hosts real IP address infarct rely s on the HTTP-X-FORWARDED-FOR header sent by the proxy server...
Real Audio Download Limiter
i'm running a site with .ra and .ram files, when some visitor download or stream all these files at the same time it causes an huge bandwidth consumption. so i'd like to limit the download per each IP to a certain number of .ra and .ram files at time. i wonder if i can use some php script with cookies session but i'm new to this and i don't know where to start.
Real Time Echo'ing Of Var In A Loop
i have a big loop, and rather then waiting until its done for me too see what happened, every time it runs, how can i get the browser to echo the result, and proceed to keep running the loop. basically this loop takes a long time to finish, and i had to set my max runtime past 30 seconds. i guess incorporating a refresh of some sort like this would eliminate the need for the time extension too?
PHP Template Redirecting To Real Video
I've developed a RealVideo content management system w/ PHP and MySQL. On the back end is a form that sends a Real Video file (.rm) and writes the filename to a database. On the front end is a PHP template that pulls the filename from the database and outputs a string that is read in by a Flash movie. The Flash movie reads in the file location and places HTML-encoded text inside a text field that says "Launch Video." All works fine -- the Flash movie launches the Real Video file, and the file plays correctly. There's only one problem: the Real Video doesn't stream. In order for a Real Server to stream a Real Video file, a "stub" file with the extension .ram needs to be placed in the root directory. The only content in these .ram files is a URL pointing to the actual .rm file, and it's written in this format: pnm://ra.domainName.com/realvideoFile.rm My problem: The form is sending a Real Video file and the receiving page is copying it to the server as well as inserting a record into my database, but it can't write a .ram file to the root directory because to do so I'd have to adjust permissions accordingly (PHP is part of group Apache). That's unacceptable; I won't adjust permissions on the root directory. My solution was to create a redirector that acts as the stub file: PHP Code:
Real World Singleton Class Example?
Anybody can show me real world singleton class example? Something that works (is implemented) as part of working solution. Does it make sense to create database handler class that way?
Is Gmail Homepage Real Ajax?
I saw gmail's storage size on mail.google.com. It was counting size like "Over 2728.845439 megabytes". then increasing... but my dialup connection disconnected I don't understand howto count storage size, when my pc disconnected internet. is it real 2728.845439 MB? or only text?
Stripping Commas From Real Numbers
I have an HTML form in a PHP script which queries the user for a dollar amount of sales. If a user enters "1,000,000" rather than "1000000" for 1 million, PHP (or MySQL?) treats the commas as a decimal and "1" is entered in the database. A simple work-around is to simply advise the user "Please enter numbers only, no commas or $'s" but this seems awkward. Is there a built in function or another easy way to have commas and currency signs stripped out of form-entered data?
Exploding At Real Breaks Not Wraps
I am working on reading my pop3 email , and I am trying to return the header data using the function, I get this fine. The question I have is since there is no consistency to the rows, I want to take each row of data, not a wrap of a long line, any idea beyond checking if it has a : in it???
How Convert Http:// Text To Real Hyperlink?
I have some texts in MySQL databases. When I show this texts in webpages using PHP, I need to convert every ocurrence of http://blablabla.com to <a href='http://blablabla.com'>http://blablabla.com</a> , so my text will really became 'active'. The people who wrote the texts don't know HTML tags so I can't ask them to write explicity <a...> </a> commands. The problem is the same with text that contains the @ charactere, as name@mailserver.com . I have to change this to <a href='mailto:name@mailserver.com'>name@mailserver.com</a>. Please, I don't know how to use regular expression. I think It can make this replacemments very easy..
Checking If Email Address Is Live And Real?
There's all kinds of ways to validate an email address to make sure it's well formed and whatnot, but what about checking to see if it's a valid e-mail account? Like how you can use checkdnsrr() to check to see if a URL is valid. I know finger used to be used at one time, no? But server block finger requests, and I'm not sure many e-mail accounts out there are even fingerable type accounts anyway.
MySQL Result To Real Array In Function
I'd like to create a function which input is the result of a mySQL query. The output should be exactly the same, only not a mySQL result array, but a 'real' array. So it should also get the fieldnames returned by mySQL and use those as keys. I can't get things to work properly: it should return a multidimensional array, like $result_array[1] = array( [field1] => field1 value, [field2] => field2 value, etc. ) somehow my result is (with code below) $result_array[1] = array( [0] => field1 value, [field1] => field1 value, [1] => field2 value, [field2] => field2 value, etc. ) +++++ code ++++++ $get_res= mysql_query(QUERY); if( $res = mysql_fetch_array( $get_res ) ) { do{ $result[] = $res; }while( $res = mysql_fetch_array( $get_res ) ); }; foreach( $result as $key => $value ){ print_r($value); };
Real Good Content Management System ?
I'm getting somewhat annoyed about how many cms's there are in PHP/MySQL while so few are really good. Yesterday I started to like ezPublish, until I decided the template language is ugly and the process for creating a maintenance template for a content class is not logical. I'm starting to think I should write my own cms, but that will increase the leadtime for my site enormously. So I would like to know from you if you know a cms that .. - Is free and open source - Is PHP/MySQL based ( usable with just about any host ) - Doesn't enforce site/navigation structure - Has a WYSIWYG editor or one can easily be plugged in - Has a forum module - Is also an application framework with good separation of content, code and layout. - Does not have its own insane template language - Supports a moderation process for content - Has an intuitive process for creating maintenance forms for posting and maintaining content. I think Zope comes close, but that's Python :-(
Real Audio Http Streaming Without .ram File
I wanted a way to (http) stream Real Audio files without the need to use ..ram files. In case there are others interested in this, the following is the solution that worked for me: <?php Header("Content-Type: audio/x-pn-realaudio"); echo "http://www.domain.com/audiofolder/track1.rm"; ?>
Read Data From MS Access Into MySQL In Real-time
I am currently working on a project that involves reading information from a inventory system into Access via ODBC and display the info on the web site using MySQL. I would like to create a live link between the MS Access(local) and MySQL (remote) whenever the inventory system is updated MySQL will be updated as well. I know that MyODBC will let me do the opposite of what I would like to accomplish by reading data in MySQL into Access. Is it possible to do the reverse way.
How Can One Get Real Time Stock Quotes For An Online-community?
For one of our web-communities we plan an offer of real time stock quotes incl. advanced notification services. I have the following questions: - Do you know of any services, that already offers such services in a decent way? And more important: - Does anybody know a provider of such services, that offers a real-time stock quote data stream for such a usage at a decent price? I only know of Deutsche Börse offering it for 1駨 Euro per month. That is too expensive for us.
Dynamically Genetrate RAM (Real Media) Text Files
I am working on a record company's site. They offer a selection of track snippets for stream/download. I would like to be able to dynamically generate the RAM (text File) to save manual input in the DB. Currently each RAM file has to be uploaded everytime a new track is added....but I'd like to have this created on the fly when a user is browsing the site. user selects track...is forwarded to the dynamically generated RAM file...which in turn selects the appropriate media. I can't think how i'd get this to work as I am trying to create a text file that is parsed rather than a peice of HTML that is read by a user. Perhaps on the server I'd have to add PHP Parsing to the RAM mime type?
Converting TIMESTAMP Fields Into "real Time"?
Is there a code for converting a db field that is TIMESTAMP into "real time"? Meaning if the field is 2007-03-21 10:51:28have is output: "10:51 am", Or: 2007-03-21 13:51:28output: "1:51pm"?
Problems With Php Date/time - Real Time Clock
On my website i would like to have a real time clock....i mean to show seconds running one after another...how can i do this? Another problem is how to get time into a variable (which then i will insert into a database table)?
Mysql Fetch_field Gets Table Alias, Not Real Table Name
After a SQL 'select .... from tablename alias' the mysql_fetch_field function returns a value $result=>table which will contain the alias, not the actual table name. Is there a way to get the actual table name ? I am running mysql 4.1 and php 4.4
User's "real" IP Address
I log a user's IP address into my database once they have voted on a specific item. Before voting, it checks to see if their IP address is in the database for the item. This works fine, but there is a problem. AOL users seem to have a masked or "fake" IP address. If a user votes on the item from their AOL browser, it will let them vote multiple times because it doesn't doesnt seem to see that their real IP address is in the database. AOL users tell me that it lets them vote multiple times in their AOL browser but it works fine and only lets them vote once when they vote in their IE browser. Is there any way of detecting if a user's "real" IP address is already in my database, so they cannot vote multiple times?
Where's The "real" Documentation On PHP?
My understanding is that Zend are the folks behind the one and only PHP implementation. Now that PHP5 is released, I'm quite interested in using it. However, the documentation avialable at PHP.NET suggests that it isn't by Zend. What reason is there to believe it is complete and accurate in any sense? (There's lot of user clarifications which show that it isn't complete). In particular, the section of PHP5 has parts that are simply blank (e.g., Class Constants, etc.). What else is undocumented? Does ZEND supply accurate documentation, and if not, why not?
How To Get The "real" URL?
I've been twisting my mind trying to figure out how to get the real URL. I have a page at namezero which requires you to have a frame_banner at the bottom of the page, thus making it impossible to enter direct URL-adresses. E.g. http://www.metusmortuus.net and http://www.metusmortuus.net/samples.html will both end up at the same page, namely the page that this virtual domain is pointing to. (I hope you understand this) What I need is to find the actual URL that was typed into the 'location'-box. Then I would be able to simply redirect my visitors to that page manually. (Yikes, this was hard to describe, but I hope you get the picture) None of the predefined variables listed in phpinfo() worked (incl. request_uri and http_referrer), so I guess this is a long shot...
Do Professional PHP Programmers Use Error Checking In Their Code?
I've made it habit to check all returns in my code, and usually, on most projects, I'll have an error function that reports error messages to some central location. I recently worked on a project where someone suggested to me I was spending too much time writing error messages, and that I was therefore missing the benefit of using a scripting language. The idea, apparently, is that the PHP interpreter writes all the error messages that are needed, and that I shouldn't write such code myself. I was given the impression that if I needed extensive error checking, or strict typing, then I should use a real language, like Java, but if I'm going to use a scripting language like PHP or Ruby, then I should leave errors to the interpreter, since the whole point of using scripting languages is speed of development. Has anyone else heard this argument, and do you agree with it? I'm wondering how other PHP programmers handle error messages. Check everything or leave it to the PHP interpreter to tell you when there is an error? Which of these two functions is better, the one with error checking or the one without? function getWeblogEntries() { $query = "SELECT * FROM weblogs"; $result = mysql_query($query); $howManyWeblogEntries = mysql_num_rows($result); for ($i=0; $i < $howManyWeblogEntries; $i++) { $row = getRow($result); extract($row); echo "<h1>$headline</h1>"; echo "<h7>$date</h7>"; echo "<div class="mainContent">$mainContent</div>"; } } function getWeblogEntries() { $query = "SELECT * FROM weblogs"; $result = mysql_query($query); if ($result) { $howManyWeblogEntries = mysql_num_rows($result); for ($i=0; $i < $howManyWeblogEntries; $i++) { $row = getRow($result); if (is_array($row)) { extract($row); echo "<h1>$headline</h1>"; echo "<h7>$date</h7>"; echo "<div class="mainContent">$mainContent</div>"; } else { reportError("In getWeblogEntries, the function getRow failed to return an array on the $i iteration."); } } } else { reportError("In getWeblogEntries, the query to the database failed."); } }
Parsing Challenge...
I thought I ask the scripting guru about the following. I have a file containing records of data with the following format(first column is the label): CODE#1^DESCRIPTION^CODE#2^NOTES NN-110^an info of NN-001^BRY234^some notes NN-111^1st line data 2nd line data 3rd line data^BRT345^another notes NN-112^description of NN-112^BBC23^multiline notes blah blah blah NN-113^info info^MNO12^some notes here How do I parse so I can insert them in the database, e.g. MySQL/Access?
NovelSpace Media, LLC Announces The Launch Of Their New Online Bookstore And Web Portal Devoted To Developers And Programmers.
NovelSpace Media, LLC has announced the launch of its new online bookstore, NovelSpace.com. Located at http://www.novelspace.com, it features a wide and varied selection of books for computer aficionados, developers, software engineers, and programmers. In addition to low prices and shipping fees, NovelSpace.com boasts an easily navigated interface along with quick checkout and simple account management. Proceeds from each purchase are donated in support of various open source projects. NovelSpace Media is also inaugurating Developer Haven, the first in a series of web portals to be developed by the company. Designed as an online resource for programmers and software developers, Developer Haven features a section devoted to industry news and a directory of links to websites with code samples, tutorials, components, and software packages. Users can also test-drive a beta version of DH Search, an internet search engine tasked exclusively to researching material related to programming and software development. Developer Haven can be accessed from NovelSpace.com, or on its own at http://developerhaven.novelspace.com. About NovelSpace Media, LLC NovelSpace Media is a development firm currently specializing in e-commerce and portal websites. The driving goal of the company is to offer customers easy access to books and resources at competitive prices, as well as building thriving online communities around rich content offered through topic specific web-portals.
Search Engine Challenge
I'm running a site with +20.000 articles. The articles (html files) are saved on the server as txt files. Alle other data (author, date, category and so on) are in a MySQL db. Before we had the articles put in the db also and then performed SQL queries for the search engine. But this is no longer feasable since there are too many articles and the db has gotten too big. The search engine does all of the db and the server cpu goes max. I'm looking for a php type search engine that automatically indexes the txt files, produces 1 index file with all indexed words + the id's of articles having those words. Like that the search script doesn't have to query all the articles (the whole db) anymore but just this one index file. Would be nice also if there would be possibility to have a blacklist of words (the, a,...) and other admin things.
Get Auth'd Username From IIS4 Challenge?
I'd like to setup some intranet pages that are personalized by user. However, I'd like to keep my users with one name/password that's dynamically updated in all "places" when they change their userame and password. Thus, I think I want to use IIS4's built in NT Domain auhentication. Now, I know how to suck the current authenticated user in VBScript ASP code... is there any way to get this same info in PHP? Would a session variable be the way to go, putting the auth routines in ASP and then transfering the info to PHP with session vars? or something else "Secure"? I'm not a pro on session variables.
Simple Challenge - Working With Image Coordinates And Dynamic Linking.
(*** apologies for the X-Post, but I felt it was relevant to all the groups ***) I have a page with a large centre-aligned image on it. I want a functionality whereby users can click their mouse on any point in this image and it would then show a virtual mouse pointer at the place where they clicked it. If they were to click somewhere else, the position of the virtual cursor would change. The position of the cursor needs to dynamically generate a link and display it in a form field text edit box. If that link is then viewed separately, it would launch the same page with the virtual mouse pointer at the location where the original person placed it. Basically I want to be able to have one guy point to a location on the image for the benefit of another guy, but graphically as opposed to relying on written explanation. I can run CGI and PHP scripts if need be. Easy-peasy, or can of worms?
|