Jump to content

kicken

Gurus
  • Posts

    4,695
  • Joined

  • Last visited

  • Days Won

    177

Everything posted by kicken

  1. The constant __FILE__ tells you what file is currently executing. This will change for included files. eg: common.inc.php <?php var_dump(__FILE__); ?> index.php: <?php include 'common.inc.php'; var_dump(__FILE__); ?> The var_dump inside of common.inc.php will output a path such as: /home/doubledee/html/common.inc.php where as the one inside index.php will output: /home/doubledee/html/index.php So, you can use __FILE__ to determine what file your currently executing in, but not what file was actually requested. __FILE__ is mainly useful for logging errors or deriving file locations relative to the current file.
  2. SELECT * FROM 2012_tournaments WHERE start_date_time < CURRENT_TIMESTAMP That would return all the rows where the start_date_time column has a date/time less than the current date/time. It's not clear from your code above what exactly your trying to do, so it's hard to provide much further help. The above query assumes that you have correctly defined the start_date_time column as a DATETIME datatype. If you did something silly like make it a VARCHAR you'll have to change it.
  3. There are other ways to determine the files name yes. PHP_SELF isn't as bad as some people make it out to be though. The only real danger is if you output it to a page without running it through htmlentities first. Using it in other ways is not generally a problem. Someone can't completely change PHP_SELF to some other url like you implied above. They can only add additional information to the URL. In the example above that might cause your if condition to fail, but it's not any sort of big problem really. The user would just end up back at the login page after logging in. People who use your site as intended will never have this issue, only people who try and abuse it would. Make a page and print_r($_SERVER), that will show you what your alternatives are. I believe a 'safer' alternative to PHP_SELF is SCRIPT_NAME but I can't remember for sure. I typically don't use either value.
  4. That's one of the things you have to watch out for as a developer. There have been numerous times where I have been tasked with something that the requester though was simple, then I ask them all kinds of questions regarding things they 'didn't think about' and soon they realize it wasn't so simple after all. There's been a few times as well where I will do just like you did and develop it in a certain way just to have it rejected and need redone because that's not what they ment.
  5. I could agree with a mark off for commenting due to this line: float PackageWeight = 0, ShippingDistance = 0, Charge = 0, Distance = 0; You have two different variables related to distance, but the problem description only includes one distance (what the user entered for their shipping distance). It's not obvious what the other distance variable is for until you read the code later on. There's other way to make it more obvious without necessarily having to comment on the variables, but I could agree with a mark off in general for lack of clarity. I could see how that mark could be the case as well. Your code calculates the rate using a fraction which means it will essentially be prorated. It doesn't specifically say in the problem whether this is desired or not, but typically things are not prorated in my experience. This is a point where you could have asked for a clarification. Example: I'm shipping a package weighing 5kg a distance of 100 miles. By your calculation, we have a total cost of: $0.44. (2.20 * (100/500)) Instead of a fractional distance, lets treat it as blocks. 0-500, 500-1000, 1000-1500, ... By doing that, we end up with a shipping cost of $2.20: (2.20 * (ceil(100/500)).
  6. It seems to me your problem has to do with the &year= variable in your URL. It's conflicting with your wordpress setup causing WP to error with no posts found. Use a different variable name
  7. If your using mysql, when your doing your query for the business data you can use the clause: ORDER BY RAND() to get the results in a random order. Not sure if other db's have a similar method. Otherwise in PHP, read the results into an array, then use shuffle() to randomize it before outputting it.
  8. On your stats page, echo you your generated sql query and then run it in mysql directly (using something like phpMyAdmin/mysql workbench/mysql cli tool). That will let you test to make sure your query is correct and returns results. A couple other things I notice, though probably not a cause of your current problem: 1) You should run your variables through urlencode before putting them into a url, and htmlentities before outputting them to your html. 2) You should run your variables through mysql_Real_escape_string before using them in a query.
  9. Sorting them out into an array then putting that into the table makes it easier. The code below is untested, but shows the basic idea. require("includes_database/mysqli_connect.php"); $query="SELECT forum_id, topic_title, topic_id, FROM phpbb_topics WHERE forum_id IN (13, 14, 15, 16)"; $result=mysqli_query($dbc, $query); $whichColumn = array(13 => 0, 14 => 0, 15 => 1, 16 => 1); $columns = array(); while ($row=mysqli_fetch_array($result, MYSQLI_ASSOC)){ $col = $whichColumn[$row['forum_id']]; $columns[$col][] = $row; } echo "<table border=1 cellpadding=2>"; echo "<tr><td>Lost</td><td>Found</td></tr>"; for ($i=0,$max=max(count($columns[0]), count($columns[1])); $i<$max; $i++) { echo'<tr>'; if (isset($columns[0][$i])){ $row = $columns[0][$i]; echo "<td width='15%'><a href=/sahbb/viewtopic.php?f=".$row['forum_id']."&t=".$row['topic_id'].">".$row['topic_title']."</a></td>"; } else { echo "<td width='15%'> </td>"; } if(isset($columns[1][$i])){ $row = $columns[1][$i]; echo "<td width='15%'><a href=/sahbb/viewtopic.php?f=".$row['forum_id']."&t=".$row['topic_id'].">".$row['topic_title']."</a></td>"; } else { echo "<td width='15%'> </td>"; } echo'</tr>'; } echo "</table>"; mysqli_free_result($result); mysqli_close($dbc);
  10. What I would do probably is first, build a SELECT query that will pull all existing records matching whatever was in the csv file. Say your checking the Name column, then something like: //Assume $csv is the data from the csv file in an array $names = array(); foreach ($csv as $row){ $names[] = mysql_real_escape_string($row['name']); } $sql = "SELECT Id, Name FROM table WHERE Name IN ('".implode("','", $names)."')"; $res=mysql_query($sql); $existingData=array(); while ($row=mysql_fetch_array($res)){ $existingData[$row['Name']] = $row['Id']; } //Now you can check if something exists by testing for it in $existingData foreach ($csv as $row){ $exists = isset($existingData[$row['name']]); if ($exists && $ignoreNew){ continue; } else if ($exists && $update){ //do update query } else { //do insert query } }
  11. Your already calculating how many stars they have access to based on the amount. Just do that same calculation when they submit the form and make sure their selected start falls in that range. Your range seems a bit confusing to me though. Would have expected $20 to get stars 1-40 if $5 gets you 1-10. No need for a max stars column, just use their total donation amount to calculate the max stars on the fly.
  12. Sounds fine to me. A lot of places just pass the current url as a hidden input in the login form. Either way is probably fine. Using the session would prevent people from fiddling with the url.
  13. That is because a where clause applies only to a single row at a time. Each individual row cannot match both 'red' and 'black'. You have to use OR to get all rows matching either. Once you have that, you can use PHP to narrow the results further. One method would be to group the rows by type into sub arrays, they check each type to ensure it contains both values, Based on your first post: <?php $sql = "SELECT term_id, tag_id FROM points_tags WHERE term_id IN('".implode("','", $tagArr)."')"; $res = mysql_query($sql); $groups = array(); while ($row=mysql_fetch_array($res)){ if (!isset($groups[$row['tag_id']])){ $groups[$row['tag_id']]=array(); } $groups[$row['tag_id']][] = $row['term_id']; } $hasAll=array(); foreach ($groups as $tag=>$terms){ if ($terms == $tagArr){ $hasAll[] = $tag; } } print_r($hasAll); ?> Untested, but something like that should do what you want.
  14. Answered over on devshed http://forums.devshed.com/php-development-5/drop-down-box-default-871422.html
  15. I find that somewhat hard to believe. One, because they would have to specifically disable json for it to not be available, and two because it is actually quite commonly used so if they were really trying to target the average user, they would have it. If your host doesn't support it, pick any other random host with php 5.3, they will almost surely have it. Or get a VPS where you can control what you do and don't have yourself.
  16. Any host that supports PHP 5.3 should have json_encode/decode. It doesn't require anything special to support it.
  17. You have to use the var keyword to limit the scope. When you use a variable, JS will walk up the scope chain to find it. If it gets up to the global scope before finding it, it will create it there. Using the 'var' keyword will declare the variable at that scope level so JS will find it and not look further. Though not really technically correct, you can think of it as: Variables are global by default, and you use 'var' to make them local.
  18. You have no field in your form named submit. You named it loginsubmit: <input type="submit" value="" class="submit" name="loginsubmit" />
  19. http://www.nipnotes.com/styles/forms.css Lines 15-17: That is why it does not display.
  20. You should write to a file without any PHP code, then prepending the contents would be simply: $logFile = 'log.txt'; $newContents = 'blah blah blah'; $oldContents = file_get_contents($logFile); file_put_contents($logFile, $newContents, $oldContents);
  21. Oracle supports sequences. It's been a long time since I used it, but if these google results are accurate still it'd be something like: first create the sequence CREATE SEQUENCE jobAutoInc INCREMENT BY 1 START WITH 1; Then, whenever you insert: INSERT INTO jobs (jobId, Name, whateverElse) VALUES (jobAutoInc.NEXTVAL, 'blah', 'bleh'); If you need the id for later use in your code, you can first do a SELECT jobAutoInc.NEXTVAL FROM DUAL and grab the results, then use it in your insert and wherever else you need it.
  22. For one, mysql_query doesn't return an object, but your trying to use it's result as an object. Second, your $result variable is only going to contain the data for the last select, all the rest are ignored. Third, you can do everything in a single query rather than using a loop like your doing. Put all the id's in an IN clause in the query.
  23. <?php if(isset($_POST['image_id'])){ foreach ($_POST['image_id'] as $file_id=>$actions){ if (isset($actions['save']){ /// } if (isset($actions['delete'])){ /// } if (isset($actions['rotate'])){ /// } } } Your $_POST['image_id'] is an array where each key is the file id, and the value is an array of actions. You can just loop over it using a standard foreach loop, including a variable for the key. Then you just test which actions are set and do whatever needs done for each action.
  24. Because you can't embed an if condition into a string like that, and you don't echo vars into a string. Move your condition outside and set a variable, then embed that variable in the string. As for your echo, just concatenate the variable. if ($row['customertitle'] != '') { $name = $row['customertitle'].' '.$row['customerlastname']; } else ( $name = $row['customerfirstname']; } $body = " Dear ".$name." <BR> This is a test. ".$_SERVER['SERVER_ADDR']." <BR> ".$accessinformation." ";
  25. Google for a bbcode parser library. It wll parse out sequences like that. Save yourself the trouble of having to try and code it yourself.
×
×
  • 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.