Jump to content

DavidAM

Staff Alumni
  • Posts

    1,984
  • Joined

  • Days Won

    10

Everything posted by DavidAM

  1. It's pretty much the same thing, you just have to take the season into account: (SELECT * FROM #__tv WHERE published = 1 AND ( (season < $curSeason) OR ( season = $curSeason AND episode < $curEpisode) ) ORDER BY season DESC, episode DESC LIMIT 1) UNION (SELECT * FROM #__tv WHERE publishied = 1 AND ( (season > $curSeason) OR (season = $curSeason AND episode >= $curEpisode) ) ORDER BY season ASC, episode ASC LIMIT 2) Using a UNION lets you do it with a single call to the database.
  2. I don't think this is valid syntax: $this->"queryid".$id = $result; you would have to build the dynamic property name first: $qID ="queryid".$id; $this->$qID = $result;
  3. To access two different database servers you would need two different connections. But you can access multiple databases on the same server using a single connection. In fact, you can access multiple databases in a single query: SELECT * FROM dbOne.table1 AS T1 JOIN dbTwo.tableBravo AS T2 ON T1.coldID = T2.colFK You can also change the default database for a connection at any time using mysql_select_db() (or similar function). Inside your loop, just qualify the INSERT statement to the second database: INSERT INTO dbTwo.tableName (...) VALUES (...)
  4. Just concatenate the strings together: $mail2->Subject = $_POST['name'] . ' - ' . $_POST['email'] . " - confirmation mail";
  5. Echo your SQL just before you execute it. Take a close look at it to see if there is something wrong. Test the return value from the execution (i.e. mysql_query() or whatever) to see if it succeeded. -- If you're using mysql, you can echo mysql_error() to see the error message. Turn error reporting on in your PHP script to see if there are any PHP errors causing problems.
  6. The default does NOT have to be at the end of the switch. I sometimes put it at the top of the switch because it more clearly "documents" what that particular switch is doing. The more correct statement would be: "the LAST case (or default) does not require a break". I have also gotten into the habit of ALWAYS including a break, so if I come back later and add a case at the end of the switch, I don't forget to add a break to the preceding case. back to the OP It looks like you are trying to create a switch dynamically, and I really don't think you can do that. However, the solution, I think, is much simpler: $answers = explode("/", $results['answer']); if (in_array($userinput, $answers)) { echo $answers[0]; } else { echo 'incorrectguess'; }
  7. We would have to know the structure of the database, specifically the table you are trying to put them into. The code snippets you provided do not indicate to structure of your database and tables. If you are trying to put them in a single field as a comma-separated string, then, yes, you would use the implode() function to build that string. You could give it a try and see if it does what you want.
  8. The code in your first post: GetSQLValueString($_POST['father'], "text"), indicates this function expects a value and a type. However, in your next post: GetSQLValueString($_POST['father'][1], $_POST['father'][2]), you are passing two values. What exactly are you trying to do with the result of the checkbox array? Are they supposed to go into a single field, or are there separate fields for each possible answer? Be aware that you may get any number of elements in the "father" array. And, in fact, the "father" element will NOT exist in the array if the user does not check any boxes. For example: <input type="checkbox" name="father[]" value="answer 1" /> answer 1</label> <br /><label> <input type="checkbox" name="father[]" value="answer 2" /> answer 2 </label> <br /><label> <input type="checkbox" name="father[]" value="answer 3" /> answer 3 </label> <br /> If the user checks the first and third box, the resulting array will be: $_POST[father][0] = 'answer 1'; $_POST[father][1] = 'answer 3'; If you are trying to put all the values in a single field, then perhaps something like this will work: $fatherValue = (isset($_POST['father']) ? implode(',', $_POST['father']) : ''); GetSQLValueString($fatherValue, "text"), If you want them in separate fields; or even better, in separate rows of a child table, you will have to loop through each element and build and insert statement.
  9. I don't think that the query string can be used as a condition of the redirect or rewriterule directives. I think you have to use the RewriteCond to test the query string and then use a rewrite rule to do the redirect. Someone correct me if I'm wrong. If you want to redirect ALL requests for this_page.php - regardless of what is in the query string: RewriteRule ^this_page.php$ /this_New_page.php [R=301,L] If you want to redirect ONLY requests whose query string STARTS with "id=": RewriteCond %{QUERY_STRING} ^id= RewriteRule ^this_page.php$ /this_New_page.php [R=301,L] If you have more complex conditions, post them, and be very specific. The code above will NOT redirect this_page.php?mode=delete&id=4 but would redirect this_page.php?id=4&mode=delete
  10. See fopen(), fgets(), fwrite(), and fclose(). It looks like fgets() will be better than fread() here. Something along these lines $fIn = fopen(filename, 'r'); $fOut = fopen(newFilename, 'w'); while ($line = fgets($fIn)) { $line = '<p>' . str_replace(array("\r","\n"), "", $line) . "</p>\n" ; fwrite($fOut, $line); } fclose($fIn); fclose($fOut);
  11. You did not clearly state a problem, so this "solution" might not solve it; This statement: if (isset($id))($row){ does not seem to be syntactically correct to me. Did you, perhaps, mean: if ((isset($id)) AND ($row)) { However, isset($id) will always be true there, because you set it at the very first line. Perhaps a better test would be: if ((!empty($id)) AND ($row)) { Plus you have some duplicated code there. I would probably re-write the entire IF statement as: if ($row) { session_start(); $_SESSION['user_id'] = $row[0]; $_SESSION['residentname'] = $row[1]; $_SESSION['unit_num'] = $row[2]; setcookie("TestCookie", time()+3600); /* expire in 1 hour */ $resite = "submitjob.php"; if (!empty($id)) $resite .= "?do=viewone&id=$id"; header("Location: $resite"); exit(); } else { echo "Sorry the app didn't find a match."; }
  12. I'm not a CSS guru, but I see you are setting the TABLE width to 100% in your CSS. This tells the browser to use the full width (of the containing element) for the table. Since you don't provide a width for the cells (columns), the browser is going to choose how wide to make each column. I think you might see slightly different widths on different browsers. My experience is that the browser chooses to "stretch" all columns to fill up the space. I don't know how to tell the browser to use the minimum required space in a particular column; or to apply all "extra" space to a particular column. I'm not sure that it can be done at all. You can remove the width specification from the table. Then the browser should make the cells just large enough for the contents. This will result in a table less than 100% wide, so if you leave the borders on, the table will not cover the entire DIV. Without the width specification, the table will not expand to more than 100% if the contents are too large; it would just cause word-wrap in the cells.
  13. The problem is with the HTML. The heading that you put in the first cell of the first row is making the entire column wider than you want it. Try forcing that heading to span both columns: <tr><td class="row_header" colspan="2">' . $row1['uni1'] . '</td></tr> That should allow the other cells to shrink. If that does not work, you may have to remove that heading row and just use an <H1> or <H2> immediately above the table.
  14. You are using single-quotes (around the array index "id") inside of a single-quote delimited string. The single-quote before "id" is ending your string, and the "id" is an unexpected string. Since you can't put a variable inside a single-quote delimited string, you need to delimit the string with double quotes: $emp = "SELECT employees.function FROM employees WHERE employees.userid=${r['id']}";
  15. Just for reference, it seems you are not using the same variable for counting and for testing: if($total_hp < 30){ $player = $player_hp + 5; None of your code snippets defined $total_hp, they all referred to $player_hp
  16. You have to count the number of posts (or whatever) for each user and order by that count. Since you have no GROUP BY in that query, the COUNT will be 1 for each row. I don't know the layout of your table, but the query should be something like this: SELECT user, COUNT(post_id) -- Count the primary key on the table FROM post_table GROUP BY user ORDER BY COUNT(post_id) DESC -- show the user with the highest count first LIMIT 10; -- only return 10 rows
  17. @tibberous When I am programming, my hands are on the keyboard. It is a waste of time to reach for the mouse for a simple operation that can be done from the keyboard. @OM2 I am using v5.6.8 of Notepad++, if I go to Settings -> Preferences and select the MISC. tab, there is a group box labeled "Document Switcher". In that box is a check box labeled "Enable MRU behavior". If I uncheck that box, the CTRL-TAB switching changes to sequentially tab through the files. Give it a try, I think that is what you are looking for. By the way, if you uncheck the "Enable" option in that same group, CTRL-TAB works exactly like other Windows programs. (You don't even see the list, it just moves to the next file and CTRL-SHIFT-TAB moves to the previous file). I have never had 100 files open at one time, maybe as many as 10. But once I got used to the "MRU Behavior", I found it helpful. I guess if I had found this option early on, I probably would have unchecked it. I find the search feature usable, and have visited the website mentioned in the help file (http://www.scintilla.org/SciTERegEx.html). But it seems to behave differently than I am used to with PHP RegExp. So, I don't use the Regular Expression search as much as I would like to. My biggest complaint is that Compare plugin maps ALT-S to "Compare to Last Save" and I would often hit ALT-S when trying to quickly type ALT-F S (File -> Save). Whenever I did that, it would start a compare, but it LOST ALL CHANGES TO THE CURRENT FILE. I finally found the setting to remove the ALT-S mapping so it would quit, but man I lost a lot of code changes because of my fat fingers.
  18. 1) It took me a long time to get used to the CTRL-TAB functionality. What I have learned is that it goes to the tab that was active before the one you are in. It has actually become useful now that I understand what it is doing. Even with 5 or 6 files open, if I'm editing File1 and CTRL-TAB to File2, then copy some text, CTRL-TAB takes me back to File1, paste it, CTRL-TAB back to File2, copy, CTRL-TAB to File1, paste, etc, etc. It appears that if you hold the CTRL key and keep pressing TAB, it will cycle through all of the files in the order of most recently active. The ones you pass through do not count as becoming active. So, from File1 CTRL-TAB-TAB (through File2) to File3 (release CTRL), then CTRL-TAB goes back to File1 (File2 was never active). So CTRL-TAB now goes back to File3. It actually is much more usable than CTRL-TAB'ing through all open files or reaching for the SHIFT key to CTRL-SHIFT-TAB backwards. 2) I have not had much luck with multi-line search or replace. I've tried the RegExp search, but I don't have much luck with it for either search or replace. 3) I've never had problems searching for the '$' sign. I guess it would be a problem if the RegExp box is checked (since it is a meta-character in RegExp). 4) If you are running Linux, take a look at sed. P.S. I'm running Notepad++ on Windows
  19. basename() strips off the path component, leaving only the filename and extension. I don't think the tmp_name will usually have a path component, so it shouldn't really matter - however, if PHP were to put a path component on the tmp_name, it would need to be there for move_uploaded_file() to work.
  20. This: if(move_uploaded_file(basename($_FILES['file']['name']), $target_path)) is not correct. You should be moving the temporary file (created by the upload process) to your desired destination. The 'name' element of the FILES array, is the filename from the user's system - well, it was before you changed it a couple of lines above. The uploaded file, the one you need to move is in the 'tmp_name' element of the array -- and do NOT use the basename() function on it. if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path))
  21. The second error message is a result of the first error. Since the first error was written to the browser, the header() call fails. So, once you fix the first one, the second one should go away. The first error is caused by the use of $HTTP_POST_VARS. This variable was deprecated a while back. It may be that your host upgraded PHP or otherwise changed the php.ini file so that the variable is no longer defined (see PHP: $_POST - Manual). You should change that to $_POST. It looks like you are using $_POST everywhere else in that code, so it should not be too much trouble. if(sizeof($_POST)) { $body = ""; while(list($key, $val) = each($_POST)) { //<--Line 37 $body .= "$key: $val \n"; }
  22. The query is probably working fine. The problem is that you are returning multiple columns with the same name. For instance: SELECT Table1.StateName, Table2.StateName FROM ... will return two columns and they both will be named "StateName". When the database access layer (i.e. mysql_fetch_assoc()) dumps this into a PHP array, one column overwrites the other. You cannot have two indexes in the same array with the same name. The column names will NOT be qualified by the table name in the PHP array. So, you have two choices. Use mysql_fetch_array() to get the columns as a numeric array (without column names) or use an alias on some of the columns so they will have a different name in the array: SELECT Table1.StateName, Table2.StateName AS OtherStateName ...
  23. In database theory, NULL means that the value is not known; while an empty string means the value is known to be nothing. For instance: if you have a field in the users table for FavoriteColor; a NULL value means you don't know what their favorite color is, while an empty string would mean you know that they don't have a favorite color. In practice, a NULL is treated differently than an empty string. This will never return any results because NULL is never equal to anything, not even another NULL, SELECT * FROM Users WHERE FavoriteColor = NULL; This will return records with an empty string but NOT records that are NULL SELECT * FROM Users WHERE FavoriteColor = ''; This will return records that are NULL, but NOT empty strings SELECT * FROM Users WHERE FavoriteColor IS NULL; To get empty strings AND NULLs, we would use: SELECT * FROM Users WHERE IFNULL(FavoriteColor, '') = ''; which says if the field is NULL pretend that it is an empty string.
  24. As I said, I'm no expert at rewrite. I'm not really sure what regexp constructs are allowed in it. You might try changing it to this: RewriteRule ^Popular\.html/Page([0-9]*)$ index.php?getbypopular=1&page=$1 just in case the "\d" construct is not allowed. Note: you could add a custom error page using something like this in the .htaccess ErrorDocument 404 /err404.php Then write the err404.php file to just dump $_SERVER to the screen <?php echo '<PRE>'; print_r($_SERVER); So you can see what the request looks like. It might help you to debug this. Note: Do NOT do this on a production server, it could show information you don't want visible to hackers. If you absolutely have to put it in production, remove the file and directive as soon as you get the results. If you have access to the main http.conf file, you can turn on rewrite logging. This dumps ALOT of information about the rewrite process to a log file. It cannot be set in the .htaccess file (at least not to my knowledge) and should not be left on in production because it slows things down and it dumps ALOT of information into log files. Did I mention that the rewrite logging will write ALOT of stuff to log files using up large amounts of disk space?
  25. I'm not an expert with rewrite, but my first attempt would be adding another rule (after the one you have): RewriteRule ^Popular\.html/Page(\d+)$ index.php?getbypopular=1&page=$1
×
×
  • 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.