Jump to content

gizmola

Administrators
  • Posts

    5,945
  • Joined

  • Last visited

  • Days Won

    145

Everything posted by gizmola

  1. An absolute path always starts with a '/'. That specifies the top of the directory tree. Let's say you have a file system structure like this: /mysite/admin /game /library/ config Now in your config directory you have a file that has database credentials you need to include in other scripts. The file is named db.inc.php. Then the absolute path to that script is: /mysite/library/config/db.inc.php Then there are "relative paths". If the path does not start with the '/' it requires the software to figure out where a file is "relative to the 'current working directory'". Here's some examples of relative paths that could be used: library/config/db.inc.php Lets say you have a script in the game directory named index.php, and you wanted to try and include the db.inc.php. include( '../config/db.inc.php'); The problem with this, is that it depends on the the setting of the current working directory. When you are cronning php scripts, you are not in the web environment, so things that might work in that context, and the current working directory settings, will often not work because command line php is not operating as part of a web server. You can write a little wrapper script that sets the current working directory (using cd /directory) or do that before the call to php -f in the cron line, however, in general it is best if your php scripts are using absolute paths. You can do some searching and googling and reading up on using the __FILE__ constant as the basis of calculating a "basepath" that you can then add to other relative path variables, to tranform them into absolute paths at runtime. The use of relative paths like '../../etc' is error prone, confusing, and experienced developers don't do it, whether it's a cron'd script or scripts run in the apache environment.
  2. For your first question, this is where you need to debug. Put in a var_dump($row); right before the check and see what $row has and whether or not the 'fab1' key even exists. Yes, the & is in php pass by reference. Unfortunately this is a technical detail having to do with functions and the use of resource types like database handles. You might know about pass by reference and pass by value? Basically, for a function, the default is to pass a variable by value. What this means is that the variable is actually copied when it is passed to the function, and changes to that parameter inside the function are not retained once the function ends. Most of the time this is the behavior you want, because you want functions to take parameters and return a result. With PHP it's actually more complicated in the way that variables are stored, named, and the way this stuff works internally but the basic idea is the same. -- if you're passing a "resource" variable (a database connection, file handle, socket connection, or a complex variable like an array that contains any resources) then you need to pass that variable by reference, so that the original variable is used, rather than a copy. If a copy is used you will find that the connection is destroyed in the copy process and will not work. So this is a rare case where you need to use the & with the parameter to indicate that the original variable should be passed as is (pass by reference).
  3. You are completely wrong. MVC is a "Design pattern". There are lots of ways to implement that pattern or portions of that pattern. Facebook absolutely does implement the "Controller" part of MVC. It seems we are not communicating effectively, because I went into some detail on how and why a controller is being used there. See http://en.wikipedia.org/wiki/Front_Controller_pattern. Each of the discreet api entry points can implement a front controller pattern to provide different responses based on the parameters passed to it.
  4. The error is very clear: The file it's trying to include could not be opened. Check that it exists, and that it has permissions that allow the user apache is running as, to get to it and open it.
  5. In my opinion it's a really bad idea to use javascript for something like this, when you could instead use a server side mechanism, like using curl.
  6. Now you've gone and got Pika riled up.
  7. The principle is the same. In general, the same way as I described previously. Let's revisit that and generalize. Let's say you have a controller (the C in MVC) responsible for routing. Generalized it could be: http://www.yoursite.com/me.php?action=x&param1=foo&param2=bar&etc. me.php simply needs to be your router. This assumes that behind the scenes (using session variables) the api already has authenticated you, and knows who you are. me.php needs to take the action parameter, and use that to load the appropriate handler code for that action, and pass any subsequent parameters to it. Mod rewrite allows you to present the url: www.yoursite.com/me/friends Which would be translated internally to: www.yoursite.com/me.php?function=friends The variation you are asking about, would be: www.yoursite.com/me.php?action=friends&friend_id=1207059 Of course the code that is loaded to handle the "friends" action, needs to have logic which does the right thing when a friend_id is passed, vs the case where there is no friend_id. This is a high level description of how front end controllers work. Have a look at zend framework, code igniter, symfony or cakephp to get an idea of how they handle this, and what sort of design patterns and options they provide.
  8. At least in the case of barcode scanners, they simply convert the barcodes into numbers, and look to the application like someone typed the number into the keyboard. I'm guessing a usb scale does the same. In short, you don't code anything special, the user uses the right device at the right time, and your app simply needs to accept the input.
  9. You have a variable: $message = " some stuff and more and more"; Now you want to add more to the string, you can do ... $message = $message . "more things added to message"; or you can do: $message = "$message more things added to message"; or, what most people do, which is a shorthand for the first concatenation: $message .= "More things added to message";
  10. I just gave you the answer to both questions.
  11. This is a warning. You can suppress warnings by changing the errorlevel setting. However, the better solution is to recode using preg_match. eregi is due to be removed in favor of the pcre library.
  12. If you're asking how you get the id from an insert.... mysql_insert_id. You call this after a successful insert, and from there, you can do other inserts, or use the id as a get parameter you provide when you build a link to the display page. If you have some other question, please clarify.
  13. How facebook does it is something you'd only know if you worked at facebook. With that said, these types of things are typically done with a script that takes url parameters: http://api.yoursite.com/me.php?name=yourname Then using mod_rewrite or some similar trick, a url like the one you presented is converted on the fly. json_encode json_decode
  14. Yes I read what you wrote, lack of punctuation, misspellings, and omitted words and all. It's a piss poor attempt at a question, but despite that fact, I did my best to interpret what you're after, by consulting tea leaves, and using my vast experience answering noobs with only a passing acquaintance with the English language and no idea how to pose a proper technical question. In short people exactly like you. Did you look at the link? It is a combination of javascript libraries that lets you create a DROP DOWN LIST which includes pictures along with the elements. Since you brought up a search box, the general trend these days is to ajax search, and do incremental results which are displayed in a listbox. I put 2 and 2 together and took my best shot, because frankly, I don't have time to babysit you in coaxing out some clarity. Because you were rude, and disrespectful, I'm warning you now, that if you don't shape up, your time here on phpfreaks can be ended quite effectively with a couple of clicks of my mouse. You are the one who mentioned search box, and then described your desire for picture/text/price combined. If that is not what you're after, you really need to work on your command of the written word. If you're asking how to store an actual image in a database column, that can be done but it is not advisable in most cases. Most people store the images in a directory structure, and a column that contains the path to the location where the image is stored on disk. Despite this, if you want to try and store images in a database column you would need to use a blob type. Last but not least, nobody is going to feed you code, that is not what we do here. I gave you some pointers and that is all I'm going to do right now. If you have specific questions you're free to ask them, but otherwise, I expect you to provide more specifics, and we should be seeing some code very soon if you want to pursue this.
  15. Web development is a nearly bottomless topic. -Just start digging in and floundering, but whatever you do -- actually make something, be it a site, a forum, a guestbook, or whatever floats your boat. Look at code especially that found in some of the big framework projects. I like Zend framework and symfony for this purpose. You may not understand it all, but at least you will get an idea of how veteran developers write and structure code. The fact that you know c++ should position you to be able to jump in the deep end, especially with php's oop. BTW, it also would position you to pick up java very quickly. For books that I think someone with your background could easily benefit from, if you are a "learn from a book" type: http://www.manning.com/reiersol/ http://www.amazon.com/dp/143022925X/ http://www.amazon.com/dp/0672329239/ http://www.amazon.com/PHP-Master-Write-Cutting-Edge/dp/0987090879 All of these books were written by people who are known in the PHP community as top notch developers. There's also some decent courses available from sitepoint or lynda.com if you want a video course.
  16. Hey Matt: You have no idea how lucky you are to have found this community. We are very nearly unique in the programming world, in terms of the amount of patience people show here. Getting yourself in a dither over outside pressure isn't going to hep you become a competent coder. Truthfully, I only read the last page or so of this thread, and I'm not entirely clear what it is that doesn't work. Debugging commands like echo, print_r, and var_dump are very helpful in figuring out what is happening. It's just the nature of things that programming tends to have surprises for even the most experienced developer. Just glancing at your last posted code snippet I found this: if ($row['fab1']="--None--") This is a common mistake that people make. That assignment will always be true. What's doubly problematic there is that whatever value you had in $row['fab1'] is actually getting replaced wiht the string "--None--". I have no idea whether it has anything to do with your current conundrum, but you should fix it nevertheless. if ($row['fab1'] == "--None--") Actually does the comparison. In summary: -More use of simple debugging statements in your code should help you lift the fog and feel like you're not floundering and spinning your wheels so much -Try to apply DRY. I know it's probably difficult right now but surely you have to see that you are repeating code. For example: $part = mysqli_real_escape_string($dbc, trim($_POST['part'])); $rev = mysqli_real_escape_string($dbc, trim($_POST['rev'])); $partdesc = mysqli_real_escape_string($dbc, trim($_POST['partdesc'])); $ncmrqty = mysqli_real_escape_string($dbc, trim($_POST['ncmrqty'])); There's a point at which you have to see that a small function would be better, and make your code more consistent, and easier to debug. function cleanPostVar(&$dbc, $key) { if (array_key_exists($key, $_POST)) { return mysqli_real_escape_string($dbc, trim($_POST[$key])); } else { return ''; } } Now you'd replace all those repetitive calls with: $part = cleanPostVar($dbc, 'part'); The nice thing about this is that as you learn more about sanitization and filtering you can add to the function or create variations of it, without having to go through and rewrite 50 lines of code.
  17. I just have one comment. You did not state in your post what database you were using. If you had stated that you were using Oracle, I would have let you know that Oracle has sequence objects. This is different from mysql auto_increments, in that a sequence is a number generator, and it can be used to get a unique number in advance, that you can then use when you actually insert a row. You could in fact develope your own sequence generator even with mysql by creating a table that had no purpose other than to store a sequence number. With the proper locking code, this could be used to get a unique number which could then safely be used as the key for your table. Of course what you could also do is simply insert a blank row purely in order to get the project_id, and then use that to update the row when data was submitted.
  18. gizmola

    help

    The goal of this code is to create 2 constants to be used for including files from a known location, and for setting up url's. In php you create constants with the define() function. PHP has the $_SERVER superglobal that gets variables from apache and makes them available to php. This is being used to help figure out the web root. the __FILE__ is a magic php constant that provides the complete path and filename of the file in which it is called. It is often used by a configuration script in a a known relative location, so that a basepath variable does not have to manually configured by the users of the scripts. str_replace is being used to do some manipulation of the strings involved. You should take a look at the manual pages on php.net for hte functions that you don't understand. You can also echo or var_dump variables in the script to help you understand what value they hold when the script executes.
  19. Here's a good way: http://www.marghoobsuleman.com/jquery-image-dropdown
  20. There are a number of standards inolved in mail transport/email. SMTP is what is used to move email between domains/email servers. IMAP/POP is used to send/retrieve mail from the end user to their local mail server. IMAP in particular is the standard that facilitates mail folders, and persistent storage of email on a server. Then there are the actual email format standards. It's not really clear what you are after, but understanding the various standards involved might help you focus in on how you would accomplish various email related tasks, as well as coming to understand what existing packages and libraries do, and what problems they try and solve.
  21. gizmola

    MYSQL Join

    Yes that looks fine to me. I personally dislike putting `...` around every name. That exists to allow you to use mysql keywords as names of tables and columns, but is not necessary 99.9% of the time. It's more typing, and is harder to read, so I never use it. Point in fact, for the SELECT list you only need to include the alias if there's a column name conflict between the two tables as well. let's say that you get name and surname from a "names" table, and the points table would not have those columns, then you can just do : SELECT a.id, name, surname, points.... With that said, the syntax looks like it would work fine.
  22. gizmola

    MYSQL Join

    The LEFT JOIN keyword returns all rows from the left table (table_name1), even if there are no matches in the right table (table_name2). ( from w3schools.org). So basically, when left joining, you would have the LEFT table's (in this instance "id") column JOIN with with the right table's column, thus LEFT JOIN Well, im just talkin from what it sounds like, and thats always the way i've used it and it works fine so dont see a problem. I think it might help you to know that you do not need to concatenate pieces of a string together like that just because you want to break the SQL statement up into seperate lines. $sql_emp = 'SELECT a.`id`,a.`name`,a.`surname`,b.`points` FROM `table_name` a LEFT JOIN `table_name` b ON a.`id`=b.`id`';
  23. gizmola

    MYSQL Join

    Yes, that is called doing an "outer" join, or in this case, a "LEFT OUTER JOIN". The syntax in your example will perform an outer join in the way you have described.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.