Jump to content

roopurt18

Staff Alumni
  • Posts

    3,746
  • Joined

  • Last visited

    Never

Everything posted by roopurt18

  1. I don't understand how ON game.seas = season.id is working correctly. season needs to be defined as a table before you use it like that and I can't see where you're doing that.
  2. <?php require_once "HTML/Template/IT.php"; require 'db.inc'; if (!($connection = @ mysql_connect($hostname, $username, $password))) die("Cannot connect"); if (!(mysql_select_db($databaseName, $connection))) showerror(); if (!$regionresult = @ mysql_query ("SELECT * FROM region LIMIT 10", $connection)) showerror(); $template = NEW HTML_TEMPLATE_IT("./templates"); $template->loadTemplatefile("example.7-4.tpl",true, true); while ($regionrow = mysql_fetch_array($regionresult)); { $template->setCurrentBlock("REGION"); $template->setVariable("REGIONNAME", $regionrow["region_name"]); // // I'M GUESSING THIS IS WHERE YOU'RE ERROR IS AT. // IT'S HELPFUL TO ECHO THE SQL STATEMENT AND LOOK FOR PROBLEMS. // // I'VE ALSO REFACTORED YOUR CODE, AS IT'S READABILITY WAS POOR IMO. $sql = " SELECT * FROM winery WHERE region_id = {$regionrow[$region_id]} "; echo $sql; // CHECK THE OUTPUT, DOES IT LOOK RIGHT? $wineryresult = @mysql_query ( $sql, $connection); if( !$wineryresult ) { showerror(); }else{ while ($wineryrow = mysql_fetch_array($wineryresult)) { $template->setCurrentBlock("WINERY"); $template->setVariable("WINERYNAME", $wineryrow["winery_name"]); $tempalte->parseCurrentBlock(); } $template->setCurrentBlock("REGION"); $template->parseCurrentBlock(); } } $template->show(); ?>
  3. Yes, it's a 301 redirect. What I meant was I'm not sure of this part of my syntax, as in I wasn't sure I was providing the redirect code properly: [QSA,R=301,L] It should be Ok like that though.
  4. It depends on the OS. I would be inclined to argue against naming directories after your users' e-mail addresses for security reasons. I have no idea what you plan to store in them, but let's say I'm an attacker and I gain access to your file system. Here I am on your file system: > ls public_html user_data Oh look! A user_data directory; I wonder what's in there. > cd user_data > ls joeboo@domain.com fred@domain.com larry@domain.com Cool! I've just farmed some valid e-mail addresses. Let's see what else I can find. > ls joeboo@domain.com recent.orders secret.question friends > cat recent.orders order id: 10392 date: 2009-11-20 time: 11:00:00 products: 10x widget, 20x bar, 5x foo payment: visa Well, now I know that joeboo@domain.com has made an order recently with his Visa card. I'm going to send joeboo@domain.com an e-mail and tell him something happened to his order, we're very sorry, but he'll need to provide us with his credit card information again to complete the order. You should not put any information on the file system that could be used to compromise your users or their data. You never know when someone is going to archive your home directory and walk away with it. Likewise if someone steals one of your backups. I'd suggest naming the directories after the user's ID column in the database.
  5. Mmmmmm. Thanks for pointing that out Daniel0.
  6. I don't understand why renaming one folder would require 3000 redirects. RewriteEngine on RewriteRule /oldpath(.*) /newpath$1 [QSA,R=301,L] #Not sure if that syntax is proper for R=301
  7. C# gives you the best of both worlds. From the standpoint of client-code, your objects appear to have public properties that you can just assign or retrieve from. However, they are implemented as getter and setter methods so you can perform any type of manipulation or validation that is necessary. I'd like very much to see this feature in PHP.
  8. From K12 through college, I've had several courses taught by more than one teacher or professor. I make no assumptions about how they divided up the grading amongst themselves.
  9. I'm not sure why you're errors aren't reporting properly, but a blank page is usually indicative of parse errors. A parse error is when you make a mistake with the PHP syntax, such as adding extra brackets or forgetting semicolons. I was able to find the syntax errors in your source files by running PHP with the -l flag from the command line. If you open a command prompt, you can run PHP directly from the command line. roopurt18> php -v PHP 5.2.11 (cli) (built: Sep 16 2009 19:39:46) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies with DBG v3.8.6, (C) 2000,2009, by Dmitri Dmitrienko with NuSphere PhpExpress v2.0.3, Copyright (c) 2002-2009 NuSphere Corp, by D mitri Dmitrienko If you use the -l flag, PHP will check your file for syntax errors. roopurt18> cd \path\to\my\files roopurt18@\path\to\my\files> php -l junk.php Parse error: syntax error, unexpected ')' in junk.php on line 12 Errors parsing junk.php By doing this, I found the following in your code: // line 12 has an extra close-paren if (!$regionresult = @ mysql_query ("SELECT * FROM region LIMIT 10", $connection))) // <-- RIGHT HERE, REMOVE ONE OF THE ) // line 21 has an extra ] $template->setVariable("REGIONNAME", $regionrow["region_name"]]); // <-- remove the extra ] in "region_name"]]
  10. Code readability is very important, especially when you revisit your code 6 months later and forgot what it's doing. I find writing my queries out like this to be most readable (just a suggestion, do what works for you): <?php $gamestats = " SELECT g.`id`, d.`Date`, g.`Time`, g.`Opponent`, g.`Weather`, s.`name` FROM `game` g INNER JOIN `seas` s ON g.`seas`=s.`id` WHERE g.`user`='$user' ORDER BY g.`Month` DESC "; ?> rajivgonsalves gave you good advice when he advised that you run the query directly in phpMyAdmin (or another "direct" MySQL interface). As a general guideline, whenever you run into trouble with programming, remove as many of the complexities as possible and go back to the basics. This will help you identify the source of your problem. For example, if you run your query directly in MySQL (using phpMyAdmin) and it doesn't work, then we know the problem is with your query. phpMyAdmin will even be kind enough to print error information. If you run your query in phpMyAdmin and it works, then the problem must be in your PHP code. See how this helps narrow it down? I want you to find a user id for which you query should work. Then replace $user in your query with that id and run it directly in phpMyAdmin. For example, if user id 10 should work, run this query directly in phpMyAdmin without any interference from your PHP code: SELECT g.`id`, d.`Date`, g.`Time`, g.`Opponent`, g.`Weather`, s.`name` FROM `game` g INNER JOIN `seas` s ON g.`seas`=s.`id` WHERE g.`user`='10' ORDER BY g.`Month` DESC (As an aside, you'll notice that when you format your queries in your PHP code as I've suggested, copying and pasting them into external tools becomes much easier!) Now, what does phpMyAdmin tell you?
  11. SELECT * FROM game g, seas s WHERE g.seas = s.id and g.user='$user' ORDER BY g.Month DESC With the way you've written that query, you're leaving yourself open to some potential issues. 1) Don't use SELECT *. Only ask the database for columns you plan to use. 2) FROM game g, seas s, WHERE Don't use that comma-oriented syntax for specifying joins. Explicitly specify the join time and write it out, like so: FROM game g INNER JOIN seas s ON g.seas=s.id 3) WHERE g.seas = s.id ... If you follow the advice in my second point, then you will remove the join logic from the where clause. Avoid putting your join logic in the WHERE clause. 4) g.user='$user' mysql_real_escape_string() will add the appropriate quotes for you. This code might be an indication that you are not escaping your data properly. 5) Use the backticks, Luke! Wrap your database identifiers in the appropriate enclosing characters, which would be backticks in MySQL. For example: SELECT `col1`, `col2` FROM `mytable` a INNER JOIN `myothertable` b on a.`fid`=b.`id` WHERE a.`name`='Larry' (edit) All of the mysql_fetch*() functions work with any type of statement that returns rowsets (as far as I know anyways). So your topic title of "Mysql fetch array on a join" is inappropriate. More appropriate would have been "Need help with join syntax". Since this is a MySQL issue, the "PHP Coding Help" board is also not the best place for it. I mention this because if you can place your questions in the proper boards with more useful descriptions, then you can get better help faster in the future.
  12. Someone said to me once, "Yah, we watched HD pr0n. Some things weren't meant to be HD."
  13. I wouldn't assume one professor / teacher per course.
  14. Some of it is grabbed by the OS and there is some address mapping that occurs between the RAM addresses at the high end and hardware. Although I'm not sure why .8GB seems to be the consistent number that is missing. Windows has very poor memory management anyways.
  15. You can buy it wherever, but you need to reference the technical sheet for that model and make sure you buy compatible memory. If you've never installed / upgraded hardware, then it can be a scary task. One static electric shock in the wrong place and you can ruin your system. If that's a major concern for you, consider having someone experienced install it for you. The first upgrade I ever performed was when I was 16. I upgraded an NEC computer from 16MB of RAM to 48MB and just about shit myself in the process thinking of what my father would do if I fried the $2,000 family computer.
  16. http://www.tomjewett.com/dbdesign/dbdesign.php?page=manymany.php http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html
  17. HTML is text so you store it the same way you store any other text value to the database, such as first names, titles, or descriptions. You just have to decide if a varchar(x) or large-text field type is more appropriate.
  18. Students and classes are a many-to-many relationship; neither belongs to the other and you need to use a third table. students: id, fname, lname, ... classes: id, title, description... classes_to_students: student_id, class_id
  19. Memory is so cheap he could plop in extra memory up to 4GB and his OS will have about 3.2 or 3.5GB available for his programs. Which is plenty of RAM!
  20. There are many potential causes of this behavior. How old is your hardware? It could just be general hardware failure. When was the last time you scanned for viruses spyware? Are your hardware drivers up to date? Is your OS up to date?
  21. He could accomplish returning false or an array of results with one change: return count( $FTopics ) === 0 ? false : $FTopics;
  22. $para = "Sara wants<the>big;cat:to,behave\\while/she's\"gone. What{do}you*want.! I?dunno."; print_r( preg_split( '@[ <>;:,\\\\/"{}*!?]@', $para ) );
  23. Sounds like you may want to use preg_split() instead.
  24. Both are equivalent ways of specifying the columns. FYI, when I first started PHP I used constants for my columns and table names. IMO it's more effort than it's worth and I haven't done that in a loooooooooooong time. I do it like this: $sql = " SELECT id, topic FROM forum_topic WHERE forum_topic.user_id='{$this->userId}' ORDER BY datetime DESC LIMIT 5 "; I typically write my queries in all lower case as well: select id, topic from forum_topic ... And you should properly enclose your table and column names in the delimiter expected by the database engine: select `id`, `topic` from `forum_topic` ...
  25. What's the crontab entry look like? And can you paste the first few lines of the PHP file as well?
×
×
  • 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.