Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. Right, I know. I was just giving code example to generate a unique string based on your original code. With my code (and Barand's) you'd have to use a loop and update 1 row at a time. But your original code logic shows you generating each character of the random string from the same pool of characters, but your new code (and also Barand's) effectively reduces the character pool for each character. IOW your original code could conceivably give you "11111111111" whereas yours and Barand's would never result in any of the characters being duplicate. If you are fine with that, then you're set - except for the next issue I brought up. The next issue I brought up is in essence your concern that I just quoted : duplicate strings in rows. As it stands now, all of the solutions presented (including all of yours) could conceivably yield duplicate strings in rows. So if each row must be guaranteed to have a unique string, you're going to have to come up with a different method of generating the string, which is where my last post comes in:
  2. If you're willing to change the format/length of the unique string up a bit, I would suggest using UUID(). If you want to keep with the original available chars and string length, etc.. then the solution will basically involve using php to basically put my code in a while loop that doesn't end until count == [number of rows] and then updating each row 1 at a time.
  3. I too am a bit unclear about what you really want vs. code you posted, so this is just a half guess, but perhaps this will work for you: $_SESSION["viks_cart_array"] = array_filter( $_SESSION["viks_cart_array"], function($elem) { return $elem['quantity']; } ); This will give for example: // before Array ( [viks_cart_array] => Array ( [0] => Array ( [quantity] => 1 ) [1] => Array ( [quantity] => 2 ) [2] => Array ( [quantity] => 0 ) [3] => Array ( [quantity] => 3 ) [4] => Array ( [quantity] => 0 ) ) ) // after Array ( [viks_cart_array] => Array ( [0] => Array ( [quantity] => 1 ) [1] => Array ( [quantity] => 2 ) [3] => Array ( [quantity] => 3 ) ) )
  4. Well I figured it was just an example; I was just providing more explanation about what was going on.
  5. okay well, if you don't care about whether or not the random strings can have duplicate characters in them, then what you have now is fine.. but that does bring up another point to consider.. do you care about the possibility that the generated strings between posts could potentially be duplicate? Because the way you have it now, it is possible that row#1 and row#2 could both generate the same random string. My suggestion doesn't solve for that either, btw, but just mentioning it, in case you didn't consider that..
  6. I just want to point out that neither your solution nor Barand's is quite the same as your original code, in that your original allows for duplicate characters to show up, whereas the solutions presented will always have 11 unique (case-sensitive) characters. If you want to stick with how the original works, you can do this: $c='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-_'; $randstr=''; for ($x=0;$x<10;$x++) $randstr.=$c{rand(0,strlen($c)-1)};
  7. To put it in everyday terms.. when you iterate through an array with foreach by default php uses a copy of the keys and values of the array. So if you were for instance to do this: $array = array(1,2,3); foreach($array as $val) { $val++; } print_r($array); All you are doing is incrementing a temporary value within the scope of the loop. It doesn't actually change $array, because $var is just a temp variable that is a copy of the value of the current index. So, print_r will still show $array as (1,2,3). However, if you include the & prefix, it tells php to reference (use) the actual array instead of the temp copy. So if you do this: $array = array(1,2,3); foreach($array as &$val) { $val++; } print_r($array); print_r will now show $array as (2,3,4) On a sidenote, iterating through an array like this is basically the equivalent of using array_map or array_walk
  8. .josh

    Hello world

    Well just a heads up.. we can be douches sometimes too, especially towards people who aren't making an effort. Only difference is we don't hide behind downvotes.
  9. @renative: bragging about one's hacking exploits has nothing to do with Aspbergers. But even if it somehow did (which it doesn't), the point ignace made was to leave that "experience" off the resume.
  10. please do not make multiple threads asking the same thing.
  11. I had a feeling that might happen.. I figured the smarty code might somehow escape it or htmlentities it. Perhaps remove what you just changed and instead, try changing your smarty template code to this: adding |replace:' ':' ' {if $tags} {foreach from=$tags item=tag name=myLoop} <a href="{$link->getPageLink('search', true, NULL, "tag={$tag.name|urlencode}")|escape:'html'}" title="{l s='More about' mod='blocktags'} {$tag.name|escape:html:'UTF-8'}" class="{$tag.class} {if $smarty.foreach.myLoop.last}last_item{elseif $smarty.foreach.myLoop.first}first_item{else}item{/if}">{$tag.name|escape:html:'UTF-8'|replace:' ':' '}</a> {/foreach} {else} {l s='No tags have been specified yet.' mod='blocktags'} {/if} Unfortunately, I don't have much experience with smarty, so it's just a guess based on a quick google search.
  12. well, based on the posted code, perhaps in tag.php, you can change this: foreach ($tags AS &$tag) $tag['class'] = 'tag_level'.(int)(($tag['times'] - $min) * $coef + 1); To this: foreach ($tags AS &$tag) { $tag['class'] = 'tag_level'.(int)(($tag['times'] - $min) * $coef + 1); $tag['name'] = str_replace(' ',' ',$tag['name']); }
  13. Okay, so in your script, how are the tags currently stored? For example, if you already have them in an array, you can do this: // example array of tags $tags = array( 'tag', 'tag', 'another tag' ); $array = array_map( function($v){return str_replace(' ',' ',$v);}, $tags ); Basically the goal is to replace the spaces with .
  14. According to your code, you are exploding at spaces and building new lines based on individual words. So, how are you even determining which words should be "double" words?
  15. what is the column type you are putting this in?
  16. nuh uh, mine is better: function haxx_erm_hash_me ($str) { return strrev($str); }
  17. So you mention arrays, but it sounds like you're really talking about databases and selecting data from it, so I'm going to go ahead and assume you're just using the wrong word. Auto Increment is usually only used for automatically generating a unique id for a new row, commonly known as the "id" which is used as the primary key or index column. While you could maybe use this to sort "oldest" to "newest", normally you would sort by some other column, such as a date/timestamp column. The query for that would look something like this: // sort ascending SELECT * FROM tablename ORDER BY column ASC // sort descending SELECT * FROM tablename ORDER BY column DESC Read up on basic database handling. That tutorial demonstrates basic database interaction, and the example script includes the code principle for allowing users to sort tabulated data on a page. Caution: this is an old tutorial. While the principle remains true, the actual code used is out of date. For example, don't use mysql_xxx syntax, as it's deprecated. So, read the tut, learn the principle, apply it to modern code syntax. The query would then look something like this: // sort ascending, maximum of 15 results returned SELECT * FROM tablename ORDER BY columnname ASC LIMIT 15 LIMIT n tells the database to only return n rows from what was selected. This is what is called pagination. The principle is the result of using an offset with LIMIT [offset],[result limit]. For example, let's say you have 20 rows, and you want to put 5 rows per page, for the first page you'd do this: // sort ascending, maximum of 15 results returned SELECT * FROM tablename ORDER BY columnname ASC LIMIT 0,5 So by default, when you use LIMIT n, you are telling the db to return a maximum of n results. But if you have 2 numbers separated by a comma, the first one specifies an offset, and the 2nd one specifies the limit. So in the example, we have 20 rows total, and we want 5 per page. So for the first page, the offset is 0, because internally, the row list starts at 0, not 1. Then we tell the db to only give us 5 results from how many we select (which we selected all results, since we don't have any conditions to filter the data or anything). For page 2, we'd use LIMIT 1,5. For page 3, we'd use LIMIT 3,5 and so on. The database determines which rows are offset markers by how many results are returned from the query divided by the limit you specify. So if you do a select query that yields 20 results, and you put a limit of 5 on it, well 20 / 5 = 4, so there are 4 offset markers (0-3). So offset 0 tells the database to give you rows 1-5, Offset 1 tells the database to give you rows 6-10, #2 : 11-15 and #3 : 16-20. If there are say, only 18 rows, then the last offset would only have 3 rows. It will not affect how many results are shown per page, except for whatever "remainder" is left over from the result set, on the last page. For example, if you have 20 rows and select all 20, and use pagination to show 5 rows per page, you will have 4 pages with 5 results each. If you delete the 2nd row on page 1 and then refresh the page, what will happen is the query will select 5 rows per page the same as before. So when you refresh, it will still show 5 results on page 1, but what you had as the first row on page #2 will now be bumped up to the last row on page #1, and then on your last page, there will only be 4 rows.
  18. Yes, I get a headers already sent error. Do you sometimes use output buffering in your script (e.g. use ob_start)?
  19. Really? You admit you have no idea what you are doing, and yet you go changing random things not knowing what will happen? And on a production environment..really?? If you don't know what you are doing, the best thing you can do is don't change anything. Especially if your site stores personal information from other people. Hire someone and give them access to take a look at it. Also, don't assume something should be a simple fix. I know practically nothing about cars. It would be very presumptuous of me to tell a mechanic that the funny noise my car is making should be an easy fix, when I admit I don't know crap about cars. Do you know who's qualified to judge whether or not something should be an easy fix? I'll give you a hint: it's not the guy who doesn't know what they are doing. That's a real quick way to make enemies and get raked on work that's needed to be done. Also, expecting my mechanic to walk me through fixing my car over the phone, when I know jack shit about cars, is equally unrealistic. And it's equally unrealistic to expect us to walk you through fixing your site, indirectly via a forum, when you have no idea what you're doing. I'm not trying to be a douche, so I apologize if I'm coming off as one, but you need to be realistic about your situation.
  20. at face value, this looks okay. Where are you setting $_SESSION['comment1']; I assume on a previous page? Are you sure you didn't typo the name and reference a different form field when you set it? Because it's not some truncation of the value you entered in.. it's a completely different value...
  21. The error message tells you what file produced the error. navigate to it in your file manager. But that's not really the point. The point is that in your code, you use filesize(), and it is failing. filesize() usually fails when you attempt to use it on a file that doesn't exist, or is not writeable by php (php does not have permissions to write to the file). The error messages tell you what the path/to/file is that filesize() is attempting to evaluate. So, go into your file manager and check to see if those files exist. If they do, then you need to compare the file permissions with php's file permissions for the file/directory those files are in. For example, if you uploaded those images yourself via ftp, chances are, php does not have permissions to touch them, which would cause filesize() to fail. So, you will need to alter permissions on the files/dir to allow php access to it. You may possibly be able to do this through php, using chmod(). But it kinda depends on what the current file/dir perms are, and how those files got there in the first place. More than likely you will need to alter the permissions within whatever interface your host provides for you, or else via server command-line.
  22. This is most commonly caused by attempting to use filesize() on a file that doesn't exist or is not writeable.
  23. Is your experience in testing/developing, in different environments, e.g working locally with wamp or xampp or something vs. a hosted server, or multiple hosted servers? Because the most common cause is that it depends on what the error reporting levels are set at, either in the php.ini file or in some script itself.
  24. what is the original content of $str and what are you doing with the altered $str afterwards
×
×
  • 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.