Jump to content

Alex

Staff Alumni
  • Posts

    2,467
  • Joined

  • Last visited

Everything posted by Alex

  1. I think this is what you're looking for: $var = 'variable'; ${'new_' . $var} = 'value'; echo $new_variable; // value
  2. I don't think this is possible. Why would you even want to do it? What added benefit are you seeking?
  3. function stripzeros($num) { if(strpos($num, '.') !== false) { $split = explode('.', $num); if($split[1] == 0) { return $split[1]; } return $split[0] . '.' . rtrim($split[1], '0'); } return $num; }
  4. That's not an error, it's just not what you expected. fopen returns a resource, not the data you're expecting. For that you'll need to use fread. Or instead you can more simply use file_get_contents: $file = 'http://ws.audioscrobbler.com/1.0/user/sandi-g/topartists.txt'; $data = explode(',', file_get_contents($file)); // ...
  5. $total_posts = mysql_query("SELECT COUNT(post_title) as total_posts FROM posts WHERE cat_id = {$row["cat_id"]}", $connection); $row = mysql_fetch_assoc($total_posts); echo $row['total_posts'];
  6. There might be a better solution but you could do something like this: if(strpos($num1, '.') !== false) { $num1 = rtrim($num1, '0'); }
  7. Didn't even notice that. The array indices start at 0, so it should be: rand(0, 1) Or you can just use: $pic[array_rand($pic)];
  8. <?php echo "/img/" . $pic[rand(1,2)]; ?>
  9. From your foreach it looks like this is what you want: $comma_separated = implode(",", $matches[0]); echo $comma_separated;
  10. No you don't. You're closing the one from the else you just posted there. Try fixing the indenting on your code. It's not correct, maybe that's what's confusing you.
  11. You're forgetting an underscore on this line: while ($row = mysql_fetch assoc($extract)) should be: while ($row = mysql_fetch_assoc($extract)) And if that's your full code you're also not closing the bracket opened here: if(!$session) {
  12. You can't do what you're looking for in PHP. You can accomplish this with JavaScript.
  13. The first method you mentioned, also known as the PEAR naming scheme, is a pretty popular. One added advantage it gives you is the ability to do something like this: function __autoload($classname) { $path = str_replace('_', DIRECTORY_SEPARATOR, $classname); require_once("$path.php"); }
  14. No problem. By the way, can you mark the topic as solved by clicking the button on the bottom left.
  15. Try: SELECT * FROM ver_pro WHERE (name LIKE '%$srch2%' OR prCode LIKE '%$srch2%' OR price LIKE '%$srch2%') AND active = '1' AND mID='2' ORDER BY prID
  16. No.. That won't work because there is no way to set a cookie and tell if it was successfully saved on the client's computer in the same request. Use the solution here: http://coderemix.com/php-cookies-enabled-check
  17. If you're just looking for some programming/problem solving related challenges I find Project Euler to be fun sometimes.
  18. Oh, if that's your question you should be asking over at the mod_write board.
  19. Huh? If you already have that rewrite rule in effect then redirect like this: header("Location: wow-armory-profile/" . $profileID); exit;
  20. Well that's because $books['PHP and MYSQL VQP'][4] doesn't exist. Look at your own array: $phpmysql = array (1 => 'Introduction to PHP', 'Programming with PHP', 'Introduction to SQL and MySQL');
  21. You didn't ask a question or tell us what your problem is.
×
×
  • 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.