Jump to content

cpd

Members
  • Posts

    883
  • Joined

  • Last visited

  • Days Won

    5

Posts posted by cpd

  1. Firstly, why are you grouping by ID when ID is, or at least should be, unique?

     

    I'm not really convinced you've searched high and low as you've identified the ORDER BY is ordering your result set but haven't searched how to use it? The key word is DESC meaning descending. You'll want to change it to ASC meaning ascending.

     

    Moreover, be patient for an answer. This forum has people contributing from all over the world with different time zones so just wait 24 hours and you should have an answer!

  2. Link the file with a <link ... /> tag and make sure you're link is written using the public domain not the file system. 

     

    e.g. a website in /home/user_account/public_html/some/css/main.css would require a /some/css/main.css in the href attribute of the <link ...> tag.

  3. Assuming the names are consistent throughout the CSV, i.e. they all start with Upper-case and are unique, you can cycle through them all in a similar way you already have and create a new array, then natural order the array.

    $teamTotal = array();
    while(($d = fgetcsv($fh, 1024) !== false) {
       $teams = explode("|", $d[0]);
       foreach($teams as $t) {
          if(isset($teamTotal[$t])) {
             $teamTotal[$t]++;
          } else {
             $teamTotal[$t] = 1;
          }
       }
    }
     
    arsort($teamTotal);
    

    You can now cycle through them in order highest-lowest. This algorithm however, will take a while to complete with large data so you may want to consider a different data structure other than an array if speed is important/you have large data.

  4. I'm slightly baffled by your question having read it several times. 

     

    Your first query is unnecessary as there is no relationship between the first query and second query. Moreover, you'r third query isn't necessary as you've got all that information requested from the second query; there's no need to re-request it.

     

    @ginerjm, its mysqli_fetch_...() not query().

  5. I thoroughly enjoyed reading this absolutely magnificently in-depth OP. Please be sure to continue posting in such an insightful manner.

     

     

     

    Dude...  :sarcastic:  I'm being sarcastic. You're going to get 0 responses without giving details of the specific problem.

  6. Actually, as with PHP 5.5 the PHPass libraries are outdated.

     

    How come its out of date?  I.e. what methods used are out of date? I've not checked for a while, but can't find anything that suggests it is with a quick read up. Unless you mean it doesn't take advantage of some of the newly available features due for release with 5.5?

     

    Edit: I meant to link https://github.com/rchouinard/phpass in a previous post! Haven't had to download it in a while.

  7. Yes. If you're going to authenticate a user with a username, you need to make it unique else two users could in theory login with each others credentials. When you query the database for the user, select the user ID and store it in as a session variable as you are with the username.

  8. ... but that requires having specific details of what that code and data is and how it is being used. posting an example of your data (the input) and what result(s) you are trying to get from that data (the output) would allow someone to help specifically with what you are doing and why your code might be having a problem after x number of iterations.

     

    I thought I already made a post explaining this. Mac_gyver has hit the nail on the head! To really determine how you should be going about your problem we need to see specific code examples.

  9. Your database doesn't really make sense. If you have a `user_id` field in the database, don't have a `name` field as well. You should retrieve the name from the `user` table, when you need to display the messages, using a JOIN. If a user is logged in, I usually store their ID as session data to easily retrieve their details. In this case you can just use that ID in your query as the user logged in is the one posting a new message.

     

    You shouldn't be redirecting by echoing out a bit of javascript either. Use header("Location: success.php") instead.

  10. If you're trying to learn how to program you should really learn best practices as well. How you encrypt your password falls under best practices and running an MD5 hash on it only isn't one of them. 

     

    Do you only have a dialogue box login? You don't have a login page? Moreover, why would you submit a form with javascript when you can do it with a normal submit button? You're not doing anything special with javascript so let the submit button do the work. 

  11. I was concerned when writing it you'd pick up on the two statements as they appear contradictory. From what you've said, you seem to be grabbing a load of data and shoving it all into a data structure (array), then passing it around even though the receiving object may not need the majority of data. It would be more efficient to get what data you want as and when you need it with an additional call rather than requesting superfluous data. As an example you can think of building a car (CarTypeA). Each part of a car has a blueprint (CarTypeALeftDoor, CarTypeBLeftDoor...). You shouldn't select all blue prints for every single car part for all car types, put it in an array that is passed to a car builder which extracts the blue prints for CarTypeA only. You should only select the data you need at that point in time, the blue prints for CarTypeA.

     

    When I say "pass the object around" I mean request the required data, encapsulate it within an object and pass the object to any other object that requires it. For example if you have a user you can request their data and wrap it in a user object and pass the user object to whatever other object needs it. You wouldn't get all users on a hunch that you may need the data later. By breaking everything down and separating your logic you could potentially improve your efficiency as your loops could be broken down. 

     

    E.g.

    foreach($foo as $bar) {
       foreach($bar as $f) {
          // Code omitted
       }
    }
     
    foreach($foo as $bar) {
       // Code omitted
    }
    

    The first loop has an efficiency of O(N^2) and the second has O(N) which is far more efficient.

  12. ... Im just saying divs arent meant to be floated...

     

    Since when?

     

     A fluid design would mean that the page changes depending on the current page width.

     

    So a fixed width design isn't fluid?  :huh:

     

     

    Floats floats floats. I suggest you look at G+, they pull it off without any floating. Learn from the big guys.

     

    1) Go to https://plus.google.com/_/scs/apps-static/_/ss/k=oz.home.1drl9boq6bg3u.L.W.O/am=AAFwDADwsoEQDBBiAAEAAA0AoIFQRIBgvtcEAAAAIA/rs=AItRSTOmkJBpcmDiX5rOVnt-KDjaBzU0bg. 2) Hit CTRL+F. 3) Type "float". I count 533. I think you'll find they take control of positioning using JavaScript and not just CSS...

  13. You also don't understand JavaScript, you can't re-size an image using JavaScript. You can make it look smaller, but you can't physically change it's dimensions.

    You need to use PHP to find the ratio of how to scale the image, then save the image in the correct dimensions (All done by PHP)

     

    I beg to differ. Its now possible to re-size images client-side by using the new "canvas" element [1][2][3]. A completely new image! I tried it myself when playing around with HTML5. Moreover, PHP creates an entirely new image when you use GD; it doesn't manipulate the image stored on the file system as you appear to think, but instead manipulates a copy created from the actual image.

     

    [1] Pascal Helfenstein. Resizing images with Javascript. http://blog.liip.ch/archive/2013/05/28/resizing-images-with-javascript.html

    [2] Mozilla.org. How to develop an HTML5 image uploader. http://hacks.mozilla.org/2011/01/how-to-develop-a-html5-image-uploader/

    [3] Andrea Giammarchi. 100% Client Side Image Resizing. http://webreflection.blogspot.co.uk/2010/12/100-client-side-image-resizing.html

  14. It might work properly but its bloody awful!

    1. Not really sure what "// Start session" is meant to describe but it definitely doesn't appear to call session_start(). Is this even correct?
    2. Doing if(!$username || !$password) isn't good validation at all. All you're really testing is if the variable is initialised. A variable is initialised if it contains a space therefore, if the user submits a space as a username its valid; that's just wish-wash. Ideally you shouldn't allow spaces either side of a username when the user is created, then trim() the username just before validation upon login.
    3. session_register() was deprecated in 5.3 and removed in 5.4 [1] so you shouldn't really be using it although if you're still on an older version obviously you can; not sure how advisable this is.
    4. MD5 hasing a password is by no means satisfactory security. You should encrypt the password using multiple techniques all of which are covered by a nifty script called PHPass [2].
    5. MySQL is going to be deprecated so look at moving to PDO or MySQLi. 
    6. The way you're setting sessions isn't brilliant and the data you're setting is questionable.
      1. You're setting their password in the users session which isn't good unless you have taken precautions to help prevent the session from being hijacked.
      2. The "budgets" should really be stored in an array or serialised object. 
    $_SESSION['budget'][0]['name'] = $budget_1_name;
    $_SESSION['budget'][0]['total'] = $budget_1_total;
    $_SESSION['budget'][1]['name'] = $budget_2_name;
    $_SESSION['budget'][1]['total'] = ...;
    

    Although I probably wouldn't have variables such as $budget_1_name as they would be better represented as an array.

     

    With regards to your actual question: 1) store the success/error message in a session; 2) redirect to the appropriate page, login page for errors or dashboard for a success; 3) display the message where you want within each page by testing if the session has been set; 4) unset the session ensuring it doesn't continuously pop up.

     

    [1] PHP. session_registerhttp://uk1.php.net/session_register

    [2] Openwall. Portable PHP Password hashing. http://www.openwall.com/phpass/

×
×
  • 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.