-
Posts
4,704 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
You'd need a condition where if the item is not selected, do not do anything. If you change your variable to an array as I mentioned before it'll make the process easier because you could just loop the array of selected items rather than have to loop over everything.
-
You'd want to use cURL or file_get_contents to download the source for the URL entered. Once you have the source in a string, searching it depends on how advanced of a search you want to do. strpos would allow you do a quick and simplistic search.
-
You could just zero-pad your rand call to make it 4 digits long. $num = str_pad(rand(0, 9999), 4, '0', STR_PAD_LEFT);
-
Name your checkbox v_selected[] that way on the PHP side you have an array. That will make it easier to process. Also $_POST['v_selected_$count'] is not going to work right. Variables are not translated when inside single-quoted strings so you are looking for a posted item named quite literally 'v_selected_$count' rather than 'v_selected_0' as you intend.
-
I still don't like that one. It still could be interpreted in either way. Perhaps a better phrased question would be "In what order are nested function calls evaluated?" with just two options "Inner most first" or "outer most first" (or you could use left to right/right to left, but drop middle out). I also still don't much care for the wording of #5 or #7. For #5 perhaps use 'lists' or 'collections' instead of arrays. For #7 either remove option B or specify in the question PHP v5.4 (or drop the 'and lower' part from the beginning of your quiz).
-
(others beat me to some of these but here ya go anyway) empty($var) would be true as well. var $var=0; is technically valid, depending on how picky you want to get: class Blah { var $var = 0; public function Blah(){ var_dump($this->var); } } No true. You can use foreach on objects, and it is intended as well (See the Iterator interface); D should be $myFunction = function(){}; This depends on what version your looking at. $array=[]; is valid in php 5.4 only (your "5.4.x and lower" implies covering 5.3 and 5.2). There are still plenty of people not using that version. This could be mis-interpreted. I assuming you mean that if you do something like: func(anotherfunc($a, $b)); php will first execute anotherfunc, then func. An alternate meaning for that question though would be given this line: func($a, $a++, $b, $c+30); in what order are the parameters run? The answer to that is left-to-right. I would change the wording on that answer so you don't use 'continue' so much. Perhaps something like ""break" exists the loop and continues script execution; "continue" jumps immediately to the next iteration of the loop." ----- You have various spelling errors in some questions too, so do a proof-read.
-
Why do some Linux VPS host companies restrict access to time/date settings?
kicken replied to silvercover's topic in Linux
I had a VPS based on OpenVZ at one point and was not allowed to change the date/time on it. The only thing you could do was change the timezone. I'm not sure if that's a limitation of OpenVZ or if it was just the way it was configured. The two Xen based VPS's I have allow me to change the date and time no problem if I wanted to. Note that if your just wanting to adjust the time because it's a few hours off, you likely need to be setting the timezone, not adjusting the time itself. Try running tzselect to set the timezone. -
Problem with reading a docx file in a zip archive
kicken replied to Stefany93's topic in PHP Coding Help
A docx file is itself a ZIP file which you would have to open and then extract information out of. There are libraries out there for working with word documents, you will probably want to look into one of them so that you are properly interpreting the docx format. -
You should probably just be running a DELETE query first to remove existing categories, then insert the category list again. Just doing an insert (even with the duplicate key part) won't remove a category if you were to unselect one that had been previously added
-
The proper syntax for ON DUPLICATE KEY UPDATE is ON DUPLICATE KEY UPDATE column=someValue, column2=someOtherValue ... just like an update statement. You need to rewrite your query in that format.
-
Your code does not make much sense. Why are you creating tables? You should create the tables before hand using something like phpmysqladmin or mysql command line tool. To add data to them (such as when a person submits your form) you want to run an INSERT INTO with the new data. Two additional notes for when you get there: 1) Your using mysql_* functions for your queries and connection, which means you need to be using mysql_insert_id, not mysqli_insert_id. 2) You have to call mysql_insert_id right after you run the INSERT INTO query that would generate the ID. You cannot do it on another page or after you do other queries. You'll need to get the generated ID on the first page then save it in the session or pass it as a URL parameter to access it on the other pages.
-
What results are you getting vs what are you expecting to get? Syntactically that line is fine, so your problem probably lies either with the data itself (ie trying to sort numbers stored as VARCHAR), or with how you're processing the results after the query (doing something that alters the order).
-
That line means that there is no index on your venzo_itunes_sales table, which means mysql has to do a full table scan (checking every individual row) each time you run that query. You'll want to create indexes on both the venzo_itunes_sales.label field (for the JOIN condition) and the venzo_itunes_sales.sales_or_returns field (for the WHERE clause)
-
When you upload the files you would save a record in your database indicating the filename and the associated date (either user entered or automatic). Then to list them just run a query against the table for any files in a given date range and generate your list with a link to the file. The steps would look something like if (/* User is uploading */){ //Save the file somewhere to disk //Store location saved and date to database } else if (/* User is searching */){ //Query database for files where date = $userEnteredDate (or date between $userDate1 and $userDate2 for a range) while (/* we have results from above query */){ //Output a link to the file using the stored path } } Write some code and try to implement the steps. If you get stuck somewhere post the code and what you're stuck on.
-
On an additional note, when your mixing AND and OR conditions you should use parenthesis around them to make it clear how they relate to each other. If I am understanding the precedence in mysql right, what you have would be evaluated as this: WHERE ((name = '%s' AND marks ='%s') AND grade = '1') OR grade = '2' Which means you'll get records where grade=2 or (name=%s and marks=%s and grade=1). In other words, you'll get records where grade=2 regardless of what the name and marks columns are set to. What you intend (I am guessing) is for the query to be processed as: WHERE name = '%s' AND marks ='%s' AND (grade = '1' OR grade = '2') Which will return records where name=%s and marks=%s which have a grade column equal to either 1 or 2. p.s. side note mysql does allow || (and &&) however OR (and AND) are more typical and standard.
-
After the first time you go through your while($page = mysql_fetch_array($q2)) loop, you will have exhausted all the records in that result set. All subsequent calls to mysql_fetch_array will return false and cause the loop to exit. What you need to do is loop the result set and save the results to an array first, then use that array to match things up. $q1 = mysql_query("SELECT section_id , section_name FROM sections ORDER BY section_id"); $q2 = mysql_query("SELECT page_name , page_link , section_id FROM pages ORDER BY page_id"); $pages = array(); while($page = mysql_fetch_array($q2)) { $pages[] = $page; } while($section = mysql_fetch_array($q1)) { echo $section['section_name'] . "<br>"; foreach ($pages as $page) { if($page['section_id'] == $section['section_id']) { echo $page['page_name'] . "<br>"; } } } Or, better yet, learn how to use an SQL JOIN to return your pages and sections in a single query and display them how you want with just a little processing logic: $sql = ' SELECT s.section_id, s.section_name, p.page_name, p.page_link FROM sections s LEFT JOIN pages p ON s.section_id=p.section_id ORDER BY section_id, page_id '; $q1 = mysql_query($sql); $lastSection=0; while($section = mysql_fetch_array($q1)) { if ($lastSection != $section['section_id']){ //Only display section header if the section has changed. $lastSection=$section['section_id']; echo $section['section_name'] . "<br>"; } echo $page['page_name'] . "<br>"; }
-
I used to read both the Google Blog and IE Blog years ago and got good info from them both. I don't really read any blogs these days though.
-
I have a giant folder of music files I've collected over the years from friends and what not. I just open that in VLC and set it to random. No particular track or anything that I code to. Back in highschool/college friends would ask me to make compilation CD's of select songs from their collections. I'd always just rip each CD in it's entirety and save the tracks into my library rather than just what they wanted. As a result I have a ton of stuff and hardly a clue as to what exactly is in there. Every once in a while a song plays and I'm like 'WTF is this? It sucks.' or 'WTF is this, it rocks!' lol.
-
You need to either use eval() to run the code, or write it out to a temporary file and then include() that file. The later is probably the easiest. Note that running arbitrary code is dangerous. Someone with bad intentions would mess up your site pretty good if you just let them run whatever code they want. If your trying to do this for your own personal use, you'd probably be better off installing a local server using a package like xampp or wamp. If your trying to setup some kind of site to let users run code (like for tutorials or whatever) you need to take a lot of precautions on how you setup the server to prevent people from damaging stuff.
-
You're missing the () after execute, which means your never executing the query.
-
I don't really know perl but that sounds about right. You give it a relative path and it will determine what the actual full path is to the given file. This includes resolving things like symlinks on linux. Regarding the caching stuff, when you do something that causes PHP to lookup a stat() on a file it will cache that information so that future calls needing the same info for the same file can be resolved quickly. I find it is generally not necessary to call the clearstatcache function, but it's there if you need it. afaik the cache is only valid for the currently executing request so if you do something with a file in request A, then do something with that same file in request B, both will go to the file for any information rather than a cache. Clearing the cache would only be necessary if you're doing something something with the file multiple times in the same request.
-
I kind of have my own style I guess. From reading through the wiki-list it probably resembles 1TBS the most. I put the opening brace after the expression (eg if ($blah){). Having it on it's own line annoys me to no end. I use tabs for an indent rather than spaces. I rarely have any issues with this, but I can understand why spaces would be preferred in a large multi-coder environment. If I end up needing to split something across multiple lines, I usually do something like this: $a = sprintf("Welcome %s, your color is %s and your symbol is %s\r\n", $name, $color, $symbole ); or if ( $a == $b || ($c == $b && $x==$y ){ blah(); } I generally don't care what style someone uses, so long as it is readable and not a big wild mess like some people post to the forums here.
-
I'll agree to that. I used to be able to get to things like the maps api or translate tools pretty easy from the front page. Now I mostly search for the stuff because I can't seem to find it otherwise. I get other language results occasionally, but I've never really considered it much of a problem. It's usually just a couple here or there, not pages worth. And if it does look relevant I can usually just click the translate link next to the result. I'd say for the most part though google is pretty good at showing me English results only. Google's also pretty good at showing me relevant results right away too. I'm not a privacy nut that blocks any and all attempts by a website to track/figure me out though so google has a pretty good idea of what I am interested in. For example if I search "router" google shows me pages of stuff on the computer networking device, were as bing shows a mix between network devices and the woodworking tool. I've had similar good results when searching other ambiguous terms like that. I'm sure bing would do just as well if I used it and gave it a chance to figure me out but google already knows all that so it generally works better.
-
2 draws, 2 google, 1 bing. Even when I tought google was better, bing wasn't necessarily bad. Most of the time the first two or three results were the same, maybe just in a slightly different order. I use google for two reasons mainly: 1) It's built into chrome's address bar (i know bing is too but google is default). and 2) Habit, i've been using it for a long time. The few times I've used bing there hasn't really been anything that would make me go there over google.
-
is_null involves a function call which is a relatively costly operation in PHP, that is why there is a speed difference. I tend to use is_null anyway out of habit and I like the way it reads better when I skim code. In practice it generally makes little difference as you're probably not going to be calling it thousands of times. Either method accomplishes the same task so use whichever you prefer.