|
You're not selecting 'oem_name' as a field in the query on line 50...
|
# ? Jul 19, 2013 16:55 |
|
|
# ? Jun 4, 2024 12:37 |
|
ManiacClown posted:See, this is what I love about SA. Since I registered it's had intelligent discussion framed in a manner that fits my personality, but after getting out of college (so long, long ago now) I've found that it's got an insanely broad knowledge base that can help me with drat near anything. Thank you all for your help so far. Haven't really been following all of this very closely but the query on line 50 does not SELECT from a column named oem_name so the associative array returned by mysql_fetch_array() on line 55 will not have an index called oem_name. Edit: beaten.
|
# ? Jul 19, 2013 17:02 |
|
Whoops. Yeah, that'll do it. I fixed a couple other errors that came up after I fixed it and now it'll at least output the first OEM name in an <h3>, although in a line before that it says "HP Array" for some reason. That's less an issue than another undefined index that's popped up, this time in line 82. What I don't get is that line 69 seems to define it. File link again. Line 69: php:<? $model_result[ $smq_row['system_oem'] ]['children'][] = $child;?> php:<? if ( sizeof($model_result['children']) )?> Edit: If I try to echo $model_result is outputs the word "Array" and then gives me the undefined index error. Doing a foreach() on $model_result gives me "Array" repeatedly. Echoing $smq_result the line after setting it gives me "Resource id #8." This seems to indicate to me that there's still something wrong with my SQL query. Here's how the query ends up as echoed: SELECT system_oem, system_model FROM systems WHERE system_oem IN ('Acer', 'Asus', 'Compaq', 'Dell', 'eMachines', 'Gateway', 'HP', 'HP-Compaq', 'IBM or Lenovo', 'Toshiba') ORDER BY system_oem, system_model ManiacClown fucked around with this message at 19:43 on Jul 19, 2013 |
# ? Jul 19, 2013 18:14 |
|
Let me introduce you to two little functions named print_r() and var_dump(). Start wrapping php:<?php print '<pre>'; print_r($smq_row); print '</pre>'; print '<pre>'; var_dump($smq_row); print '</pre>';
|
# ? Jul 19, 2013 19:49 |
|
Again: wow. That's drat useful. Thank you. I'll post the order of declarations here and it's probably more readable to check the output (sylesheet links commented out) to see what it puts out. The six manufacturers (Acer through HP) at the bottom are what it should be outputting for the <h3>s, so it's at least doing those. The fact that $soq_row is returning "boolean false" seems to be the problem, but I'm not sure why it's returning that. Declarations for those commands are in the following order: $system_oem_query $soq_row $soq_result $system_result_query $manufacturers $model_result $smq_row $smq_result $parent $child $output Unfortunately I won't get back to this until Monday morning (because damned if I'm going to do work for free at home for a $9 an hour job), but I'll get back to this first thing then.
|
# ? Jul 19, 2013 20:42 |
|
FirePHP is also nice for logging to the console in Firefox. It's easy to get going. I've seen Webkit versions but don't know how well they work. http://www.firephp.org/ Also, you can automate all that "error at line <blah>" stuff in your die() functions. http://davidwalsh.name/php-magic-constants Of course there's real, more complex PHP debugging software that you can install on the server too.
|
# ? Jul 19, 2013 21:05 |
|
I should note with FirePHP, its easy to overwhelm it and have it stop working. It works by putting logging lines in the header. Header space however appears to be limited, so buyer beware. Its *fantastic* for ajax-y type stuff however, since it stops logging output from messing up your json/whatever.
|
# ? Jul 20, 2013 04:19 |
|
ManiacClown, your boolean false is probably the result of the query returning no data; there doesn't appear to be anything wrong with the query itself but you can prove that by running it on your data via SQLyog and seeing what the result is. It could be as simple as your "system_oem" data being all lowercase, but the oem_name is capitalised. This is another reason why you use IDs for relational tables and not strings. On a related note to what substitute started to cover, let's talk about dev environments. You could make your life a whole lot easier if your development environment and tools are set up correctly for debugging, possibly saving you hours of head scratching or tail chasing. I'm pretty sure a lot of us started where you are now, using something like Notepad for editing PHP and print_r() and die() to debug (and still do on occasion), but the future is really in an IDE that does the legwork for you. I don't want to overload you with lots of "this is how you should be doing it" talk, but the right dev environment is as important for debugging code as designing the right schema is for a databases. Some of what follows might make you think "sure I'll do that later if I have to do more complex code", but spending maybe an hour to get all this up and running will save you huge amounts of time in the future. My personal environment setup is to use XAMPP (Cross-Platform Apache MySQL PHP Perl). You can grab a copy for any OS, drop it on your hard drive (or a pen drive if you grab the portable version) and have PHP and MySQL up and running in moments. I tend to run it from the batch files (apache_start.bat mysql_start.bat) simply because that gives me the error output and I can always see it's actually running. To setup a new site I'll make a folder under /htdocs/, for instance /htdocs/mygreatproject.com. This would be accessible via http://localhost/mygreateproject.com but I'd prefer to have it be http://dev.mygreatproject.com/ (we tend to use subdomains; dev/local for localhost development, staging/test for live server testing). To get the site to be at that subdomain we'll set up a new vhost entry, then open the windows hosts file and add an entry to point that subdomain to 127.0.0.1 (localhost). This is all covered in this setting up virtual hosts guide. For all our database management needs we use SQLyog (there's also the community version which is free but lacks a few features). We can copy a database from another server or restore it from a backup with Yog, and it's basically our go-to tool for everything database related. Xampp has the default user as "root" with no password, so that makes life easy for dev. For PHP development I've used NotePad++, PhpEd, Eclipse, Netbeans and Aptana, but my current favorite is PHPStorm (the EAP version is periodically free). PHP Storm has so many features it's ridiculous and I can't possibly tell you about them all, however the most important feature is live debugging. Like an IDE for any other language, this will let you insert breakpoints in your code that cause execution to pause, allowing you to examine all the variables and the stack trace, and step through your code line by line. This is absolutely invaluable and has saved me countless hours. This extremely short guide tells you how to setup and use this feature, which basically consists of uncommenting 6 lines in the php.ini, adding a bookmark and clicking two buttons. Going even deeper, we also use GIT for source control, which integrates into PHPStorm. We also use it for deployment because it's magic when configured right and the reflog and branching has saved us from losing days worth of code That's a whole other can of worms mind you. I'm interested to hear if anyone else has other systems they use to make their lives easier. FirePHP does look good for Ajax logging and I'd never heard of it before.
|
# ? Jul 20, 2013 07:15 |
A clean LAMP stack & vim, commits via git. Your environment sounds absolutely mental
|
|
# ? Jul 20, 2013 10:10 |
|
If we're going down the dev environments rabbit hole, I would suggest Vagrant. I just wrote a long post on how to get started with it: https://leftnode.com/entry/getting-started-with-vagrant.html It'll also give you the added benefit on learning how to build a basic LAPP stack from (near) scratch. Give it a look.
|
# ? Jul 20, 2013 13:09 |
|
musclecoder posted:If we're going down the dev environments rabbit hole, I would suggest Vagrant. I just wrote a long post on how to get started with it: https://leftnode.com/entry/getting-started-with-vagrant.html Vagrant is super awesome, but Virtualbox has some funkiness when handling symlinks in shared folders. This doesn't really affect basic PHP development, but if you're using NPM packages (like for CoffeeScript or LESS/SASS) you might run into it and it's a bitch to troubleshoot.
|
# ? Jul 20, 2013 14:57 |
|
Vagrant I can get on board with; it's been great when we've needed a clean or complex server environment and can't fake it on windows for local dev like everything else. There are a few too many pitfalls for us to roll it out for every dev on every project, plus it takes a bit of setting up, but it certainly has it's uses. One of my colleagues insists on using just vim, and while I love the programs simplicity I can't stand watching him struggle with things I can do quickly in an IDE, especially when it comes to the debugging, let alone the power he's missing out from integrated searching, auto-complete, type hinting, jump-to-definition, auto-formatting, syntax highlighting and on-the-fly error checking, etc. I know vim can do a lot of this with some tlc, but this all just comes naturally to PHP Storm.
|
# ? Jul 20, 2013 14:59 |
|
It's funny you mention that because I use all vim all the time. Without a doubt the most productive I've ever been. It has a huge learning curve, though. To each their own.
|
# ? Jul 20, 2013 16:35 |
|
I used to feel the same way about EMACS. Like 15 years ago. Honestly a good autocompleting IDE is worth its weight in gold. Which of course makes Sublime Text all that. With Code intel and the various plugins, you get great autocomplete, plus you can drive the whole drat thing from the keyboard, and its got a lot of the string processing cleverness that made emacs a joy to work with. Its the non insane lovechild of eclipse and emacs/vi. Of course if one still likes old text mode IDEs , pretty much all the things people DIDNT like EMACS for back in the day, specifically its hugeness, is almost quaint in 2013. Its huge, but compared to the big graphical IDEs, its actually quite slim. duck monster fucked around with this message at 00:29 on Jul 22, 2013 |
# ? Jul 22, 2013 00:27 |
|
v1nce posted:For PHP development I've used NotePad++, PhpEd, Eclipse, Netbeans and Aptana, but my current favorite is PHPStorm (the EAP version is periodically free). PHP Storm has so many features it's ridiculous and I can't possibly tell you about them all, however the most important feature is live debugging. Like an IDE for any other language, this will let you insert breakpoints in your code that cause execution to pause, allowing you to examine all the variables and the stack trace, and step through your code line by line. This is absolutely invaluable and has saved me countless hours. This extremely short guide tells you how to setup and use this feature, which basically consists of uncommenting 6 lines in the php.ini, adding a bookmark and clicking two buttons. PHPStorm looks amazing. It was kind of irritating that I had to affirmatively turn on line numbers, but the coloring is quite nice and PHPStorm has much better visual contrast than Notepad++ does. I can actually see clearly what I'm doing! Granted, Notepad++ probably has color options, but I never thought to check them. I also like the code checking. Now that I've got the error handling all set up with PHP interpreter and SQL dialect, my problem is specifically in line 48. For some reason, it can't resolve the table manufacturers and, as a result, either of the two columns. I'm guessing I have the database connection set up incorrectly. I used the connector driver direct from MySQL. I have the relevant database at C:\Documents and Settings\Administrator\My Documents\Dropbox\wamp\bin\mysql\mysql5.5.24\data\test_db_2 and I'm not sure what I should put in for the URL. I've got com.mysql.jdbc.driver as my JDBC driver class and both URLs I've tried for the database fail to connect. Then again, I don't know if it's the URL or if there's some other issue going on. It just says "Incorrect driver and/or connection specified."
|
# ? Jul 22, 2013 23:10 |
|
ManiacClown posted:
Why did you think a JDBC driver would work with PHP?
|
# ? Jul 23, 2013 03:20 |
|
Blinkz0rz posted:Why did you think a JDBC driver would work with PHP? I'm just trying to set up PHPStorm. It seems to want one for debugging purposes, so I had to guess at which one to use. Edit: Hey, I got it working! It turns out instead of jdbc://[path] I had to have jdbc:mysql://[path]. Edit 2: Here's an export of the database. ManiacClown fucked around with this message at 22:02 on Jul 23, 2013 |
# ? Jul 23, 2013 15:23 |
|
Wrong topic.
|
# ? Jul 24, 2013 03:49 |
|
I'm trying to get WifiDog running on an Ubuntu laptop. There seems to be an issue with the install PHP file, whereby upon filling out the "Create new administrator user" page, it promptly either just refreshes the page, or brings me back to the very start of the install process. Someone suggested it might be the installer failing to remove a temporary file that specifies the install script, but I'm not quite sure where to start - Would anyone be able to suggest where I could look? Here's the file.
|
# ? Jul 24, 2013 10:52 |
|
There's no error checking there to ensure that the file can be opened, nor is there any to ensure that the writes succeeded. Later on, it intentionally suppresses important warnings and errors. It also abusively mixes business logic and display logic in a complicated way that can make it a real bear to maintain. If the rest of the code is this bad (and from a quick browse, it is), you don't want it on your server. Or anyone else's server. Judging from the last update times of 4-7 years ago and the sheer volume of unchecked spam in the bug tracker, the project is dead and the existing bugs aren't going to get fixed.
|
# ? Jul 25, 2013 01:42 |
|
Hello guys, currently working on an existing php file which handles database connections and queries, I have written a really simple function that takes in a query, stores the results in a table and returns an array. The aim is that anytime I want to do a query and return an array I can use this again and again.code:
code:
|
# ? Jul 27, 2013 17:55 |
|
mysql_fetch_array returns the columns per row in their own element. Try this:code:
|
# ? Jul 27, 2013 18:58 |
|
KARMA! posted:mysql_fetch_array returns the columns per row in their own element. Try this: That's exactly what I need and thank you for introducing me to PDO, just read a couple of tutorials and I will have a go later. I always find PHP is one of those languages where some people work completely different to other people. Sometimes you will see a project that is a mixture of code and HTML, other times it's pure OO. My background is a Network Admin that has used PHP over the years, but I am getting into it again with a few projects at work, if you or anyone in this thread could recommend a bang up to date PHP book so I can catch up? Thanks
|
# ? Jul 29, 2013 08:07 |
|
Vedder posted:That's exactly what I need and thank you for introducing me to PDO, just read a couple of tutorials and I will have a go later. I always find PHP is one of those languages where some people work completely different to other people. Sometimes you will see a project that is a mixture of code and HTML, other times it's pure OO. If you're set on getting a book, I'd only look for one that goes into design paradigms (like when/how to use singleton classes, factories, etc.) as that's a bit harder to pickup than language features. Master_Odin fucked around with this message at 16:13 on Jul 29, 2013 |
# ? Jul 29, 2013 08:22 |
|
Vedder posted:That's exactly what I need and thank you for introducing me to PDO, just read a couple of tutorials and I will have a go later. I always find PHP is one of those languages where some people work completely different to other people. Sometimes you will see a project that is a mixture of code and HTML, other times it's pure OO. I understand the feeling of having to find a good resource when most you find is bottom barrel. However, everything I know about it I've collected piecemeal over the years; I don't have singular source to point you in to the right direction. I can say that the online docs are great for looking up peculiarities. https://www.phptherightway.com seems to be a good overview portal to get your head around the space occupied by php. After that, I've tried looking in to "the best php book" but I'm having trouble finding a reputable source. Unfortunately I haven't gotten further than the amazon bestsellers list and there are too many old books on there. 2006 is old people, jeez! My advice would be to look for recent books that you find appealing and trust your own judgement. Good luck.
|
# ? Jul 29, 2013 15:50 |
|
Is there a PHP framework that handles localization really well? Is there a thread on this topic already? It seems like there should be, because it's a complex issue. At work we need to solve having a major product group represented in different regions (North America, Europe, Asia, etc.) with multiple languages, and some product/content is different in some of the regions and/or countries. It's a big problem we're trying to figure out how to tackle. We started taking the main site and breaking out common pieces that could be shared globally to different regions with dynamic elements to switch per site or site section, but it's becoming more and more of a situation of us writing our own framework. I'm really hoping to find a better way to manage all of this.
|
# ? Jul 29, 2013 20:24 |
|
substitute posted:Is there a PHP framework that handles localization really well? Is there a thread on this topic already? It seems like there should be, because it's a complex issue. Well, there's the gettext library which is kind of outdated, but it's classic Unix, so it'll work across a lot of platforms. The newer PHP library is intl which is easier to use. As for frameworks themselves, search Packagist for something that might look like it would work: * https://packagist.org/search/?q=intl * https://packagist.org/search/?q=localization
|
# ? Jul 29, 2013 20:55 |
|
Heyo, I'm working on a Wordpress theme and I want to have a bit more control over a form's interaction and validation, so rather than using Gravity Forms I really just want to run the $_POST through a straightforward validator library. Problem is, the company I'm doing this for are on PHP 5.2.6, and it will be quite a task to move forward. My googling for PHP standalone form libraries are not yielding anything useful. Any suggestions?
|
# ? Aug 1, 2013 05:54 |
|
If you're using Wordpress you will be seriously shooting yourself in the foot if you don't do things like the way Wordpress wants you to, even if it's a larger pain. Don't make something special.
|
# ? Aug 1, 2013 07:03 |
|
McGlockenshire posted:If you're using Wordpress you will be seriously shooting yourself in the foot if you don't do things like the way Wordpress wants you to, even if it's a larger pain. Don't make something special. Hmm okay, well it seems like the form options out there really railroad my options, does gravity forms allow you to manually build the form HTML and just use it for validation. The documentation provides no hints on this, and is really over controlling on the markup. The client won't be editing the form structure so all that's necessary is to hook in for validation.
|
# ? Aug 1, 2013 09:23 |
|
Doesn't Contact Form 7 give you direct access to the markup? http://wordpress.org/plugins/contact-form-7/
|
# ? Aug 1, 2013 17:59 |
|
I'll have a crack at it today, I'm not familiar with the Wordpress ecosystem so it's a learning exercise finding the plugins that provide the right level of customisation without needing to be hacked to poo poo.
|
# ? Aug 1, 2013 21:48 |
|
I'd recommend against hacking up an existing plugin, but rather find one that's not written like complete rear end and use it as a guide to build your own plugin. It's a little more long winded, but it takes far longer if you begin hacking one up and discover it doesn't do what you were expecting, needing, or it's just generally horribly written about half way down. Now, this is absolutely not the right way to do it, but if you have to do something fast and now you could always https://create and write some procedural PHP in there to basically have a single page form/tool/whatever. It's like a poor mans plugin, only a hundred times worse. Good for a quick hack, terrible for a permanent solution. Depends on your needs.
|
# ? Aug 4, 2013 07:01 |
|
v1nce posted:I'd recommend against hacking up an existing plugin, but rather find one that's not written like complete rear end and use it as a guide to build your own plugin. It's a little more long winded, but it takes far longer if you begin hacking one up and discover it doesn't do what you were expecting, needing, or it's just generally horribly written about half way down. Contact Form 7 fit the bill for what I needed. I just deregistered it's Javascript enqueue to stop it's own AJAX validation running, and set up my own. I can put my own markup in just fine so I get the backend without getting restricted on the front end, works for me.
|
# ? Aug 4, 2013 16:22 |
|
I do not quite understand how long PHP stores variables 1. User on Domain A loads SWF from Domain A. 2. DomainA SWF sends a POST request to DomainB.VarSetter.PHP, setting a a variable. 3. DomainA SWF spawns a pop-up window which loads DomainB.VarGetter.PHP 4. DomainB.VarGetter.PHP seems able to read the variable value. (But I do not understand why) I am not passing a session ID to either PHP file, though I am calling startSession(). If many people use Domain A SWF at the same time, will the value of the PHP variable get all crossed up between users? Edit: If I DO need to pass a session ID between the two PHP files: - Both PHP files are on the same domain. - Could I maybe tell the POST-invoked VarSetter.PHP file to call a client-side JavaScript function which opens a pop-up displaying VarGetter.php, and pass the sessionID via query string? Captain Pike fucked around with this message at 20:14 on Aug 5, 2013 |
# ? Aug 5, 2013 19:42 |
|
When you say "variable" you mean "session variable," right? They're stored until the session expires from inactivity. quote:I am calling startSession() Sessions are controlled by cookies. Cookies are locked to the domain. Without seeing any of the code you've described, it's going to be hard to tell what's actually going on here.
|
# ? Aug 5, 2013 23:45 |
|
Thank you very much for your reply. I apologize for my poor explanation. McGlockenshire posted:When you say "variable" you mean "session variable," right? Yes, I meant "session variable". McGlockenshire posted:the function you should be calling is session_start() My mistake! (I am using the correct function name in PHP) McGlockenshire posted:They're stored until the session expires from inactivity. I will see if I can construct a simplified version of my code (that is not all entwined with third-party library code. However, it looks like the following may be true: 1. User A's browser makes a POST call to mydomain.com/1.php // session_start() is called. $_SESSION['poop']='butts'; 2. A cookie is saved in User A's browser identifying the session. 3. User A's browser loads mydomain.com/2.php // echo $_SESSION['poop']; 4. User A's browser cookie tells mydomain/com/2.php which session to get the session variable value from. 5. echo $_SESSION['poop']; // This prints 'butts' for User A. If so, things are probably working correctly, correct? Captain Pike fucked around with this message at 05:55 on Aug 6, 2013 |
# ? Aug 6, 2013 05:24 |
|
You can just use session_id(); to see that the session is remaining constant between pages if you want.
|
# ? Aug 6, 2013 05:45 |
|
I'm working on some simple code that echoes the value of POST submissions from a previous page. But what I'd like to do is have each echoed variable have an ampersand echoed between them. I'm not too hot on PHP so the only thing I can think of is having it echo each value with an ampersand on the end, but this is a problem for the last one that ends up in place as not all the values need to appear dependent on input. Is there a way to automatically echo ampersands in a line between any values?
|
# ? Aug 6, 2013 09:02 |
|
|
# ? Jun 4, 2024 12:37 |
|
Try: echo implode(' & ', $_POST);
|
# ? Aug 6, 2013 09:14 |