Jump to content

PFMaBiSmAd

Staff Alumni
  • Posts

    16,734
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by PFMaBiSmAd

  1. Assuming that you have fetched a row from the database in $row, the following will handle the conversion of numeric values - <?php function make_int($val){ return is_numeric($val) ? (int)$val : $val ; } $row = array_map('make_int',$row); echo json_encode($row); ?> The above could be extended to handle boolean values.
  2. If you have had no success with any script, it would be better to pick the one you feel most comfortable with and troubleshoot why it is not working. You may have some fundamental issue on your server/development system that would prevent every suggested script from working. Short answer: In programming, it is aways better to troubleshoot and find the root cause of a problem then to waste a lot of time just trying things and throwing away code simply because it doesn't work. Pick the script you understand the best and post it along with a statement of the symptoms and any errors you got when you tried it.
  3. A) See the following thread for how you would use 'lookup' arrays to map one value to another - http://www.phpfreaks.com/forums/index.php?topic=337702.0 B) You should also use an array to hold the resulting values, with associative key names that indicate the purpose of the value, rather than $a, $b, ... You can then use array_sum to get the sum of the values. C) You should not use $_REQUEST if possible. Use the correct $_POST or $_GET or $_COOKIE variable where the data is coming from. D) You should validate all your external data so that your code behaves in an expected way when the data is not present or when it does not have an expected value.
  4. You would use an array with the key/value pairs, so that you don't need to alter your program logic every time you add or change a value.
  5. Have you echoed $sql so that you know if it actually contains what you think? I suspect, based on the lack of actual code, that where you are setting $Model at and where you are using it are not in the same scope.
  6. mysql_real_escape_string only protects against sql injection in string data, i.e. data enclosed by single-quotes in a query. For things like numerical data (which is not enclosed by single-quotes in a query), you need to validate/cast the data as a number in order to prevent sql injection, because it is possible to form sql that contains no quotes for which escaping the quotes doesn't do anything because there are no quotes to escape.
  7. I vote for the or something. It will return a result resource consisting of the set of rows that were matched. The values that weren't matched (didn't exist in the table) won't exist in the result set.
  8. In the first post in this thread you were using an array name for the Points[] form field. All you need to do is make the team_id[] field an array name as well. In your form processing code you should use a foreach loop to iterate over the $_POST['team_id'] array so that your code will operate for any number of values. Your code is using an UPDATE query. This will change/edit the existing values in the table. It will not add a new set of scores. To do that you would need to use an INSERT query and you would need a column that uniquely identifies the different sets of scores, such as a date.
  9. type='button' doesn't actually do anything by itself (requires a javascirpt event to be used.) Use type='submit'
  10. http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#function_in
  11. The first two code examples you posted are file system paths, being used by php functions that operate on files on the server. The first code is using a file system path relative to the main php script that is being executed. The second code is using an absolute file system path, that starts at the root of the current hard disk. If you want to make an absolute file system path that refers to a folder within your document root folder, you can use $_SERVER['DOCUMENT_ROOT'] to get the full path on your server to your document root folder, then concatenate the rest of the path onto that value. The last code example you posted is HTML markup that is used by a browser to fetch an image. The src="..." attribute is a URL to where the image can be fetched. A leading / on a URL makes it a domain relative URL. The browser takes the domain of the current page and appends a domain relative URL to it to arrive at a the URL to fetch.
  12. Where there's a will, there's a way (I don't recommend that you actually use this method as you will never be able to read and troubleshoot what your code is doing) - <?php $state = 'state'; // variable function name $country = 'country'; // variable function name ?> <span class="dark_grey"><?php echo ($company['country'] == 'United States') ? "{$company['city']}, {$state($company['state'])}" : "{$company['city']}, {$country($company['country'])}"; ?></span>
  13. <?php // get the date from the URL or get the current date $month = isset($_GET['month']) ? sprintf('%02d',(int)$_GET['month']) : date('m'); $year = isset($_GET['year']) ? (int)$_GET['year'] : date('Y'); $date = "$year-$month"; // determine previous/next month (valid from 1970 (or 1901, depending on php version and operating system) through 2038 only) $previous = explode('-',date('Y-m',strtotime($date . '-1 -1 month'))); $next = explode('-',date('Y-m',strtotime($date . '-1 +1 month'))); // produce previous/next link $query = (empty($_GET)) ? array() : $_GET; // get an empty array if no existing $_GET parameters or get the current $_GET parameters $query['month'] = $previous[1]; // set or replace the month parameter $query['year'] = $previous[0]; // set or replace the year parameter $prev_link = "<a href='?" . http_build_query($query, '', '&') . "'><img src='prev_month.png' alt=''></a>"; $query['month'] = $next[1]; // set or replace the month parameter $query['year'] = $next[0]; // set or replace the year parameter $next_link = "<a href='?" . http_build_query($query, '', '&') . "'><img src='next_month.png' alt=''></a>"; // output the links echo $prev_link . " Previous Month Current date: $date Next Month " . $next_link; ?>
  14. Your code is not checking if the query executed without any errors before attempting to access the data from the query. If you use mysql_error() in some error checking and error reporting/logging logic, it will tell you why the query is failing. Are you debugging this by browsing to the file to see the errors or are you running this as a cron job and checking the php errors in the log file?
  15. Is error_reporting set to E_ALL and display_errors set to ON so that the or trigger_error() logic would actually do anything?
  16. The output on the action page that you posted is basically the last set of values, repeated, because you are reusing the same names for each set of fields. I'm also guessing that you have hard-coded a value of 3 in a loop and that is why you got three copies of the same data. You also don't need to submit the team names because you already have the id for each team. You need to use array names for the fields so that each set of data values will be available and the data can be processed in the php code using array functions. Using arrays will make ALL your code, both in the form and in the form processing, much simpler. Once you change to using arrays, the $_GET data will look like this in your php code (without the teamName field) - Array ( [team_id] => Array ( [0] => 5 [1] => 22 [2] => 40 ) [points] => Array ( [0] => 4 [1] => 0 [2] => 2 ) ) Edit: You also have space characters (the + in the URL data) at the start of each team_id and teamName data value that you should find the cause of and eliminate.
  17. You are outputting the heading inside of the loop, so of course it is repeated. You would need to output the heading once, before the start of the loop. You would also want to put the echo '</ul>' ; after the end of the loop.
  18. The DB Gods sacrifice a kitten every time someone tries to use a Database like it is a spreadsheet. Several kittens died for this thread. :'(
  19. We cannot answer the question you are asking without knowing what the php code is doing. BTW Wordpress is just a php script itself. The php code could be storing the content in the php file itself, in a .php file that is being included into the main .php file, in a .txt file, in a .csv file, in a .xml file, in a database, reading it from some other site, ... The whole point of programming is to write code to do what the programmer wanted, when, and where he wanted it. Whoever wrote your php scripts decided (or was told) where to store the content and that is where the content will be. If the php script was well written, there should be an administrative web page that lets you edit/add content. If you have some php code you would like help with, you would need to post it.
  20. Is this custom written php code or is it based on an opensource php script, such as Joomla, Mambo, Mediawiki, phpbb, SMF, Wordpress, or similar (there would generally be comments in the .php source code that identifies what it is.)
  21. That would indicate that your logic is incorrect or has a php syntax error and you need to troubleshoot what it wrong with it and find out what it is actually doing. If you want help with some specific code, you need to post it along with a statement of what it did when you tried it and post any errors you got as well, but putting multiple unrelated tables in a single query is incorrect.
  22. Also, what relationship exists between the data in these three tables? If there is no relationship between the data in the three tables, you should not have them in the same query because the result you get is not what you think it is.
  23. A query that executes without any database errors, even if the query matches zero rows, is a successful query and your $rs variable will contain a result resource. You would need to use mysql_num_rows() to find out how many rows the result set contains. Your existing code will only echo the There are no matches for this... message if the query failed due to an error of some kind (connection problem, sql syntax error, spelling/typo in the table/column names, ...)
  24. You would use GROUP BY item_id term in your query to consolidate rows with the same item_it into groups and use SUM(price) to sum the price within each group. If you show your existing query, someone can probably help.
  25. Not sure if this has anything to do with your current problem, but if you revisit your last thread in the forum, you will find that someone pointed out that in your previous code (and also in the current code in this thread), that you are not executing the SELECT query that is checking if an asset already exists or not. Someone also pointed out in that previous thread that you should have the error_reporting/display_errors settings set to specific values to get php to help you.
×
×
  • 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.