Jump to content

kicken

Gurus
  • Posts

    4,704
  • Joined

  • Last visited

  • Days Won

    179

Everything posted by kicken

  1. If you really must have the formatting then you'll probably need to use a library such as phpexcel. I've never used it so can't be much help there, read the documentation and examples and try and adapt. I never both with formatting for my excel exports, as such I just generate a CSV file and serve that up. Excel does understand html tables so you could try dumping out a simple document with only the data table and formatting and see if it will properly import the formatting with that.
  2. You chmod the parent through your ftp client or an ssh session. Once the parent is 777 drop in a quick script to make and chmod the upload directory: <?php mkdir('uploads'); chmod('uploads', 0755); Browse to the URL for that script so it creates the directory and then remove that script. After the directory is created then use your ftp/ssh to set the parent back to 755
  3. You can do that with jQuery using the .delegate method. Just use whatever css query would match your desired elements. For example: jQuery('#map').delegate('.star', 'mouseover', function(e){ //do whatever here //e.target will be a reference to the specific .star element if you need to extract data from it. }); You want to have it setup so your attributes are quoted with double-quotes, or use the ENT_QUOTES option to htmlentities(). Also you need the json_encode() call to make a proper JS string. $picture = '<div class="planet_float"><img src="images/planets/'.$picture.'.png"></div>'; $map_array .= '<img id="'.$address.'" onmouseover="popup('.htmlentities(json_encode($picture)).')" src="images/star.jpg" style="position:absolute; left:'.$b_x.'px; top:'.$b_y.'px; border-style:solid; border-color: yellow;">'; It'd probably be better/easier in the long run though to use jQuery+ajax rather than mess around with trying to echo stuff out to an on* attribute.
  4. No, the 'T' stands for token. That is why there is things like T_SL (<<), T_SR (>>) T_DOUBLE_ARROW (=>) and a whole lot others. Each individual operator or element of the PHP syntax is broken down into a token which the parser then breaks the source code up into for processing.
  5. Use json_encode and htmlentities together when you want to echo out some variable to an on* parameter. One way to avoid doing a bunch of concatenation is to put all the parameters in an array and then implode that. $onmouseoverParams = array($picture, $detail_name, $stargate_address, $detail_owner, $time_conquered, $time_offset, $detail_siege, $alliance); $onmouseoverParams = array_map('json_encode', $onmouseoverParams); //Fix for JS $map_array = ' <a href="map.php?planet='.$address.'" onmouseover="ajax_popup('.htmlentities(implode(',', $onmouseoverParams)).')"> <img src="images/star.jpg" style="position:absolute; left:'.$b_x.'px; top:'.$b_y.'px; border-style:solid;border-color: yellow;"> </a> ';
  6. If you don't have a condition to apply to a query, then just omit the WHERE clause entirely. $query = "SELECT MAX(`pageId`) AS `pageId` FROM `pages`"; Change your first mysql_query line to also include an or die with the mysql error message so you can see what mysql is complaining about: $query = "SELECT MAX(`pageId`) AS `pageId` FROM `pages`"; $result = mysql_query($query) or die('Error: ' . mysql_error()); while($row = mysql_fetch_assoc($result)) Also selecting the max page id and doing +1 and using for a new id is a poor method, you should use mysql's AUTO_INCREMENT feature instead to let mysql automatically generate the IDs. That way you do not have to worry about possible duplicates from simultaneous requests or re-used IDs from a delete.
  7. Check your phpinfo() output and make sure that allow_url_fopen is enabled. If it is and you still get the error, then you are probably running on a SELinux setup which disables php's ability to open sockets when run under apache. You either need to change the SELinux configuration to allow that or disable SELinux all together. Some google searches should turn up the howto for each of those options.
  8. The main reasons behind initializing variables are basically 1) To prevent notice errors from appearing. 2) To ensure your variable have a known state. For #1, removing the notice errors by setting the variables makes it so that PHP will have to spend less time reporting errors, not fill your logs up with these errors, and make the errors actually useful. A lot of people handle these notices the wrong way, in that they just disable the message by turning down error reporting. Contrary to popular believe this does NOT stop PHP from reporting the error, it merely stops it from echoing the message regarding the error. All the error reporting mechanisms are still triggered and PHP wastes time doing things it doesn't need to be doing. You should also keep your error reporting high so that you do see these notices during development. It will help you greatly when it comes to identify if you made a typo in a variable name such as maybe doing $is_admin when you meant $isAdmin. For #2, this ties into the register_globals setting. If that setting is enabled then your users can set any variables they want by just adding them to the URL. If you did not initialize your variables and did something such as: if ($_POST['username'] == 'blah' && $_POST['password']=='bleh'){ $isAdmin=true; } if ($isAdmin){ //show super-secret world-destrying options. } Then all someone would have to do to gain admin access to your script is append ?isAdmin=1 to the URL. There's no need for them to actually know the username and password because they can just set the variable directly. If your povide an initialization then this no longer works as your initialization will over-write any value the user specifies: $isAdmin = false; if ($_POST['username'] == 'blah' && $_POST['password']=='bleh'){ $isAdmin=true; } if ($isAdmin){ //show super-secret world-destrying options. }
  9. The general rule of thumb is that search engines do not understand Javascript and as such it has no effect on your page when crawled. So as long a you have your href pointing to the desired url instead of doing something stupid like href="javascript:blah();" then they will follow it properly. I believe google (and maybe some others these days) do support some limited javascript now, basically just enough to catch redirects and some of the basic stupidities that some webmasters do (ie, <a href="javascript:void();" onclick="location.href='whatever.html'">). There's a chance google might process your onclick but when it sees that your making an ajax request for a URL it will add that URL into it's crawler queue so you should be ok either way.
  10. The reason your script does not doing anything is because you never call one of those inner functions, all you ever do is define them. That said, PHP doesn't really support nested functions. The script will parse successfully, but if you ever call the outer function (big_func in your case) more than once you'll get a Fatal error about re-defining the functions. There really isn't any pratical use for trying to do a nested function setup, just declare all the functions at the top global level and then use them as needed elsewhere.
  11. No, the time you give using set_time_limit will override any php.ini value that has been set. One thing I will do for parsers and such is come up with an approximate time-per-record to parse and then multiple that by number of records that need processed. If it's not really possible to determine the number of records then just set it to a high value like 999. Note that setting it to 0 will remove any time limit allowing the script to run forever, but you should avoid that in case you end up with an error causing an infinite loop.
  12. You need to run your $_POST['questions'] variable through mysql_real_escape_string as well.
  13. Yea, my sisters and I used to play it a lot too as kids, particularly on road trips. We played #3 quite a bit too when we would go visit my grand parents, wasn't too much else to do over at their place besides play cards heh. Another game we played a lot that could be added to the list I suppose is the Triangle peg jump game. My grandpa had built his own board for it that we played on, was pretty neat. Triangle Peg Board Game
  14. Transplanted from one of my old Dev Shed post when someone asked for ideas: These were for a C++ programming course, but they could all be adapted for the web using PHP or Javasvript without too much issue. #4 is basically like the rpg already on the list.
  15. I assume your talking about the advertisements. This is because the ad companies have their own cookies associated with their banner ads which are all served up from their own domain. Whenever they serve up an ad they can look at the cookie and determine your preferences from that. They will get some idea of what you are looking for because when they have their clients include the code for ads on their pages, there is an ID of some sort to identify the client which is categorized on their end into a bunch of groups (like phpfreaks would be put into a computers, technology, program, probably more groups). So whenever you end up loading one of their ads they can see what type of site your on and associate that with the cookie value you have. Then next time and ad is loaded they take into account the past views based on the cookie id to serve up an ad related to what you've been looking at.
  16. For some reason your site is sending a Content-Encoding: none header in the response, that is what is causing the validator to complain. I have no idea why it would be sending this header, but you need to check into that and find out. Go over your install and see if it is a setting anywhere. Maybe someone more familiar with joomla could be of more assistance.
  17. No, $tsql2 = "SELECT * FROM ( SELECT TOP $itemsPerPage * FROM ( SELECT TOP $maxRecords productID, product_name, product_price FROM products INNER JOIN product_catalogue ON products.catalogueID = product_catalogue.catalogueID WHERE category1 = '1' ORDER BY productID ASC ) tbl ORDER BY productID DESC ) tbl ORDER BY productID ASC"; var_dump($tsql2); //Outputs the query $stmt2 = sqlsrv_query($conn,$tsql2); That is what I meant. var_dump will display the query that is about to be run to your page. Copy and paste that into management studio and run it.
  18. That's what the \b's are for. /\b(time)\b/ does not match 'strtotime' but it will match 'time'. The only issues with a generic replace like this are: 1) It will pick up variables named like functions, eg $time=13992; 2) It will pick up function names inside strings, eg: echo "The current time is:"; You'd need a little more processing to handle things like that. A more advanced regex might do it but my regex-fu is not that strong.
  19. Your best bet would be to obtain a list of function names from php.net probably and then do a replace for each one, of the form: preg_replace("/\b($word)\b/", '<a href="http://www.php.net/$1">$1</a>', $str); The \b's should let you catch the word in most situations properly, and the list of possible names will help make sure your links are accurate.
  20. Echo out your query and run it in management studio to make sure you are getting the correct results back. If it is giving you the right results then change your PHP so it just dumps them out to make sure you are getting them there properly: while($row = sqlsrv_fetch_array($stmt2)){ var_dump($row); } If that comes back ok, show us what kind of output you are getting.
  21. This topic has been moved to Microsoft SQL - MSSQL. http://www.phpfreaks.com/forums/index.php?topic=358946.0
  22. For SQL server you need to do sub-query setup and select the TOP X records sorted in the proper order, then from that result set select the TOP Y records sorted in reverse order, then select them all again sorted in the proper order again. It's a bit of a pain in the ass. For example: SELECT * FROM ( SELECT TOP $itemsPerPage * FROM ( SELECT TOP $maxRecords productID, product_name, product_price FROM products INNER JOIN product_catalogue ON products.catalogueID = product_catalogue.catalogueID WHERE category1 = '1' ORDER BY productID ASC ) tbl ORDER BY productID DESC ) tbl ORDER BY productID ASC Where $maxRecords = $pn*$itemsPerPage
  23. I just use PHP for my template language, I figure anyone can learn the basics of that just as well as they could a custom template language. The only nice thing about a custom template language would be the ability to shorten certain operations that can get a bit tedious when doing templates, especially forms. I do run my templates through a sort of pre-parser to handle a few things, such as re-writing <?= to <?php echo so that it works even if short_open_tag is disabled. I also turn error reporting down to exclude notices and warnings when the template is being run to hide any undefined variable notices or foreach warnings (they are still logged to a file and eventually fixed as time permits). As others have mentioned, I would make the display part of your template/view and put the conditional there. Then just assign some variables to the template you can use to pick the proper value. For example: function getOnlineStatus($lastActivity){ $minutesOnline = (time() - strtotime($lastActivity))/60; if ($minutesOnline < 15){ // Member Online $indicator = 'online'; }else if ($minutesOnline < 30){ // Member Idle $indicator = 'idle'; }else{ // Member Offline $indicator = 'offline'; } return $indicator; } function runTemplate($file, $vars){ include($file); } $user = /* Get the user information from somewhere */; $tplVars = array( 'name' => $user['name'], 'image' => $user['profilePic'], 'onlineStatus' => getOnlineStatus($user['lastActivity']), 'bio' => $user['bio'] ); runTemplate('user_profile.tpl', $tplVars); Then in your user_profile.tpl file: <div id="profileImage"> <img src="<?php echo $vars['image']; ?>"><br> <?php if ($vars['onlineStatus']=='online'): ?><img src="/images/Light_Green_10.png" width="10" alt="Member Online"> <?php elseif ($vars['onlineStatus']=='idle'): ?><img src="/images/Light_Yellow_10.png" width="10" alt="Member Idle"> <?php else: ?><img src="/images/Light_Gray_10.png" width="10" alt="Member Offline"> <?php endif; ?> </div> <h1><?php echo htmlentities($vars['name']); ?></h1> <p><?php echo nl2br(htmlentities($vars['bio'])); ?></p>
  24. Separating logic from presentation (html or whatever) is about separating business rules out from the html. For example you don't want to have your form validation code and database stuff like adding a user or updating records embedded inside your html. You keep that all separate in the file and then call up the appropriate templates/view based on how the business logic runs. There is such a thing as 'display logic' and that usually does go into the templates/html. This is why most template systems have support for basic control structures such as loops and if/else statements, as well as some ways to manipulate variables such as htmlentities or urlencode. You should not need to do anything more complex that that inside your template files. What you have there for a function is an acceptable usage. You could still split it if you wanted to and assign $minutesOnline (or something similar) as a variable in your template and then inside your template have an if statement to choose the appropriate image to use. That would allow you to easily use text instead of an image in a different template or area if you decided you want to do that.
  25. Your final result after running all three replacements is stored in $PlayerName2 but your outputing $PlayerName, which only contains the result of the first replacement. There's no need to use three separate variables, you can just re-use the same one. You can also put your replacements in an array and do it in one call. $replacements = array( '{FIRSTNAME}' => $name[0] , '{LASTTNAME}' => $name[1], '{NICKNAME}' => $p['nickname'] ); $PlayerName = str_replace(array_keys($replacements), array_values($replacements), $Style);
×
×
  • 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.