|
duck monster posted:Wrong
|
# ? Feb 2, 2009 05:51 |
|
|
# ? May 16, 2024 18:40 |
|
duck monster posted:Wrong, and remember that Python does a fair bit of type cohercion via magic methods where possible. Python doesn't evaluate 1 + "1" to 2 (it throws a very similar error). PHP does. Does this make one right and the other wrong? No. These are characteristics that define the languages. edit: and for the record, not even your own example is giving the behavior you're looking for. Python is throwing a run-time error. It is not evaulating 1 + null to null. supster fucked around with this message at 05:56 on Feb 2, 2009 |
# ? Feb 2, 2009 05:51 |
|
supster posted:Python is strongly typed. PHP is weakly typed. You're comparing apples to oranges. Mind you I'll add that 1 + "1" = 2 is loving terrible, especially if your expecting the correct answer of 50. (The ordinal position of ASCII "1" is 49). We are reverting back from Pascal to Cobol here folks, thats how regressive it is. Weak typing is the worst thing ever, especially when it lets so many plainly wrong things pass without complaint. But for comparison, check out VB's evaluation of Nulls. VB is a loving awful language thats also weak typed, but it knows about Null and Not a number, at least if my memory serves me right.
|
# ? Feb 2, 2009 06:00 |
|
And when it comes down to it, do the null checks yourself or write a helper function that does all that for you. It's not especially hard to get the behavior you're looking for. The implicit conversions are defined in the documentation for PHP, so it's not like you have to figure this out on your own. Edit: Next you'll be complaining about the lack of unsigned ints in Javascript and PHP. waffle iron fucked around with this message at 06:04 on Feb 2, 2009 |
# ? Feb 2, 2009 06:02 |
|
duck monster posted:Mind you I'll add that 1 + "1" = 2 is loving terrible, especially if your expecting the correct answer of 50. (The ordinal position of ASCII "1" is 49). We are reverting back from Pascal to Cobol here folks, thats how regressive it is.
|
# ? Feb 2, 2009 06:09 |
|
supster posted:Are you loving retarded? If you're here to complain about PHP being weakly typed, this isn't the thread to do it in. There is nothing wrong with weakly typed languages if you use it properly and understand how typing works. Yes, it would be a terrible idea for a php coder to discuss a fault in PHP in the PHP thread. Anyway, it gets more fun.. At the same time is evaluating null as zero in math, code:
duck monster fucked around with this message at 06:30 on Feb 2, 2009 |
# ? Feb 2, 2009 06:25 |
|
duck monster posted:throw an exception when attempting arithmatic in a variable that hasnt even been allocated yet. quote:Notice: Undefined variable: test in test.php on line 2 code:
|
# ? Feb 2, 2009 07:20 |
|
duck monster posted:Yes, it would be a terrible idea for a php coder to discuss a fault in PHP in the PHP thread. The last PHP Sucks thread died about two months ago, please go start up a new one instead of making GBS threads all over this one.
|
# ? Feb 2, 2009 07:36 |
|
Honestly what I find hillarious is that it's not even remotely a fault of the language. You could have picked one of dozens, but you picked something that is exactly how a weakly typed language is supposed to behave. And then when you realized that you resorted to arguing that weakly typed languages are bad in general. Maybe you can hit up the C/C++ thread next.
|
# ? Feb 2, 2009 07:49 |
|
duck monster posted:Mind you I'll add that 1 + "1" = 2 is loving terrible, especially if your expecting the correct answer of 50. (The ordinal position of ASCII "1" is 49). No scripting language ever is going to evaluate a character to its ordinal position implicitly. What the hell man
|
# ? Feb 2, 2009 11:26 |
|
Mercator posted:
I don't know why people cite things that made PHP as popular as it is as the reasons why it sucks. Loose typing, type juggling, monolithic function library, and "magic" behavior probably led to its widespread usage, even if the principles go against everything you were taught in CS. If you want PHP to act like X language just use X language. Internet Headache fucked around with this message at 12:03 on Feb 2, 2009 |
# ? Feb 2, 2009 11:58 |
|
Some of duck monster's objections are ones I can identify with. I've had to diagnose and fix lots of problems in my site that were caused by absent-mindedly using variables that weren't defined in the current scope, which were then treated as zero for numerical calculation purposes. It would have been so much simpler if it had instead stopped working and printed an error message, or at least printed a message. (Yes I know you can get it to print a "notice" but I didn't originally know how to do that.) There are lots of things I hate about PHP, but as I'm just a fiddler and not a real programmer, I tend to assume there are reasons for them that make sense in some context. Mind you, I am glad it has (what seems to me) the sense to interpret "1" as 1 and not 49 in an integer context.
|
# ? Feb 2, 2009 12:24 |
|
Mercator posted:
He's firebombing at this point, don't bother trying to understand his point of view.
|
# ? Feb 2, 2009 15:28 |
|
When I run this query:code:
However when I run this query in my PHP script, I get an error: "Unknown table 'st' in MULTI DELETE" Any ideas what could cause this?
|
# ? Feb 2, 2009 22:56 |
|
I don't know what exactly is causing that, but if I was typing it then it would look likecode:
|
# ? Feb 2, 2009 23:02 |
|
royallthefourth posted:I don't know what exactly is causing that, but if I was typing it then it would look like code:
Edit: code:
Stephen fucked around with this message at 23:36 on Feb 2, 2009 |
# ? Feb 2, 2009 23:32 |
|
royallthefourth posted:I don't know what exactly is causing that, but if I was typing it then it would look like In the infinite genius of how PHP parses things, it's probably totally unaware of the "st" alias until it reaches "spaces.stores AS st", which is why royallthefourth's syntax works instead.
|
# ? Feb 3, 2009 01:34 |
|
Zorilla posted:In the infinite genius of how PHP parses things, it's probably totally unaware of the "st" alias until it reaches "spaces.stores AS st", which is why royallthefourth's syntax works instead. edit: \/\/ Seems to be a repeating occurance in this thread... supster fucked around with this message at 02:41 on Feb 3, 2009 |
# ? Feb 3, 2009 02:24 |
|
Zorilla posted:In the infinite genius of how PHP parses things, it's probably totally unaware of the "st" alias until it reaches "spaces.stores AS st", which is why royallthefourth's syntax works instead. Finding things wrong with PHP is like shooting dead fish in a barrel with a shotgun, but I think you missed the barrel with this one.
|
# ? Feb 3, 2009 02:36 |
|
Yeah, thinking about it again, I should have realized I was waaay off.
|
# ? Feb 3, 2009 04:34 |
|
I've decided it's time to switch from mysql to mysqli. I've got the basics down, but I'm unsure as to how to get results from a prepared query. The tutorials I've found say use mysqli_stmt->bind_result; I personally don't like this, as it (I think) implies a certain order in the select that, while yes, I can enforce it, I don't want to. I might one day add or remove something from a select, and don't want to have to change the order of the variables in the ->bind_result. I want something similar to mysql_fetch_assoc, which doesn't care what order things are in. Also, based on the documentation on the PHP site, I don't see how to get to a Result object through a prepared query, only through a simple one. Maybe I don't need to, but I can see it exists. This problem is likely because the documentation, while pretty good on a per-function basis, is pretty lovely for the overall extension. So let's say I have something like this in my old system: code:
code:
|
# ? Feb 4, 2009 01:40 |
|
Golbez posted:... what now? How do I get an associative array out of this? Or should I care, and just learn to live with the buffered results?
|
# ? Feb 4, 2009 02:36 |
|
gibbed posted:Wow, that's uh, pretty crappy way of returning results. Is PDO an option? Well that's just it, I'm assuming I'm missing a better way of returning results, but the best the PHP documentation will give me is a bland list of functions, rather than answering the simple question, "What methods does one use to get results from a prepared query?" I'd rather avoid PDO, since I don't need the abstraction it offers; this will be once and always on a MySQL database.
|
# ? Feb 4, 2009 02:42 |
|
Golbez posted:Well that's just it, I'm assuming I'm missing a better way of returning results, but the best the PHP documentation will give me is a bland list of functions, rather than answering the simple question, "What methods does one use to get results from a prepared query?" I'd rather avoid PDO, since I don't need the abstraction it offers; this will be once and always on a MySQL database.
|
# ? Feb 4, 2009 02:44 |
|
I don't know of a way to get an associative array with the standard mysqli library. I think you're stuck with mysql_stmt->bind_result() unless you use an abstraction layer like pdo.php:<? $db = new mysqli($host,$user,$password,$database); $query = "SELECT Category, Location FROM Main WHERE ID = ?"; $stmt = $db->prepare($query); $stmt->bind_param('i',$id); $stmt->execute(); $stmt->bind_result($category, $location); while ($stmt->fetch()) { // sets the value of result column 0 to $category, result column 1 to $location printf("%s %s\n", $category, $location); } ?>
|
# ? Feb 4, 2009 02:51 |
|
Then is my distaste for using bind_result unique, or do other people think it's a bit weird? Then again, you need to have the proper order in bind_param, so I guess it's no big reach to force it in bind_result. On a related note, when doing a simple query in mysqli, you get a Result object returned. I don't see that happening with a parameterized query; you're just always working with the Statement object. am I right?
|
# ? Feb 4, 2009 06:56 |
|
Yeah, if you're working with prepared statements you will always work with a statement object.
|
# ? Feb 4, 2009 11:27 |
|
Supervillin posted:Yep, do this to whatever your input variable is before you escape stuff yourself: Great, this looks like exactly what I'm after. Thanks!
|
# ? Feb 4, 2009 13:22 |
|
I have a site that needs a little help with some login codes They've never really worked and I'm at my whit's end now.. I simply need a login/logout code that when users log in they see members only links. When they log out the links need to go away. The codes I'm presently using DO connect to my MySQL database and once logged in you see the links. However the logout is worthless and doesn't DO anything. However on the login page it doesn't tell you you're already logged in. It will just let you do it again. I honestly just need a whole new batch of codes. It's ridiculous. Sessions and cookies are all really foreign to me. I've been searching sites for months and can't find what I'm looking for. The original codes were done by my friend years ago and have been broken for almost that long. Sorry for the wall of code. php:<? $CookieData = unserialize(stripslashes($_COOKIE['phpbb 2mysql_data'])); $myID = $CookieData['userid']; echo "<!-- "; var_dump($_COOKIE); echo " -->"; ?> (id.php blah blah included on the overall header) letting me do... <?php if (is_numeric($myID)){?> Member Linkage? <? }else { ?> Non member linkage! <? } ?> So that's what I'm working with as far as members only links, however, when I log in with my present login codes it doesn't...do this. Logout: <? include "include/session.php"; session_unset(); session_destroy(); ?> <? echo "<center><font face='Verdana' size='2' >Successfully logged out. <br><br> <a href=login.php>Login</a></font></center>"; ?> Login: <form action='loginck.php' method=post> <font face='verdana, arial, helvetica' size='2' align='center'> Login ID <BR> <input type ='text' class='bginput' name='username' > <BR><BR> Password <BR> <input type ='password' class='btn' name='password' > <input type='submit' value='Submit'> </form> newsession: <?php //error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR); $session['userid']=session_id(); $session['username']=$name; //echo $session['username']; ?> session: <?php session_start(); session_register("session"); ?> loginck: <? include "include/session.php"; $dbservertype='mysql'; $servername='xxxx.perfora.net'; // username and password to log onto db server $dbusername='xxxx'; $dbpassword='xxxx'; // name of database $dbname='xxxx'; //////////////////////////////////////// ////// DONOT EDIT BELOW ///////// /////////////////////////////////////// connecttodb($servername,$dbname,$dbusername,$dbpassword); function connecttodb($servername,$dbname,$dbuser,$dbpassword) { global $link; $link=mysql_connect ("$servername","$dbuser","$dbpassword"); if(!$link){die("Could not connect to MySQL");} mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error()); } ////////////////////////////// ?> <? $userid=mysql_real_escape_string($userid); $name=mysql_real_escape_string($name); $password=mysql_real_escape_string($password); if($rec=mysql_fetch_array(mysql_query("SELECT * FROM Signup WHERE username='$username' AND Password = '$password'"))){ if(($rec['username']==$username)&&($rec['Password']==$password)){ include "include/newsession.php"; echo "<p class=data> <center>Welcome back<br></center>"; print "<script>"; print " self.location='index.php';"; // Comment this line if you don't want to redirect print "</script>"; } } else { session_unset(); echo "<font face='Verdana' size='2' color=red>Wrong Login. Use your correct Name and Password and Try <br><center><input type='button' value='Retry' onClick='history.go(-1)'></center>"; } ?> BaconRelaxer fucked around with this message at 07:09 on Feb 8, 2009 |
# ? Feb 7, 2009 17:05 |
|
Darrish posted:Sorry for the wall of code. Use [php] for code blocks. I can't read what you posted as it appears now.
|
# ? Feb 7, 2009 19:59 |
|
I am running an SQL query and feeding the results in an array that will result in lots of repeated data. What PHP function detects repeated data and deletes it from the array?
|
# ? Feb 8, 2009 11:04 |
|
Probably this: http://us2.php.net/array_unique
|
# ? Feb 8, 2009 11:09 |
|
cka posted:Probably this: http://us2.php.net/array_unique God I love PHP, after doing all the dirty work in college with C++ and poo poo, and then working in Assembly, this is hilarious. Thanks a ton!!
|
# ? Feb 8, 2009 11:11 |
|
I'm developing a small browser game, and one of the components of the game is that players can set events to be completed later. Specifically a player could say "I want to build this structure" and then an entry would be added to a table specifying the Time, Type, etc. of the event to be completed later. I already have the functionality for creating and completing an event written, and it works fine. However, at some point I'll need these events to be completed automatically (currently I run the update script manually). I've been investigating different ways that I can get commercial web hosting to accomplish this such as cron jobs, but I'm unsure of how to proceed. Is it possible to set a cron job within PHP? Could I get the event and then have the script set up a cron job to complete it at a later time? It's of course possible to set cron jobs to run, but so far I've only seen it where I can set it manually. I haven't been able to find much research on this topic.
|
# ? Feb 11, 2009 03:47 |
Cloud Dog posted:Is it possible to set a cron job within PHP? Could I get the event and then have the script set up a cron job to complete it at a later time? It's of course possible to set cron jobs to run, but so far I've only seen it where I can set it manually. I haven't been able to find much research on this topic. I would add it to some sort of 'event queue' table and setup a cron job to run a php script every x minutes/seconds or whatever is suitable for your needs, and that script looks at the event queue and sees if there is anything it needs to do.
|
|
# ? Feb 11, 2009 04:09 |
|
fletcher posted:I would add it to some sort of 'event queue' table and setup a cron job to run a php script every x minutes/seconds or whatever is suitable for your needs, and that script looks at the event queue and sees if there is anything it needs to do. That's actually very possible, and it's how I add it set up originally (and could easily go back to). I was concerned that some hosts might not appreciate me running a cron job every 15 seconds (I think that'd be the minimum to achieve decent feedback), but perhaps they don't pay attention to that sort of thing.
|
# ? Feb 11, 2009 04:25 |
Cloud Dog posted:That's actually very possible, and it's how I add it set up originally (and could easily go back to). I was concerned that some hosts might not appreciate me running a cron job every 15 seconds (I think that'd be the minimum to achieve decent feedback), but perhaps they don't pay attention to that sort of thing. Well, not knowing much about your game, I'd say that at the point you start pissing them off with the amount of resources your event script is using you've probably already outgrown shared hosting anyways, and you'll want to move on to a VPS or dedicated server.
|
|
# ? Feb 11, 2009 04:46 |
|
Cloud Dog posted:That's actually very possible, and it's how I add it set up originally (and could easily go back to). I was concerned that some hosts might not appreciate me running a cron job every 15 seconds (I think that'd be the minimum to achieve decent feedback), but perhaps they don't pay attention to that sort of thing. I don't know anything about your game, but I can share a train of thought that I've just run down if you want to avoid crons. Say you want to build a structure with a time delay on it. Rather than saying 'add this structure to the completed structures table at X time' you would add it to the table with an activation_time field or something. Now when you select structures from the table you have to modify your queries to only take into account buildings that are 'built', ie, have an activation_time that is <= NOW(). I don't know if any of this is helpful, but I thought I'd share. Obviously this might not apply, and it could add a level of complexity or inefficiency to your queries depending on how your db is structured.
|
# ? Feb 11, 2009 08:31 |
|
How do I create a matrix in PHP? Just like in matlab you can do [1 2; 3 4]. Is there an equivalent in PHP? Are there matrix functions I can do (perhaps classes I can download somewhere that will let me do matrix functions)?
|
# ? Feb 11, 2009 10:34 |
|
|
# ? May 16, 2024 18:40 |
|
cannibustacap posted:How do I create a matrix in PHP? Just like in matlab you can do [1 2; 3 4]. Is there an equivalent in PHP? array(array(1,2),array(3,4)); does it sort of
|
# ? Feb 11, 2009 11:20 |