-
Posts
16,734 -
Joined
-
Last visited
-
Days Won
9
Everything posted by PFMaBiSmAd
-
Your opening php tag, isn't. It should be <?php
-
<?php function version_add($current,$add){ $current = explode('.',$current); $add = explode('.',$add); foreach($current as $key=>$value){ $current[$key] += $add[$key]; } return implode('.',$current); } $currentversion = '0.2.1'; $newversion = version_add($currentversion,'0.0.1'); echo $newversion;
-
Php variables are case-sensitive. It's $_SESSION
-
You are getting a php syntax error on a specific line in your code, indicating an unexpected AS (the T in T_AS means TOKEN - i.e. php is a parsed, Tokenized, interpreted language) was found on that line. If you look at that actual line in your code, you will see that you have used an as $hits inside an is_array statement. Since the purpose of an is_array statement is to test if the supplied argument is an array, why do you have the as $hits in there? Sorry to be blunt again, but you simply must think about what you are doing when you write and debug your code. You must also lookup what each statement does. is_array — Finds whether a variable is an array. The only thing is_array takes as a parameter is a variable name that may or may not be an array.
-
Date not posting in mysql database from php script
PFMaBiSmAd replied to toney's topic in PHP Coding Help
Also, the date and mktime functions, depending on php version, operating system, and hardware register size, don't work for years that are older than 1970. You would be better off taking the year number, month number, and day number, validating the date (see: checkdate) and building a YYYY-MM-DD date string yourself (see: sprintf so that you can supply leading zeros where needed.) -
I recommend that you look at the at's as's in your code. Only php foreach() statements have them. Edit: fixed typo
-
how can php Undefined index a freaking row value?
PFMaBiSmAd replied to Monkuar's topic in PHP Coding Help
So, did you actually find out why the subforums1 index does not exist when the code is expecting the data from the query to have that index in it? -
Or an array_diff and a few count statements - <?php $main = range(10,20); $subarray = array(1,12,13); $diff = array_diff($main,$subarray); if(count($diff) == count($main) - count($subarray)){ echo "all elements in the subarray were found in the main array"; } else { echo "not all the elements in the subarray were found in the main array"; }
-
You can probably use array_intersect , followed by an array_diff to find if all the elements in one array are found in another array.
-
Date not posting in mysql database from php script
PFMaBiSmAd replied to toney's topic in PHP Coding Help
The time function does not take any parameters. Perhaps you intended to use mktime ? -
Specifically - $position = (($currentpage-1)*$rowsperpage)+1;
-
You would take the page number and the number of records per page that your pagination script is using and calculate the starting number for any page.
-
Similar to what Psycho just posted above - <table border="1"> <tr><th>Sushi</th><th colspan="2">Ingredients</th></tr> <?php // each row needs a <tr></tr> // the first row under each type is a complete row // the 2nd - nth row under each type do not have any <td></td> for the 1st column, but need to start with a <tr> foreach ($sushi as $type => $ingredients){ echo "<tr><td rowspan=" . count($ingredients) . ">$type</td>"; // start the first row $first = true; foreach ($ingredients as $name => $meas){ if(!$first) echo "<tr>"; // start the 2nd - nth row under each type $first = false; echo "<td>$name</td><td>$meas</td></tr>"; // the rest of each row } } ?> </table>
-
You have three different INSERT INTO notifications ... queries, inside of conditional logic, in code that isn't indented so that it is readable. Are you sure that your logic is even what you want and that any code with one of the insert queries is even executing? Are you sure that the insert query is not returning an error?
-
The reporting/display/logging of the error message is just the last step in the error handling code that php executes every time it encounters an error every time your code runs. The reason you would want to find and fix the cause of any php produced error message is so that only real errors will be reported and displayed/logged, so that you will know when a legitimate visitor did something that your logic did not take into account or a hacker is trying (did) break into your script and how he did it, so that you can find and fix the problem. If you are getting 100's of errors, producing a gigabyte size error log file, you are definitely not coding fine.
-
Associative array index names are strings and need to be quoted, the reason being is that you could be using defined constants to provide the actual values and the syntax needs to support both methods. Use quotes around index names that are literal strings (the extra code that php executes behind the scenes in the error response code every time it finds an unquoted array index name is a killer.)
-
Because you are not specifying a From: email address header, it's likely that the MTA's relaying restrictions are not being met (either the To: address or the From: address must normally be a valid mail box hosted on the sending mail server.) Try putting in a From: email address header that contain your godaddy hosted email address and see if it will send to an outside To: email address.
-
Did you check the mysql manual for the correct syntax for what you are doing, like the error message suggests? The following is the insert syntax definition for the form of the insert query you are using, with the parts you are trying to use highlighted in red - It's not possible to write code or a query for your data, until you learn the correct way to write the code or a query at all. Programming is an exact science. Leaving out one keyword changes the meaning of what you are doing and makes it so that the programming language or sql language doesn't know what you are telling it to do.
-
sprintf-like for variable-only purposes without printing
PFMaBiSmAd replied to neuroxik's topic in PHP Coding Help
Since no one here knows what it is you are asking or want as a result, I'll take the next guess - <?php $c = array('i','ì','í','î','ï'); $str = "Bla bla '%s' bla"; $sql_str = 'WHERE '; foreach($c as $v){ $sql_str .= sprintf($str, $v); } echo $sql_str; -
sprintf-like for variable-only purposes without printing
PFMaBiSmAd replied to neuroxik's topic in PHP Coding Help
Since your example isn't valid mysql, I'm not sure what it is you are actually trying to produce, but one way of putting together a query with multiple repeating terms is to implode an array with the right 'glue' to produce a term that you then put into the final query statement. Do you have an actual example of an array of values and what query you want to produce from those values? -
If you indent your code properly, you can probably see that you are only performing the UPDATE query for one of the logic conditions. Also, your if(){}else{} if logic does not cover the case where $hoes is equal to $hobedding. You are also needlessly re-executing the select query inside of the loop. The following should be (untested) equivalent to what you are trying to do (I renamed variables to match their meaning in the table) - <?php include "server.php"; $sql = "SELECT * FROM players"; $que = mysql_query($sql); while($res=mysql_fetch_array($que)) { $hoes = $res['Hoes']; $maxhoes = $res['MaxHoes']; $hoimcome = $res['HoIncome']; $hoesmorale = $res['HoesMorale']; if ($hoes <= $maxhoes) { $income = (250 * $hoes * $hoincome * $hoesmorale); } else { $income = (250 * $maxhoes * $hoincome * $hoesmorale) + (125 * ($hoes - $maxhoes) * $hoincome * $hoesmorale); } $sql5 = "UPDATE players SET cash = cash + $income WHERE id = {$res['id']}"; mysql_query($sql5) or die(mysql_error()); } ?> And you are aware that mysql can perform logic in a query. The following (untested) is all you really need to do - <?php include "server.php"; $sql5 = "UPDATE players SET cash = cash + IF(Hoes <= MaxHoes,250*Hoes*HoIncome*HoesMorale,(250*Hoes*HoIncome*HoesMorale) + (125*(Hoes-MaxHoes)*HoIncome*HoesMorale))"; mysql_query($sql5) or die(mysql_error()); ?>
-
Most php4 code will work as-is under php5. There are very few incompatible changes in going from php4 to php5 and they are documented here - http://us.php.net/manual/en/migration5.php Also see the versions 5.1.x, 5.2.x and 5.3.x. links on that page. However, a lot of php code is poorly written using php's lazy-way and non-portable short-cuts and long ago depreciated features and functions that where suitable for turning in programming assignments that 'work' but which have no place in actual web applications. If you are suddenly getting a lot of php notice, warning, and error messages, it is most likely that those were always occurring as the code runs, but were hidden by php's error_reporting, display_errors/log_errors settings. You will simply need to find and fix everything that is producing an error message. The reason you would want to find and fix the cause of any php produced error message is so that only real errors will be reported and displayed/logged, so that you will know when a legitimate visitor did something that your logic did not take into account or a hacker is trying (did) break into your script and how he did it, so that you can find and fix the problem.
-
Sorry, cannot help you without knowing all the conditions and context of what you are doing. You must have some kind of logic to test the value and produce/return the zero value for negative numbers. Even using a built-in or user written function would require the use of a statement. Now, if you will care to fully explain what it is you are trying to do and in what context, I'm sure someone can probably help you.
-
$num = ($num < 0) ? 0 : $num;
-
@spacepoet The last code you posted (reply #6) is even worse crap and more out of date and inconsistent then the original code you were using at the start of this thread. You appear to be using a programming method called throw-a-way coding. You try something, it does not work. Instead of learning what it means and what it is doing, what is wrong with it, and how to fix it, you throw it away and try something else. All this does is waste a huge amount of time. It will literally take you 100's of times longer to arrive at working code by proceeding this way. This is not programming. You must learn what each line of code means and how it contributes to the goal you are trying to accomplish in order to be able to write code yourself or even to adapt code that someone else wrote to something that you want to accomplish.