Jump to content

Naez

Members
  • Posts

    99
  • Joined

  • Last visited

    Never

Everything posted by Naez

  1. Okay so I've got a couple tables: articles ----------- id - primary cat_id - INT index foreign #links up with categories table author_id - INT index foreign # links up with user table title - varchar(255) body - longtext url - varchar(255) # [b]url-safe-article-title-for-seo-links[/b] ----------- categories ----------- id - primary category - varchar(255) ----------- The only thing is, I want to seperate things off by level too. So for instance: "Advanced" articles will carry say category id's 3,4,5 "Intermediate" will carry 2 "Novice" will carry cat_id 1 with room for expansion of course. Now I know a couple ways to do this... add a new table, or add a parent_id field in categories. But I'm not sure the best way to do this so hralp! And more importantly, how to generate a big-ass query that will do all the following: [b]Novice:[/b] - Novice Category 1 (2 articles) [b]Intermediate[/b] - Intermediate Category 1 (5 articles) - Intermediate Category 2 (2 articles) - Intermediate Category 3 (20 articles) [b]Advanced:[/b] - Advanced Category 1 (2 articles) # I know I'll need some semi-intricate joins and groupings, and a COUNT() I'm not exactly the SQL JOINs master so hopefully I can get some hralp. Also on side note should I use longtext or something else for the body? Thanks!
  2. Okay so I've got a couple tables: articles ----------- id - primary cat_id - INT index foreign #links up with categories table author_id - INT index foreign # links up with user table title - varchar(255) body - longtext url - varchar(255) # [b]url-safe-tutorial-title-for-seo-links[/b] ----------- categories ----------- id - primary category - varchar(255) ----------- The only thing is, I want to seperate things off by level too. So for instance: "Advanced" articles will carry say category id's 3,4,5 "Intermediate" will carry 2 "Novice" will carry cat_id 1 with room for expansion of course. Now I know a couple ways to do this... add a new table, or add a parent_id field in categories. But I'm not sure the best way to do this so hralp! And more importantly, how to generate a big-ass query that will do all the following: [b]Novice:[/b] - Novice Category 1 (2 articles) [b]Intermediate[/b] - Intermediate Category 1 (5 articles) - Intermediate Category 2 (2 articles) - Intermediate Category 3 (20 articles) [b]Advanced:[/b] - Advanced Category 1 (2 articles) # I know I'll need some semi-intricate joins and groupings, and a COUNT() I'm not exactly the SQL JOINs master so hopefully I can get some hralp. Also on side note should I use longtext or something else for the body? Thanks! EDIT - Double post - locked.
  3. I do not believe so. In my opinion you should create your database connection before invoking the function, then send the $db object to the function.
  4. Check out tutorials on DOMdocument
  5. Yep was just about to suggest a cron job.
  6. Just store a timestamp instead.
  7. Unfortunately you are wrong in this regard. When using a die statement in this way you must use suppression as I previously stated. Consider the following: w/o suppression <?php mysql_connect('fakehost','user','pass') or die('ERROR!: ' .mysql_error()); ?> Output: Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'fakehost' (11001) in C:\xampp\htdocs\index.php on line 3 Now with suppression: <?php @mysql_connect('fakehost','user','pass') or die('ERROR!: ' . mysql_error()); ?> Output: ERROR!: Unknown MySQL server host 'fakehost' (11001) Also, using @ does not "severely" increase execution time, I don't know where you got that idea. However I do agree that errors should be handled differently, but I wouldn't get into that on subject on this board (More people should use the exception class).
  8. Suppresses errors, and if you don't have it you usually won't see the die statement in most PHP installs (the script will still die regardless though).
  9. It defines a constant. Constants can only be scalar types. http://www.php.net/manual/en/language.constants.php
  10. Basically, its preventing you from accessing include pages directly. for instance: main.php <?php @define('IN_MAIN',true); include('test.php'); // code goes here ?> test.php <?php @defined('IN_MAIN') or die('Not in main'); ?> If test.php is accessed directly, defined('IN_MAIN') would return false so the parser would skip to the die statement... much like when you see: mysql_connect('','','') or die(mysql_error());
  11. <?php function textarea ($str) { $open = '<textarea>'; $close = '</textarea>'; // Count the opening tags preg_match_all ('/\[textarea\]/i', $str, $matches); $opentags = count($matches['0']); // Count the close tags preg_match_all ('/\[\/textarea\]/i', $str, $matches); $closetags = count($matches['0']); // reiterate through loop to close all the open tags, there's probably a more elegant way of doing this $unclosed = $opentags - $closetags; for ($i = 0; $i < $unclosed; $i++) { $str .= $close; } // Do replacement $str = str_replace ('[textarea]', $open, $str); $str = str_replace ('[/textarea]', $close, $str); return $str; } ?>
  12. Try: <?php $x = $_GET["suggestion"]; $filename = "data.txt"; $handle = fopen($filename, "ab"); fwrite($handle, $x); $contents = fread($handle, filesize($filename)); echo $contents; fclose($handle); ?> I used "ab" in the handle because I assume you want to "append" the suggestion to the rest of the contents?
  13. I have installed the following extensions: iconv.dll php_domxml.dll libxml2.dll Restart Apache, bada bing, I still get this error Fatal error: Call to undefined function domxml_open_mem() in C:\server\apache\htdocs\***\***.php on line 34 I'm really at a loss here.
  14. Naez

    PDO question

    is there a good way to do this with extending PDO or just go with a custom class to accomplish?
  15. Naez

    PDO question

    PDO is a built-in database abstraction class and it looks by the way things are heading it will be the standard for everything database related soon enough.
  16. Naez

    PDO question

    Had to bump again, post floated down to page 3 :-\ Nobody knows? ???
  17. Was this the kind of attack that these forums were vulnerable to not too long ago?
  18. How can I keep track of how many queries are executed when using PDO? For like a footer of a website (i.e., 7 Queries)
  19. This is bad. You should always use mysql_real_escape_string() (or whatever the escape string for the database you are using is, if you are using PDO to connect and execute then you have no need to worry). Protecting from SQL injection using only addslashes still allows vulnerabilities from your user's input.
  20. $check2 = mysql_query("slect password from user where password=\"$pass\""); line 50 also use mysql_real_escape_string() on your post vars so your code isn't vulnerable to SQL injection as it is now.
  21. Barand for some reason the links in your sig don't point anywhere.
  22. I got it working from this tutorial http://www.dougv.com/blog/2006/12/19/showing-or-hiding-html-form-elements-with-javascript/ Also I guess it was just js not ajax. But now it is only displaying the first set of textboxes. I need it to show 2 textboxes for every item #
  23. I'm working on an RMA form for somebody. Basically, you can see it at http://naez.myftp.org/rmaform.php Now what I want it to do, is when Ebay is selected, the Ebay item number will show up and the paypal will show up. As you can see it kind of does that already. Problem is when form is submitted with ebay selected, and there's errors so it doesn't go through, the div's hide again. Also, in firefox if you click on the ebay radio button a bunch of times the layout gets messed up. In IE it just says "Error on page" in the status bar but doesn't ruin the layout. The framework I am using is http://naez.myftp.org/form.js . Can anyone help point me in the right direction of doing this?
  24. You could always just add a little random number/letter gen to it. For instance, consider <?php function keygen($length) { $out = null; $letters='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; for($i=0; $i<$length; $i++) { $out.=$letters{rand(0,61)}; } return $out; } $unique = keygen(5); move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"] . $unique); ?>
×
×
  • 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.