Yucky
-
Posts
81 -
Joined
-
Last visited
Never
Posts posted by Yucky
-
-
First off, don't use the <?= 'quick echo' syntax. It'll come back to haunt you. Just write it properly the first time.
I used quick tags for brevity in the example. Apart from that, there's not really anything wrong with it. It seems to be the cleanest and quickest way of doing what he wanted.
-
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.
-
Your question doesn't really make any sense. What are you trying to achieve?
-
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. :'( :'( :'(
I've told him this several times already.
By default, HTML files will not be parsed by PHP.
-
In what way doesn't it work?
-
I said earlier that the file should be .php, not .html.
-
You have to run the script on a proper server that supports PHP. You can't just preview PHP scripts in your browser.
-
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.
-
Or verification phrases.
Or those.
-
Did you remember to use session_start();?
Edit: Beaten to the punch.
-
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.
-
There's not anything you can do to prevent automated form filling. You can however try and prevent automated form submission through the use of captchas.
-
Couldn't find fault with it.
-
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.
-
As it doesn't sound like a big site, you should look at using a single include file that would contain your functions.
I don't think including business logic (essentially the code that makes your site work) in your presentation (HTML/CSS) is ever the right thing to do.
-
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.
-
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.
-
Those are unicode characters. Try parsing it with the correct character set.
-
what if it's Tuesday when they pick Tuesday?
Last week's Tuesday.
-
If you set a session in the URL, a user's session can be maintained even if they have cookies disabled.
-
Just to be clear, if they selected Tuesday, would you want last week's Tuesday or the last Tuesday gone?
-
Perhaps short tags aren't enabled.
Try <?php echo $random_number; ?> instead of <?=$random_number;?>.
-
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.
-
Ask them to find out why it triggered the spam filter. He might be able to find out by checking the headers.
img title
in PHP Coding Help
Posted
Fix: