|
Golbez posted:Hm. Just wondering, is it necessary to run a mysql_num_rows > 0 before doing a while $x = mysql_fetch_assoc? I suppose it might be cleaner, but if zero rows were returned, then the while wouldn't even attempt to run it, right? Correct, but you might want to let the user know that the query returned no rows.
|
# ? Aug 17, 2010 15:12 |
|
|
# ? Jun 6, 2024 14:35 |
|
Doctor rear end in a top hat posted:Correct, but you might want to let the user know that the query returned no rows. Right, and if I were doing anything there that wasn't inside the while() I'd do the mysql_num_rows() check, but otherwise I can skip that part.
|
# ? Aug 17, 2010 15:15 |
|
Golbez posted:KuruMonkey's str_repeat is probably an ever-so-slightly 'purer' solution. But this sounds like a very strange error on sqlsrv_query's part. I'd be surprised if it didn't actually call the same underlying code, really.
|
# ? Aug 17, 2010 15:16 |
|
(Sorry for the rapid fire questions, I'm doing a review/cleanup of my own code :P) Am I a bad person for using double bangs?code:
code:
|
# ? Aug 17, 2010 15:45 |
|
Golbez posted:(Sorry for the rapid fire questions, I'm doing a review/cleanup of my own code :P) Am I a bad person for using double bangs? you just want to get "true" or "false"? Why not just cast to Boolean: return (bool)mysql_num_rows($rQuery);
|
# ? Aug 17, 2010 15:56 |
|
Hammerite posted:you just want to get "true" or "false"? Why not just cast to Boolean: Four extra characters. (also, thanks for showing me the existence of the 'fixed' tag, that is useful)
|
# ? Aug 17, 2010 15:56 |
|
Golbez posted:Four extra characters. But far less likely to give someone else who looks at your code a "WTF" moment.
|
# ? Aug 17, 2010 15:57 |
|
Hammerite posted:But far less likely to give someone else who looks at your code a "WTF" moment. Oh fine. And I asked the other coder here if I was a bad person for doing it and he said yes, so I guess that settles it.
|
# ? Aug 17, 2010 16:02 |
|
KuruMonkey posted:Given that it looked like your code was building some large strings in its tests; have you tried running the tests in isolation, or even just in the opposite order? Good idea - I should have thought to time just the loops and that's what I was talking about when I was asking about validity. I can see if PHP can optimize out a loop with an empty block because I've found those in our code. I've been assuming that the overhead involved in calling an interpreted function (as opposed to an internal C implementation) would make array_map somewhat slower than implode, but the assumption I made about using count inside a loop was wrong so who knows. Edit: I did something stupid and the long-running loops were behaving that way because they were using the length of the generated string as a limit instead of the array length. Dunno how many times I looked at that and said "Yeah, that's right, so what the gently caress" :\ Equality checks didn't see it because $array[$out_of_bounds_index] coerces to an empty string. Gaah. A for loop with the limit pre-computed turns out to be about the same speed as a foreach and they're ~180% slower than good old implode(on 5.2.5 on Windows). Munkeymon fucked around with this message at 23:06 on Aug 17, 2010 |
# ? Aug 17, 2010 16:24 |
|
How can I check if there is anything in STDIN before reading from it? if ( ! feof(STDIN)) always returns TRUE Basically I have a while loop in a script that does fgets(STDIN), but if nothing is there it waits for input before continuing. EDIT after more research I've found out that what I'm after is a "non-blocking read from STDIN". Basically my script is a wrapper for another program. I have a while loop that reads the output from the program. In the while loop I want to get any input from STDIN and send it to the program. My first attempt with fread/fgets halts execution until input is entered which obviously isn't desired. I want the wrapper to run as normal, however if there is any input in STDIN, be able to capture that and send it off to the program. Can anyone point me in the right direction? boak fucked around with this message at 08:29 on Aug 18, 2010 |
# ? Aug 18, 2010 06:09 |
|
Can someone just give me some quick pointers on best practice (maybe even recommend a book as I'd like to learn this stuff properly) with regards to laying out my code? Specifically, I want to know where to put validation/database queries/page generation code. Currently, the page which users are visiting to use my app is getting GET parameters, passing those off to a validation function to be checked, passing them onto a verification function to verify the login, passing some parameters to a query function to get the results of the request and so on... As I'm primarily a Java developer, it makes sense to me to move these things to separate functions, it makes the logic of the page easy to follow as you don't get blinded by the implementation, etc. There's a form on the page, which currently POSTs to the same page so I can validate the form and display error messages, so that's another request type that needs to be handled by the same page and so would become its own function, called dependent on whether a POST parameter was set. Anyway, was just wondering if anyone had any tips on best practice for keeping this stuff tidy. I'm packing all my session data (IP Addresses, GET/POST Parameters) into an object to distribute to these functions as that seemed sensible, but I'm not particularly experienced in the PHP way as yet.
|
# ? Aug 18, 2010 10:10 |
|
It typically depends on what your application is, if you're using a framework, are you using OOP etc. For example, I have a website CMS written in CodeIgnitor, so it follows an MVC structure as well as some other minor CI-specific organisational stuff. Choosing how to best layout and break up your code is like choosing the best web host - each has its own pros and cons that you need to weigh up. There isn't one hard and fast "best practice" and it is difficult to get good advice from someone who doesn't know your code as well as you. Best thing to do would be look at a couple of different methods and choose one that suits.
|
# ? Aug 18, 2010 10:28 |
|
The Zend Framework is obnoxious with its lack of good documentation! I am trying to figure out how to autoload my models directory and it just isn't working out for me. Does anyone have any good resources for this or any idea what to do? I have the standard setup of controllers and view/scripts and layout/scripts directories. For some reason even require_once '../models/MyModel.php' isn't working; Edit: require once is working, I just had to prepend dirname(__FILE__) to everything. Isn't this what AutoLoading is built for? sonic bed head fucked around with this message at 03:33 on Aug 19, 2010 |
# ? Aug 19, 2010 03:30 |
|
It's time for another pointless image manipulation question! I'm doing what Alex007 helpfully pointed out and using the output buffer and imagejpeg to save an image in a variable. So I do this...code:
So, I'm completely confused. Why is Firefox wrong? Is strlen not working right in this case? I've checked, I don't appear to have the mbstring overloading enabled. Is the size difference between strlen() and actual simply the difference in headers? Edit: And I just had imagejpeg write the image to the filesystem instead and filesize() returns what strlen() returns, 642904 bytes. So that appears to be the 'real' size of the image, so why is it 200 bytes larger when downloaded (that's the actual size, not the 'size on disk') and why is Firefox's size so far off? Corollary: Is there any point to using imagejpeg() to display an image in cases where I can simply echo the already-stored image data? Golbez fucked around with this message at 15:51 on Aug 19, 2010 |
# ? Aug 19, 2010 15:18 |
|
sonic bed head posted:The Zend Framework is obnoxious with its lack of good documentation! I am trying to figure out how to autoload my models directory and it just isn't working out for me. Does anyone have any good resources for this or any idea what to do? I have the standard setup of controllers and view/scripts and layout/scripts directories. For some reason even require_once '../models/MyModel.php' isn't working; Compared to most frameworks, the Zend Framework actually has very good documentation. Have you added your namespace to the autoloader? http://framework.zend.com/manual/en/zend.loader.html I believe your stuff should be in the following structure where library is the same folder where you have Zend (this is from memory from the last time I used Zend) /library/My/Model/User.php In this case your project is called My, that is your namespace, then you have a Model folder and then a user model. The actual class should be called My_Model_User. You can have a different structure than this if you modify the autoloader, or decide to use your own autoloader. Zend framework has, by design, very few interdependencies. You should be able to use your own autoloader, or extend Zend_Loader with few issues, and the rest of the Zend Framework should work just fine.
|
# ? Aug 19, 2010 16:06 |
|
Golbez posted:(...) so why is it 200 bytes larger when downloaded (that's the actual size, not the 'size on disk') and why is Firefox's size so far off? How do you re-output your image from the DB ? If you ImageCreateFromString() -> ImageJpeg() then there's a big chance PHP is reencoding your image, changing image quality or other setting like that. If you just output the string, there shouldn't be any difference. I'd go with this (echo the DB field) personally. In FF, I'd Right-Click > Save As the image and save it to disk, then do a binary compare with the original file (or blob) to see where the difference is. My guess is that the image got recoded, or stuff (blanks?) gets appended to the image because you script outputs it after the image.
|
# ? Aug 19, 2010 16:55 |
|
Alex007 posted:How do you re-output your image from the DB ? If you ImageCreateFromString() -> ImageJpeg() then there's a big chance PHP is reencoding your image, changing image quality or other setting like that. If you just output the string, there shouldn't be any difference. I'd go with this (echo the DB field) personally. Heh. Yep, when I just do an echo straight from the database rather than using imagejpeg, the disparity disappears. Nothing being output after the image, there's a die() right after it, so I'm not sure where FF's earlier inflation came from, but at least now everything's all right. Thanks!
|
# ? Aug 19, 2010 17:04 |
|
I'm currently setting up a very basic reporting/tracking system for my job and have everything ALMOST complete. It's pretty simple input into a DB and a display page where values are shown. We basically are just pulling numbers, but there is a need for a News section. I set up a new DB table for the news with the columns: ID, Time, Date, Subject, FullText. On the display page I am showing a table of all the News from the current day with Time and Subject. I would like to be able to set it up so the user can either click on the table cell or the Subject text and open a pop-up with the full text. I can't figure out the right way to do this though. Any suggestions? I'm using PHP5 and mySQL.
|
# ? Aug 19, 2010 21:18 |
excidium posted:I'm currently setting up a very basic reporting/tracking system for my job and have everything ALMOST complete. It's pretty simple input into a DB and a display page where values are shown. We basically are just pulling numbers, but there is a need for a News section. I set up a new DB table for the news with the columns: ID, Time, Date, Subject, FullText. Quick and dirty: hide the FullText for each entry in a <input type="hidden"/> that lives inside the cell they are clicking on. Use jQuery to display it when they click on the subject: code:
|
|
# ? Aug 19, 2010 21:54 |
|
Well without adding jQuery I just stopped being a retard and made my links dynamic with the $_GET functionality. So my code now looks like this: code:
|
# ? Aug 20, 2010 01:19 |
|
Seeing that makes me itch. I use alternative syntax for control structures when I can, just feels cleaner, less html polluting your code (or code polluting your html, depending on how you look at it).php:<? <table id="news"> <thead> <th colspan="2">NEWS: <?php echo date("l, F dS, Y"); ?></th> </thead> <tbody> <?php while($newsRow = mysql_fetch_array($newsResult)): ?> <tr> <td><?php echo $newsRow['Time'] ?></td> <td><?php echo "<a href=\"news.php?id=".$newsRow['ID']."\">".$newsRow['Subject']."</a>" ?></td> </tr> <?php endwhile; ?> </tbody> </table> ?>
|
# ? Aug 20, 2010 01:51 |
Don't be afraid of jQuery! You can do some really cool stuff with very little effort.
|
|
# ? Aug 20, 2010 01:52 |
|
Have any of you ever written a "custom application" for Invision Board? I'm trying my hand at it but the documentation isn't as full as I'd hoped.
|
# ? Aug 20, 2010 02:14 |
|
epswing posted:Seeing that makes me itch. I use alternative syntax for control structures when I can, just feels cleaner, less html polluting your code (or code polluting your html, depending on how you look at it). Thanks for the tip. My code is definitely not pretty, but it's functioning for now!
|
# ? Aug 20, 2010 03:36 |
|
OK this is most likely another retarded question but I can't seem to find what I'm looking for. I'm adding records to my DB with a time stamp using the NOW() function. This inserts the time as h:m:s using the 24 hour military time. That's fine, but when I query and want to display the time back, I want to show it in h:m am/pm. Is there a function to do this, or do I just need to set up logic to sub-string, subtract and add AM/PM as necessary?
|
# ? Aug 20, 2010 14:21 |
|
excidium posted:OK this is most likely another retarded question but I can't seem to find what I'm looking for. (...) MySql, MsSql or PostgreSQL ? What is the field type you are using ?
|
# ? Aug 20, 2010 14:33 |
|
excidium posted:OK this is most likely another retarded question but I can't seem to find what I'm looking for. php:<? date( "g:H a", strtotime( $militaryTime ) ); ?>
|
# ? Aug 20, 2010 14:33 |
|
Great, thanks Lumpy!php:<?php while($newsRow = mysql_fetch_array($newsResult)): ?> <tr> <td><?php echo date("g:i a", strtotime($newsRow['Time'])) ?></td> </tr> <?php endwhile; ?>
|
# ? Aug 20, 2010 14:38 |
|
You could also add a TIME_FORMAT() to the query, if your DBMS has said function.
|
# ? Aug 20, 2010 15:04 |
|
drcru posted:Have any of you ever written a "custom application" for Invision Board? I'm trying my hand at it but the documentation isn't as full as I'd hoped.
|
# ? Aug 20, 2010 21:12 |
|
excidium posted:OK this is most likely another retarded question but I can't seem to find what I'm looking for.
|
# ? Aug 20, 2010 22:37 |
|
Fehler posted:Only for 2.3, and I guess you are using IP.Board 3? Usually their documentation is pretty good though, at least compared to some other stuff I worked with... Yep, IP.Board 3, it seems like quite a bit has changed from version 2 but at least it looks like you don't have to have people edit any files now.
|
# ? Aug 20, 2010 23:21 |
|
could any of you guys recommend a decent IDE for PHP/MySQL projects. I am most familiar with c#/MSSQL and Visual Studio in general. I'm really having trouble debugging my projects, any suggestions? Also, what's worthwhile when it comes to PHP frameworks?
|
# ? Aug 21, 2010 00:30 |
|
I used eclipse with the web-tools-platform for a long time, but became too frustrated with it. I currently use and like netbeans, it does everything I want, including debugging.
|
# ? Aug 21, 2010 00:48 |
|
epswing posted:I used eclipse with the web-tools-platform for a long time, but became too frustrated with it. I currently use and like netbeans, it does everything I want, including debugging. thanks for the tip. I recall using netbeans for a Java/OOP class a few years back, I'll give it another whirl.
|
# ? Aug 21, 2010 01:31 |
|
Begby posted:Compared to most frameworks, the Zend Framework actually has very good documentation. What I don't understand about this is why would I create my own library for this when the framework's own IDE has created a "models" directory as a child of "application"? Is that directory supposed to be empty and am I supposed to put all of my own non-controller code in my own library directory? Thank you so much for your help. You are much clearer than the docs, I think. I'm used to the beautiful code igniter documentation and even those are nothing compared to something like jQuery or ExtJS.
|
# ? Aug 21, 2010 01:41 |
|
I'm creating a site which I want to encrypt some data using AES or some other two way encryption and I don't want the key to be stored anywhere on the server. When a user signs in, I need the user to either provide the key or retrieve the key from somewhere in a way that wouldn't be easily reproducible by a hacker or someone who has access to the source code. Does anyone have a good idea for how to do this? I've been racking my brain for a couple days and have only come up with half assed ideas.
|
# ? Aug 23, 2010 04:16 |
|
Can't you just have the user submit the key over https with a form or cookie or something
|
# ? Aug 23, 2010 04:28 |
|
boak posted:Can't you just have the user submit the key over https with a form or cookie or something I'd prefer the user not actively know they are giving me the encryption key. It would be like using their password as the key, but then if they change their password( something I only keep hashed in the db, so I have no idea what it is ), then all of a sudden they can't decrypt the sensitive data.
|
# ? Aug 23, 2010 04:38 |
|
|
# ? Jun 6, 2024 14:35 |
|
Unless the user remembers the key (meaning the key is probably weak and probably unsuitable for what you want to use it for) it will need to be stored somewhere (cookie, client-side or server-side) or it'll need to be able to be generated easily (something like doing a hash of their user-agent or something), but this would be easily faked. I'm not sure you will be able to get what you're after without some kind of trade off. Without know anything about your application, I would have the user only submit the key when it is needed to decrypt something and discarded once decryption is finished. Not nearly perfect but there are going to be a number of risks no matter which route you decide to take.
|
# ? Aug 23, 2010 04:46 |