Jump to content

xjermx

Members
  • Posts

    35
  • Joined

  • Last visited

    Never

Everything posted by xjermx

  1. I've recently picked up CodeIgniter 2 + Doctrine 2, which is incredibly powerful. I'm learning as I go. I have what someone told me is called a 'join table'. Two tables that only have useful information when linked together. Its a messaging system in my webapp. You send a message to three other users, it writes to two tables. One table contains who its from, the message text, a timestamp and a primary key. The second table contains a primary key, a "to" field, and a msg_id that is meant to join back to the primary key in the other table. If I was just using native sql statements, here's what this would look like: SELECT * FROM mail_links a INNER JOIN mail_msgs b ON a.msg_id = b.id But I'm trying to figure out what the "right" way is to do this in Doctrine2. Is it Associative Mapping? Is it something else?
  2. Here is what I ended up with: private function _registration_validate() { $this->form_validation->set_rules('email', 'E-mail', 'required|valid_email|min_length[8]|trim|callback_email_check'); return $this->form_validation->run(); } public function email_check($str) { $user = $this->doctrine->em->getRepository('ORM\Dynasties2\Users')->findOneBy(array('email' => $str)); if (isset($user)) { $this->form_validation->set_message('email_check', 'This email address is already in use'); return FALSE; } else { return TRUE; } }
  3. I am running Doctrine 2.2.1 and CodeIgniter 2.1.0 I am attempting to do a simple unique validation to make sure that a field does not already exist in the database. I have tried this: $this->form_validation->set_rules('email', 'E-mail', 'required|valid_email|is_unique[users.email]'); which gives me the following output: I have also tried this (cribbed directly from codeigniter's user manual, along with an email_check function): $this->form_validation->set_rules('email', 'E-mail', 'callback_email_check'); Which gives this output: Can anyone tell me the best/correct way to do unique validation in this setup? Can anyone help me make either of the above methods work? Thanks!
  4. As part of my learn-as-I-go game project, I've created a rudimentary map: http://www.dixieandtheninjas.net/dynasties/images/dynasties_map_2.jpg I want to do a couple of things with it, and I'm unsure of whether javascript/jquery can do this or not. 1. I want to be able to shade cells based on some criteria - for instance, make all enemy provinces red, or all allied provinces blue. 2. I want to be able to put an icon on a specific region to indicate the presence of the player. In both cases, I can generate this kind of information from SQL via PHP, but I don't know where to begin with regards to having a map that I can manipulate in this manner. Any pointers? Thanks!
  5. I'm posting in this thread again, as I'm still stuck at a dead end on this problem. I'm not sure if there is simply an error in my code that makes the long-polling not work, or if I'm just trying the wrong solution here. Any suggestions or help is most welcome!
  6. It is an unfinished game that features elements of exploration, but focuses most heavily on combat.
  7. As a "learn while I build it" project, I'm attempting to construct a fairly simple tic-tac-toe game using mysql, php, jquery and ajax. It lives here: http://www.dixieandtheninjas.net/test/tictactoe (don't be surprised that you can't even play tic tac toe yet, I'm learning) My question is related specifically to doing long polling with ajax. I've "borrowed" from this thread: http://stackoverflow.com/questions/333664/simple-long-polling-example-code But I have to get it to work correctly. It seems to just timeout without successfully completing. I'm also curious how I can get it to .hide() a user's span when they logout (via window.unload). [edit: or do I need to hide them? will the ajax, when working correctly, only load people who are logged in, hence when someone logs out, they will simply no longer get displayed.. or will their span have to be specifically removed?] You can check out my jquery at http://www.dixieandtheninjas.net/test/tictactoe/tictactoe.js some of my PHP: if (isset ($_POST['myname'])) { $name = strtolower(mysql_real_escape_string(filter_input(INPUT_POST, "myname"))); //echo $name; $_SESSION['name'] = $name; //see if its in the db already $result = mysql_query("select * from tictac_names where name='$name'", $db); $rowCheck = mysql_num_rows($result); echo $name; if ($rowCheck > '0') { // name is already in the db //log them in mysql_query("UPDATE tictac_names SET logged_on = '1' WHERE name ='$name'") or die(mysql_error()); } else if ($rowCheck < '1') { // register them $sql = <<< END INSERT INTO tictac_names (name, logged_on, in_game) VALUES ('$name', 1, 0) END; $result2 = mysql_query($sql) or die(mysql_error()); // then log them in } } if (isset ($_POST['logout'])) { if (filter_input(INPUT_POST,'logout') == '1') { $name = $_SESSION['name']; mysql_query("UPDATE tictac_names SET logged_on = '0' WHERE name ='$name'") or die(mysql_error()); echo "blarg"; } } if (isset ($_POST['longpoll'])) { if (filter_input(INPUT_POST,'longpoll') == '1') { $result = mysql_query("select name from tictac_names where logged_on='1'", $db); $rowCheck = mysql_num_rows($result); if ($rowCheck > '0') { while ($row = mysql_fetch_assoc($result)){ foreach ($row as $val){ $spanid = 'sp_' . $val; echo "<br><span id=\"$spanid\">$val</span></br>"; } } } // end rowcheck } } Can anyone help me fix my polling? Can anyone give me some pointers on how I make it smart enough to both add names when they login, and remove names when they logout?
  8. Thanks for the note about XSS attacks. I patched that, I'll probably do the same in other places where people can enter text. As to the swear words, I've got a 'deniednames' table, that filters both registration names and character names. Its nowhere near exhaustive, however, and I've looked into doing preg checking or something, but that seems to create as many issues as it fixes. Likely, I'll just plan to keep an eye out for crummy names and delete them as needed. As for the browser part, you're right of course. If I was doing this professionally, I would also be taking pains to ensure that the java coding that I'm throwing in would not completely break the site for people without java enabled, but I'm of half a mind to be an ogre about it, and instead insist on people using modern browsers. Thanks again for everyone's feedback.
  9. That was it! Thanks very much for the help. I had not idea that it would behave in that fashion.
  10. code from hunter_test.php if (isset($_GET['myshield'])) { $playershield = $_GET['myshield']; switch ($playershield) { case 1: //no shield $armorval = '16'; $text = "no shield"; //$myarmorIDarray[] = $armorval; break; case 2: //Buckler shield $armorval = '12'; $text = "buckler shield"; //$myarmorIDarray[] = $armorval; // armorID 12 break; case 3: $armorval = '13'; $text = "medium round shield"; //$myarmorIDarray[] = $armorval; //Medium round shield // armorID 13 break; case 4: //Large "kite" shield $armorval = '15'; $text = "large \"kite\" shield"; //$myarmorIDarray[] = $armorval; // armorID 15 break; } //$_SESSION['myarmorIDarray'] = $myarmorIDarray; echo $text; //echo "My shield choice is $playershield! and here's an array." . print_r($myarmorIDarray); } Code from hunter_test3.php if (isset($_GET['myshield'])) { $playershield = $_GET['myshield']; switch ($playershield) { case 1: //no shield $armorval = '16'; $text = "no shield"; //$myarmorIDarray[] = $armorval; break; case 2: //Buckler shield $armorval = '12'; $text = "buckler shield"; //$myarmorIDarray[] = $armorval; // armorID 12 break; case 3: $armorval = '13'; $text = "medium round shield"; //$myarmorIDarray[] = $armorval; //Medium round shield // armorID 13 break; case 4: //Large "kite" shield $armorval = '15'; $text = "large \"kite\" shield"; //$myarmorIDarray[] = $armorval; // armorID 15 break; } //$_SESSION['myarmorIDarray'] = $myarmorIDarray; echo $text; //echo "My shield choice is $playershield! and here's an array." . print_r($myarmorIDarray); } Code from new_fight1.php if (isset($_GET['myshield'])) { $playershield = $_GET['myshield']; if (isset($_SESSION['myarmorIDarray'])) { $myarmorIDarray = $_SESSION['myarmorIDarray']; } switch ($playershield) { case 1: //no shield $armorval = '16'; $text = "no shield"; $myarmorIDarray[] = $armorval; break; case 2: //Buckler shield $armorval = '12'; $text = "buckler shield"; $myarmorIDarray[] = $armorval; // armorID 12 break; case 3: $armorval = '13'; $text = "medium round shield"; $myarmorIDarray[] = $armorval; //Medium round shield // armorID 13 break; case 4: //Large "kite" shield $armorval = '15'; $text = "large \"kite\" shield"; $myarmorIDarray[] = $armorval; // armorID 15 break; } $_SESSION['myarmorIDarray'] = $myarmorIDarray; echo $text; //echo "My shield choice is $playershield! and here's an array." . print_r($myarmorIDarray); } If you see something I'm missing, please share. Otherwise, that's why I'm confused - the php isn't doing anything different in the three different test cases.
  11. Yes, I'm aware the buttons seem out of whack. Their sole purpose is to display the weird behavior for this thread, so I was not focused on better organization. Any thoughts about why I have those line breaks?
  12. Here is the exact code from the page that *does not* produce an extra CR/LF if (isset($_GET['myshield'])) { $playershield = $_GET['myshield']; if (isset($_SESSION['myarmorIDarray'])) { $myarmorIDarray = $_SESSION['myarmorIDarray']; } switch ($playershield) { case 1: //no shield $armorval = '16'; $text = "no shield"; $myarmorIDarray[] = $armorval; break; case 2: //Buckler shield $armorval = '12'; $text = "buckler shield"; $myarmorIDarray[] = $armorval; // armorID 12 break; case 3: $armorval = '13'; $text = "medium round shield"; $myarmorIDarray[] = $armorval; //Medium round shield // armorID 13 break; case 4: //Large "kite" shield $armorval = '15'; $text = "large \"kite\" shield"; $myarmorIDarray[] = $armorval; // armorID 15 break; } $_SESSION['myarmorIDarray'] = $myarmorIDarray; echo $text; //echo "My shield choice is $playershield! and here's an array." . print_r($myarmorIDarray); } So... you didn't get alert popups? How strange.
  13. I'm still very new to javascript and ajax, and have read some, and then done some hands on learning. I'm running into a problem where I'm sending data via GET to PHP, and then returning a value. In the process of hacking it apart, I ran into a problem that *sometimes* the request.responseText seems to have an extra carriage feed (or line return) in it. You can see it in action here: http://www.dixieandtheninjas.net/hunter/dev/hunter_test2.php if you click on button 1, it behaves just fine. You'll get an alert window that clearly shows that the return text has no extra CR/LF. If you click button 2, it runs the SAME CODE, from a different PHP page, and instead returns a result that has a CR/LF in it. The same is true for button 3. My PHP code is NOT inserting a line, as far as I can tell. You can mimic the GET by trying: http://www.dixieandtheninjas.net/hunter/dev/hunter_test3.php?myshield=2 Here is an example of the PHP code involved: if (isset($_GET['myshield'])) { $playershield = $_GET['myshield']; switch ($playershield) { case 1: //no shield $armorval = '16'; $text = "no shield"; break; case 2: //Buckler shield $armorval = '12'; $text = "buckler shield"; //$myarmorIDarray[] = $armorval; // armorID 12 break; case 3: $armorval = '13'; $text = "medium round shield"; break; case 4: $armorval = '15'; $text = "large \"kite\" shield"; break; } //$_SESSION['myarmorIDarray'] = $myarmorIDarray; echo $text; } Here is some of the ajax code involved function commitshieldJS4() { var varShieldValue = document.getElementById("myshield").value; var url = "hunter_test3.php?myshield=" + escape(varShieldValue); request.open("GET", url, true); request.onreadystatechange = updateshieldJS; request.send(null); } function updateshieldJS() { if (request.readyState == 4) { if (request.status == 200) { var varReturned = request.responseText; alert ("the response recieved is: >>" + request.responseText + "<<"); } else alert ("Error! Request status is " + request.status); } } I'm totally scratching my head here. I haven't the slightest idea why those extra CR/LFs are there. Any ideas?
  14. actually, the links in the left banner DO work now.
  15. Hi folks. I started learning PHP about a year ago, and my "teach myself PHP project" eventually turned into something that vaguely resembles a game. link: http://www.dixieandtheninjas.net/hunter/ proof of ownership: http://www.dixieandtheninjas.net/hunter/phpfreaks.txt There is so much yet to do with it, but I'm interested in tracking down bugs, vulnerabilities, etc. The links on the left hand banner don't work, so ignore those for the time being. The rest is fair game. Thanks for any feedback!
  16. I'm attempting to thoroughly sanitize my PHP app to avoid common exploits, and am working on guarding from SQL injections and such. I'm using mysql_real_escape_string for data that comes from the user. I have a number of instances of the following: $ip = $_SERVER['REMOTE_ADDR']; $page = $_SERVER['PHP_SELF']; And then using those values to query or update SQL. Is it a best practice to also sanitize this sort of data?
  17. warning: I'm a self taught advanced newbie. I'm working on a multipage PHP app that has need to pass values between pages, usually very small text strings or small integers. I've designed it primarily using _SESSION variables to pass these bits of data. Some of them are written to SQL, but most of them are temporary in nature. Is using _SESSION variables in this capacity considered reasonable? Is there something else or a different way to go about this? (Page A writes a value into $_SESSION['myvalue'], and then page B grabs that data and does something with it.)
  18. Bump. I'm still looking for some help on hex map stuff. I've created an API that does some procedural generation of 'provinces'(hexes). I've also hacked away at some code I found on the internet that generates hex maps. But I'm still trying to find somewhere in the middle to meet. This is pointed toward creating a game of sorts, based on old Atlantis PBEM gaming. Anyone interested in throwing a bone?
  19. Hi folks, I've asked a few questions on the boards here, and gotten a few answers, and figured I'd throw my hat in here as well. I'm a hardware/networking IT guy who once knew some C/C++, and recently decided to learn some PHP - in part because I hope to open up some new career avenues, and in part because I hope to put together a php based browser game, based loosely on the old Atlantis PBEM game engine. I've made some headway and have managed to code myself a from-scratch 'email' style messaging service, along with authentication and all kinds of fun stuff. The part that's really throwing me for a loop though, and is a hurdle to much continued development on Project X is creation of a hex based map. I've had some luck generating hexes procedurally, and I've had a little luck hacking at hex-map code from the internet, but I have yet to find/create a workable solution. So Hi, and Anyone interested?
  20. I'm learning PHP as I build an application based on a game I used to play. I will need a hex style map, complete with forests and mountains and rivers and all of that fun stuff. I'm looking for suggestions for how YOU would recommend going about this. I'm talking in terms of table structure, and generation of the map. I started to generate it all myself, with a regions table and a region_types table. A PKey for the region, along with an x_coord, a y_coord, and a terrainbit, to correspond with the terrain types in the terrain_type table. Each region would have six possible exits, which would be determined by running a bit of math against the region table to determine which regions were adjacent. But that sounds like a lot of work, doing it all by hand. A friend recommended coding an API to build the map, and going form hex to hex, "moving" through them, generating their neighbor hexes as I go. I'm hoping for general strategies here, or "This is the way I would do it". Thanks!
  21. xjermx

    3 way join

    Solved. SELECT mailtext.messagetext, FROMUSER.name AS sent_to, TOUSER.name as sent_from, mailto.touser, mailtext.timestamp, mailtext.from_user FROM mailtext, mailto, users FROMUSER, users TOUSER WHERE mailto.whichmessage = mailtext.msg_ID and FROMUSER.users_id = mailtext.fromuser and TOUSER.users_id = mailto.touser
  22. xjermx

    3 way join

    This seems to do the trick in part: SELECT mailmessage.text, users.name, mailmessage.timestamp, destination.touser, mailmessage.from_user FROM (destination INNER JOIN mailmessage ON destination.whichmessage = mailmessage.ID_mailmessage) INNER JOIN users ON destination.touser = users.ID_users It displays the text field, a name field (corresponding to the touser field), a timestamp, touser, and from_user. It does not display the name corresponding with from_user, and I suspect that this is tricky because both TOUSER and FROM_USER use the same info, users.ID_users Do I need to use a temporary table to fix this?
  23. xjermx

    3 way join

    I have a join currently between my two mail tables. SELECT mailmessage.text, mailmessage.from_user, mailmessage.timestamp, destination.touser FROM destination INNER JOIN mailmessage ON destination.whichmessage=mailmessage.ID_mailtext ORDER BY mailmessage.timestamp this does return good results, but instead of giving me user names, it gives me user ID numbers. I assume that this can be remedied by throwing the users table into the mix.
  24. xjermx

    3 way join

    I have a "users" table with data like userID, name, email, etc. A "Mailmessage" table with the fields 'ID' (PK, auto), "messagetext", "from_user" (FK, relates back to the userID field in 'users'), "timestamp". And a third table, "Destination", which has "whichmessage" (FK, relates back to the ID field in Mailmessage), "touser" (another FK, relates again to the userID field in users). I'm a newbie, and I think I'm looking at a three way join here, so be gentle, please I'm using dreamhost for my environment, which I believe uses mysql 5.1 or 5.2, I'd have to check. My question is simply: can someone tell me how they'd format the SQL query to do a join on these tables? I'm getting lost in reams of info on inner joins and left joins and such. If it helps, the information that I'm eventually wanting to display back to the program is (pardon my shorthand): Username From, Username To, Timestamp, Message Text.
×
×
  • 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.