Jump to content

Yucky

Members
  • Posts

    81
  • Joined

  • Last visited

    Never

Posts posted by Yucky

  1. A bit rough, but here goes:

    <table width="300" border="1" cellspacing="0" cellpadding="0">
    <?php
    foreach($yourArray as $key => $value):
    switch($value['yourCategory']) {
    case 1:$colour = "00000";break;
    case 2:$colour = "FFFFFF";break;
    }
    ?>
              <tr>
                <td bgcolor="#<?=$colour;?>"><?=$value['yourCategoryName']; ?></td>
                <td bgcolor="#<?=$colour;?>"><?=$value['yourCategoryData']; ?></td>
              </tr>
    <?php endforeach; ?>
    </table>
    

     

    Wouldn't be too hard to move the logic into the function that returns your data array.

  2. I am not gonna answer that since it would be more that nice to try it and see it for your self.

    Just skip your site for a brief second and make a .php file (SO NOT A .HTML file)

    if it's a .html file it wont work. (oh could it maybe be that my page is named page9.html and that facks everything up?? a little voice says: YES!)

     

    Just run my code I made. Don't implement or do anything with it just run it as is. (as a .php file!!)

    Oops now I gave the answer i think 4 times. :rtfm: :'( :'( :'(

     

    I've told him this several times already. :(

     

    By default, HTML files will not be parsed by PHP.

  3. I try and keep most of my site's infrastructure outside of user's view, just by loggin most errors somewhere safe in a txt file.

     

    For user errors like "Please enter a username..", I tend to log them in the array, I wouldn't go as far as doing multidimentional arrays unless I am running a large scripts with different possibilities of errors/failures.

     

    Given that you may want to return data to be displayed on the page as well as error messages, it seems logical to use multidimensional arrays.

     

    I find that it's easier to stick with one structure even when I don't need to send data/error messages back to the user rather than possibly changing it later down the line.

  4. Using an array to hold errors is pretty standard. Have you considered using a multidimensional array instead?

     

    When I need to display errors to the user, I tend to use a multidimension array that might have a structure along the lines of:

    $array['data'][] - data needed be displayed goes in this subarray.

    $array['errors'][] - informative error messages are stored in this subarray and later looped through.

    $array['success'] - true/false. Helps to determine styling such as a tick or a cross.

  5. Change:

    $qry = "SELECT * FROM users WHERE username='$_POST['username']'";
    

     

    To:

    $qry = "SELECT * FROM users WHERE username='".$_POST['username']."'";
    

     

    Take care with double/single quotes. With your original code, PHP would have seen $_POST[ and then been cut off by the single quote.

  6. You're correct in some respects. A class is an OO paradigm that allows you to organise your code by grouping related functions.

     

    You seem a bit confused as to what a class is for though. It's not a case of classes vs functions as one is not a substitute for the other. They both serve entirely different purposes.

     

    If you're going to use OO then follow it through and stick with it. Don't switch between procedural and OO coding styles in one program.

     

    I think you have it wrong also. using OO in php doesn't mean writing a class for everything you do, it would be more of a time consuming process then just plain old simply functions.

     

    I don't believe mixing programming paradigms in such a fashion is good style. If you're going to use OOP, stick to it throughout. I didn't advocate writing a class for every function that didn't fall nicely into an existing class. Having a utilities/misc class with static functions seems like an acceptable solution.

     

    I'm more than open to arguments in favour of switching between procedural and OO though. :)

  7. I guess he's trying to say that all of the PHP code is displaying in his browser. I did consider that it wasn't being parsed at all but I concluded that he meant that only the code in the text field was being displayed.

     

    Make sure the document extension is .php and not .html or some variant. If that fails to work, make sure you actually have a working PHP installation on your server. ;)

  8. Are you talking about includes here or totally different scripts?

     

    If the former, it'd be slightly quicker to have everything in one file. However, you'll be using more memory if you're including code that isn't relevant to the action being performed.

     

    If the latter, I doubt it makes any difference whatsoever.

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