|
Those were both good reads and if I were in charge of coding our sites myself, I'd probably lean toward Kohana. The other one seems to be a good choice if writing your own framework seems appealing. I should've been more specific about our needs. Basically what I've come to find is that what we only really need is a robust database abstraction package. As I mentioned, I don't actually build websites, I pass that portion of developing a given site on to our content developers and then hold their hand through any PHP that may need done. In the case that something more complex needs done for a website, or any one-off function that requires heavy programming, I do that. I'd love to migrate to an MVC approach to building sites, but it wouldn't happen as our content guys are not quite that technical. The system we have in place now is essentially a database abstraction layer, and I guess what I'm looking for is something that might be more sophisticated, a little more object oriented, and optimized a little better. None of us should hardly, if ever, need to write a query to fetch, manipulate, or store data. This is why our content developers don't need to be skilled at programming to produce dynamic pages (they come cheap if they're not programmers).
|
# ? Feb 26, 2010 16:07 |
|
|
# ? May 31, 2024 05:11 |
|
So you're like for ORM, right? Try Propel or Doctrine. Have fun shoehorning graphic artists into the role of building a whole website!
|
# ? Feb 26, 2010 16:43 |
greasy digits posted:None of us should hardly, if ever, need to write a query to fetch, manipulate, or store data. This is why our content developers don't need to be skilled at programming to produce dynamic pages (they come cheap if they're not programmers). Sounds like maybe you need a template engine?
|
|
# ? Feb 26, 2010 18:27 |
|
I think php itself is a reasonably good templating engine.
|
# ? Feb 27, 2010 05:16 |
|
epswing posted:I think php itself is a reasonably good templating engine. It can also be a reasonable framework but people love to aimlessly re-invent poo poo that some how ends up inferior to the original. Meh.
|
# ? Feb 27, 2010 05:42 |
|
How do people deal with passing options thru the form considering each product might have a different option? I know you can use session/cookies to store the value but the way I have it now is that everytime someone adds an item to a cart, it'll send the data to a function which handles adding product to cart like this: code:
So I don't know how to go about handling options, any guidance would be appreciated. Something tells me it's something simple I missed but I can't seem to get past the whole.
|
# ? Mar 1, 2010 23:30 |
|
cLin posted:How do people deal with passing options thru the form considering each product might have a different option? The first goal should be to have everything with a unique ID and see if your view can manage the collation of related IDs. If that is not sufficient you might want to consider something simply like a parent-ID reference, each option has a unique ID and you create a tree. php:<? $cart->handle_product(array( 'product-id' => $_POST['prod_id'], 'quantity' => $_POST['quantity'], 'price' => $_POST['price'], 'options' => array( array( 'option-id' => $_POST['opt0_id'], ... ), array( 'option-id' => $_POST['opt1_id'], ... )) ... )); ?>
|
# ? Mar 2, 2010 03:53 |
|
Thanks! It's so much better when I can visual what I need to do.
|
# ? Mar 2, 2010 04:40 |
|
I am working on a website that will be serving a rather large number of downloads. I have been searching for a way to log the downloads of each of the files. At the moment I am using a simple script to check the request to see if its valid, log the download and serve the file. The below code snippet serves the file after the verification and logging functions. php:<? $reqfile = "files/".$file; $contenttype="audio/mpeg"; if($fn=fopen($reqfile, "rba")){ header("Content-Type: ".$contenttype); header("Content-Length: ".filesize($reqfile)); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Pragma: no-cache"); header("Expires: Mon, 26 Jul 1997 06:00:00 GMT"); header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0"); fpassthru($fn); fclose($fn); ?> This is starting to drive me crazy. What would be a more efficient way of logging and serving the file?
|
# ? Mar 2, 2010 11:20 |
|
crazypandaman posted:To me this feels like a very inefficient way of serving the files. Check out x-send-file, on new versions of Apache or Lighttpd. http://john.guen.in/past/2007/4/17/send_files_faster_with_xsendfile/
|
# ? Mar 2, 2010 11:24 |
How can I pass my php array to a javascript function? Right now, I'm just passing $data as an argument and alerting it on the other side...and I'm just getting a 'native code' alert. Do I have to pass it through as a string, or is there a better way? Thank you.
|
|
# ? Mar 3, 2010 00:42 |
growing posted:How can I pass my php array to a javascript function? Pass it as a json formatted string and then parse the JSON in Javascript.
|
|
# ? Mar 3, 2010 00:46 |
|
edit: nevermind. Q: Do you need multiple instances of a connection variable when using nested SQL queries and mysqli A: Yes gwar3k1 fucked around with this message at 22:01 on Mar 3, 2010 |
# ? Mar 3, 2010 21:14 |
|
MrMoo posted:It can also be a reasonable framework but people love to aimlessly re-invent poo poo that some how ends up inferior to the original. Meh. One of the main reasons I like frameworks is good, consistent application organization
|
# ? Mar 3, 2010 22:27 |
|
gwar3k1 posted:edit: nevermind. That doesn't sound right. You can, at least, have more than one result object at a time; there is no need, so far as I know, to have more than one connection resource at a time, assuming you only want to connect to one host. code:
|
# ? Mar 3, 2010 23:10 |
|
Hammerite posted:That doesn't sound right. You can, at least, have more than one result object at a time; there is no need, so far as I know, to have more than one connection resource at a time, assuming you only want to connect to one host. Thanks, I'll give it another try. I had a few other issues to debug so I just assumed that that was one of the causes.
|
# ? Mar 3, 2010 23:26 |
|
I'm doing some coursework for my web module at university and I've just got a quick, simple question. I'm trying to enter values from a form into 2 tables (login & customer) connecting the 2 based on the UserId as the foreign key but I can't seem to pass the UserId from the SELECT statement into a variable so it can be used in the following INSERT query, can someone point out where I've gone wrong?code:
|
# ? Mar 6, 2010 00:18 |
|
After you have called mysql_fetch_assoc, $userid is an associative array, not a string or an integer. It has a single key, 'UserId', and the value associated to that key is the User ID you are trying to use in your subsequent query. To solve this problem you could either 1) wrap the call to mysql_fetch_assoc with a call to extract() 2) change $userid in the final query to $userid['UserId'] Also, 1) you are aware that you have posted your database user's credentials? 2) you might find it handy to look up "last insert id"
|
# ? Mar 6, 2010 01:31 |
|
Hammerite posted:1) wrap the call to mysql_fetch_assoc with a call to extract() $userid = mysql_fetch_assoc($result); to extract(mysql_fetch_assoc($result)); If you do this then $UserId will contain the value you require (not $userid, which is capitalised differently)
|
# ? Mar 6, 2010 01:34 |
|
This may be a question without an answer, or too vague to answer, but we'll see... This is basically a code optimization problem, it's too slow. I have a script that I run that does some rather lengthy logic. The script combines two dynamic variables (say A & B) with some data from a big database that I have of gathered variables basically arranged as such: date | time | station | reading There's 400 stations and 400 readings per day, and 34 days of data so I have roughly 5 million records in this particular mySQL database. With the data I want to be able to retrieve and manipulate it in three different ways: 1) Single Date output, given single values of A & B 2) Sum of daily output for all 30 days, given values of A & B 3) Same as #2, but over all combinations of A & B (each variable can be one of 8 values, so this is 64 combinations or running #2 64 times in a row to print out a 8x8 table). Originally, I was pulling the data out of the giant database and putting into a temporary table, then reading that table every time the function #2 runs. This yielded an execution time of about 6 seconds per #2, or 6x64=380 seconds in total. This is currently too slow. So I thought maybe reading from the temp table was what was causing the script to be slow and instead i just pulled the data from the big database once then loaded it into a php array and carried the array through all 64 iterations. With this method, running #2 takes roughly 2.5 seconds which is acceptable. The problem I am having is when doing #2 64 times in a row for #3, my script it total takes much longer than 2.5x64. In fact, while the first iteration takes about 2.5 seconds, each successive iteration takes .2 seconds longer, by the time I've completed the 64th iteration, it's taking over 9 seconds each time. And finally the total execution time is even longer than before, about 450 seconds. Why is performance degrading like this? Am I 'leaking' somewhere? I've regained some time by unset() and re-populating the array each time #2 runs (so pulling out of the giant database and making the big array 64 times), but each successive run of #2 still takes longer and longer. I realise this might be some inherent problem with this type of thing (diminishing returns or something), but is there anything I can do to prevent this? Sorry if this is a disjointed post, I kinda hack my way through PHP (all personal stuff) and am completely lost on this one. The code is too long to submit, but I can mock up some pseudocode if it will help. mik fucked around with this message at 06:43 on Mar 7, 2010 |
# ? Mar 7, 2010 06:40 |
|
Edit, stupid question.
|
# ? Mar 7, 2010 20:07 |
|
Hammerite posted:By this I mean change Really struggling with this, made the changes that you suggested and it prints out '1' as the ArtistId in the echo statement no matter what artist is entered into the textbox and when it inserts the data a 0 is entered into the table. Below is the code (to a different page) that I made amendments to based on your suggestion, can anyone see what I'm doing wrong still? code:
|
# ? Mar 7, 2010 22:14 |
|
MrMartyn posted:Really struggling with this, made the changes that you suggested and it prints out '1' as the ArtistId in the echo statement no matter what artist is entered into the textbox and when it inserts the data a 0 is entered into the table. Here is the documentation for extract: http://php.net/manual/en/function.extract.php If one of the keys in your array is 'ArtistId' (and it is, based on your query) then after you call extract(), you will have a variable $ArtistId which holds the value you are looking for. So, change code:
code:
|
# ? Mar 7, 2010 22:47 |
|
From the documentation page linked by Jackie:PHP documentation posted:Return Values The code you are using always stores integer 1 in the variable $artistid because the argument you are passing to extract() is an associative array with one key, 'ArtistID'. If you run this code: code:
In the case of your code, you do not care about the value returned by extract() because you know that whatever happens it should return integer 1. You care about the new variable it has created, $ArtistId, which is independent of its return value.
|
# ? Mar 8, 2010 00:37 |
|
mik posted:stuff Well, I can't give you all that much help without seeing some code, but here are some general things you can look at - One possible bottleneck is building up and tearing down SQL connections. Everytime you create a new query and connect, it takes time and a lot of resources. Really bad bad things are to create a query, then loop over the results and do another query for each result, then for each of those results do another query etc. I have seen this done a lot in code I have fixed and it tends to get bad fast. Are you doing anything like that? - Are you using PDO or some other technology? Are you creating a new connection for every query or reusing a connection? You might want to open up a mysql console and look at the connections as your app runs and see what happens. If a million connections open up you have a problem. - Are your tables properly indexed? Have you done ran 'explain' on your queries? 5 million records sounds like a lot, but on a properly setup server its really not a large number of records for MySql to handle - Have you tried getting your complete results in a single query instead of doing all of this in PHP? I am 99% sure there would be some way to get the results for #2 and #3 using a single query and no temp table. You should start out using a MySql client app and create the queries, then when you get the results setup, just use PHP to run the queries. - Post your pseudo code, this will probably be the biggest help - Post some sample data, some sample values for A & B, along with what you want your results to look like for #1, #2, and the calculations that would happen to get those results. Very simplified example code:
- Post your SQL queries you are using.
|
# ? Mar 8, 2010 16:28 |
|
I'm very new at web development, so please bear with me. I have a database of employees. We can call it EMPLOYEES, I guess it doesn't matter. My first page, let's call it main.php, takes a first name and a last name for input, by way of a regular HTML <form>. When submitted, employee_search.php is called. This page makes an SQL query and retrieves the employees from the database who match the criteria entered. So if you entered "John" for first name and a blank last name, you would get: John Anderson John Jones John Smith John Williams ... etc code:
Here's my question - what way should I do it? I would like to avoid linking to 'employee_detail?ID=2352' (the ID would come from the SQL database) Would it be over-complicating things to make another form out of the table, with each returned person being a possible selection in that form? I could then have the form call employee_detail.php and just retrieve that field from the submitted form. Can I even do that? Or is there a better way to do it that I'm not thinking of?
|
# ? Mar 8, 2010 22:49 |
|
Bob Morales posted:Here's my question - what way should I do it? I would like to avoid linking to 'employee_detail?ID=2352' (the ID would come from the SQL database) Do you mean a select element with multiple='true' set? In that case you add a [] to the name of the element in HTML: name='herdOfEmployes[]' and then you can treat the argument as an array of strings in PHP: $_REQUEST['herdOfEmployes'][0] Otherwise I'm not sure what you mean
|
# ? Mar 9, 2010 00:05 |
|
Munkeymon posted:Do you mean a select element with multiple='true' set? In that case you add a [] to the name of the element in HTML: name='herdOfEmployes[]' and then you can treat the argument as an array of strings in PHP: $_REQUEST['herdOfEmployes'][0] If you had a list of search results like mine (employee list), how would you make the links so that you could click on each one and launch an 'edit employee' page?
|
# ? Mar 9, 2010 00:25 |
|
Basically, he wants to hit e.g. edit_employee.php, and pass an argument to show the data for that user, but without directly linking to it with a $_GET / edit_employee.php?userid=xxx I'm not 100% how you would do this.. Maybe some .htaccess tomfoolery? - You could maybe pass it as edit_employee.php?userid=xxx and hide it with a rewrite of some sort..
|
# ? Mar 9, 2010 00:28 |
Bob Morales posted:Here's my question - what way should I do it? I would like to avoid linking to 'employee_detail?ID=2352' (the ID would come from the SQL database) Why? That's how you should do it. If you don't want employee ids to be known, do something to encrypt/decrypt it. Also, your HTML needs some work. Use lowercase tags. No <center> tags, use CSS. You are also missing some column definitions. Take a look at this html references. fletcher fucked around with this message at 00:31 on Mar 9, 2010 |
|
# ? Mar 9, 2010 00:28 |
|
fletcher posted:Why? That's how you should do it. Also, your HTML needs some work. Use lowercase tags. No <center> tags, use CSS. You are also missing some column definitions. Take a look at this html references. That's kind of what i was thinking.. I've never really seen ( well.. noticed ) it done any other way.
|
# ? Mar 9, 2010 00:30 |
|
fletcher posted:Why? That's how you should do it. If you don't want employee ids to be known, do something to encrypt/decrypt it. Alright, if that's the way to do it, that's the way I will do it. I know about the CSS stuff but I wasn't worried about that right now, I'll get up to speed on going beyond deprecated HTML next. Like I said, it's been a long time. I guess what I was thinking was like this: code:
Bob Morales fucked around with this message at 00:41 on Mar 9, 2010 |
# ? Mar 9, 2010 00:37 |
|
I have an image resizing script that runs fine from my public html directory, but when I move it into my private directory and try to run it as a cron job, it gives me file permission errors. It seems it can read filesizes, but it cannot open or copy files. I've tried to chmod all the appropriate directories 777 to test it out, but that doesn't work. Do I need to run the cron script as a different user? How do I do that? Here is how I'm running it out of Plesk's crontab:code:
Little Brittle fucked around with this message at 00:57 on Mar 9, 2010 |
# ? Mar 9, 2010 00:46 |
Bob Morales posted:Alright, if that's the way to do it, that's the way I will do it. Don't get me wrong, it could work. It's just not what the POST method was really intended for. Read about what the difference between a GET and a POST is for more information. A general rule of thumb is to use a POST when you are going to be modifying some data. If you just want to retrieve some data, use a GET. Like this message I'm typing for example. I'm going to POST it to the forums, and it will redirect me to a link that will GET the thread, with the thread id # in the URL.
|
|
# ? Mar 9, 2010 00:48 |
|
fletcher posted:Don't get me wrong, it could work. It's just not what the POST method was really intended for. Read about what the difference between a GET and a POST is for more information. A general rule of thumb is to use a POST when you are going to be modifying some data. If you just want to retrieve some data, use a GET. That's the explanation I wanted. Thanks.
|
# ? Mar 9, 2010 01:23 |
|
Dumb question; nevermind.
spiritual bypass fucked around with this message at 05:31 on Mar 9, 2010 |
# ? Mar 9, 2010 05:27 |
|
I've got this site with a crappy guestbook script. For every 10 posts, it creates a new page. The problem is that at the bottom of the guestbooks, it has all the other pages numbered. In the case of the sample guestbook, there are like 500 pages, and all of the numbers cause the page to stretch since they don't wrap. How can I make this so that <br> is inserted every so often? Thanks code:
|
# ? Mar 10, 2010 04:13 |
|
Switch the to a regular space. Then it will auto-wordwrap. So it will be: ...($i+1)."</a> " Peanut and the Gang fucked around with this message at 04:25 on Mar 10, 2010 |
# ? Mar 10, 2010 04:22 |
|
Ha, that did it. Thanks so much!
|
# ? Mar 10, 2010 04:27 |
|
|
# ? May 31, 2024 05:11 |
|
barbarianbob posted:Switch the to a regular space. Then it will auto-wordwrap. That's called a non-breaking space, by the way. It's a space that doesn't cause line breaks.
|
# ? Mar 10, 2010 04:28 |