Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,298 members, 7,808,012 topics. Date: Thursday, 25 April 2024 at 03:12 AM

Php Script Review Please/abeg/anyone?! - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Php Script Review Please/abeg/anyone?! (967 Views)

Website Review --->please Review This Site For Me Tnks / BLOG REVIEW: Please Criticise This Blog / Website Review, Please Post A Comment (2) (3) (4)

(1) (Reply) (Go Down)

Php Script Review Please/abeg/anyone?! by bakenda(m): 5:27am On Mar 22, 2008
easter.php

<?php
$con=mysql_connect("localhost","name","pass"wink;
if(!$con)
{
die('Sorry,our server is on Easter break:'.mysql_error());
}
mysql_select_db("nairalanddb",$con);
$action=@mysql_query("select * from nairaland where category='webmaster' and sense_of_humour='ON'"wink;
if (mysql_num_rows($action)!=0)
{
echo"<strong>HAPPY EASTER</strong>.\n\n";
echo"<em>And remember, we are alive today due to the price He paid on the cross of calvary.</em>";
}
else
echo"How come";
mysql_close($con)
?>
Re: Php Script Review Please/abeg/anyone?! by my2cents(m): 12:52pm On Mar 22, 2008
LOL,

Bakenda, nice creativity.

Here are my pointers:

1) You need to indent your code man. It is hard to read as is. I would go for tabbing. So, it would look something like this:

<?php
$con=mysql_connect("localhost","name","pass"wink;
if(!$con) {
die('Sorry,our server is on Easter break:'.mysql_error());
}
mysql_select_db("nairalanddb",$con);
$action=@mysql_query("select * from nairaland where category='webmaster' and sense_of_humour='ON'"wink;
if (mysql_num_rows($action)!=0) {
echo"<strong>HAPPY EASTER</strong>.\n\n";
echo"<em>And remember, we are alive today due to the price He paid on the cross of calvary.</em>";
}
else
echo"How come";
mysql_close($con)
?>


2) no semi-colon after "mysql_close($con)" on last line.

3) I would probably take out the "strong" and "em" tags and use spans, then declare a class and/or id that would handle this in the CSS. You want to separate presentation from content as much as possible. Sure, if it is a one-off situation, inserting it in the HTML is fine, but so as to get used to it, I always try as much as possible to let CSS handle such.

4) It is common practice to make your SQL reserved words uppercase (SELECT, AND, WHERE)

5) Personal preferene: Even if there is only one line of code within an if and/or else statement, I like to enclose them regardless, so as to avoid possible confusion, within braces. Looking above, you might agree that it is possible to lump the close connection code with the "how come". Remember, you code so that others can modify without difficulty in the future instead of spending time scratching their heads trying to figure out what is going on.

6) Personal preference 2: Due to server performance (or whatever you want to call it), I like to give control to the server only when necessary. In other words, if all I am doing is printing HTML, I let the browser do that and not the server. Example:

<?php
if (mysql_num_rows($action)!=0) {
?>
<p><strong>HAPPY EASTER</strong></p>
<?php
}
?>

Note that the HTML indenting is different from the PHP's, again, for easier reading. Also, note that I am using "P" tags as opposed to the carriage returns, again letting the browser handle the breaks.

This is a personal preference. I am sure there are those who would say that opening/closing too many server-side code sections is equally tasking on the server.

Overall? Nice sense of humor and thanks for pioneering an actual code review. Hopefully, there is more to come.
Re: Php Script Review Please/abeg/anyone?! by my2cents(m): 1:22pm On Mar 22, 2008
Sorry for the 2bl post but I didn't want this to get lost among modifications:

For reusability, easier reading and abstraction purposes, you might also want to consider putting your DB calls in a generic DB function and including that on your pages. So you could do something like so:

$variableName = dbFxnCall(pass in name, server and password).
if($variableName)
do stuff
else
do other stuff

your dbFxnCall would then handle connections, etc. That way, you are writing the connection stuff once as opposed to copying and pasting which could get ugly. Imagine if you are doing DB stuff on 20 pages then I come back and say, "the server name has changed". You would need to change the name in 20 places. With a function call, you change it just once.
Re: Php Script Review Please/abeg/anyone?! by bakenda(m): 1:56am On Mar 23, 2008
Points noted.Thanks.
Re: Php Script Review Please/abeg/anyone?! by smartsoft(m): 8:47am On Mar 24, 2008
Seems we learning PHP coding here lol
Re: Php Script Review Please/abeg/anyone?! by Nobody: 11:50am On Mar 24, 2008
as for me, i love this pattern

$variableName = dbFxnCall(pass in name, server and password).

if($variableName){

do stuffs
do more stuffs
do yet more stuffs

}else{

do other stuff
do more other stuffs
do yet more other stuffs

}

notice how i packed the codes to execute 2gether, try it and compare it to what you are used to
so when reading through, all i look out for is[b] if()[/b] and }else{

I prefer to stay off the <p> tag, it gives me headaches when checking against browsers (mozilla/netscape) Versus MSIE
Hard to figure until i replace them with <br> and spaces
Re: Php Script Review Please/abeg/anyone?! by my2cents(m): 2:32pm On Mar 24, 2008
I prefer to stay off the <p> tag, it gives me headaches when checking against browsers (mozilla/netscape) Versus MSIE
Hard to figure until i replace them with <br> and spaces

webdezzi, please expatiate as I don't understand.

P tags are the semantic way of presenting paragraphs and are much more SEO friendly. Not to mention, though not always noticeable, P tags save a few bytes compared to using 2 BRs, over time. If I understand what you mean though(if not, I stand corrected and await what you actually mean), there are differences in the way P tags are rendered b/w browsers. That is okay. You can always use CSS to modify the default margins. Also, if you are really a stickler for ensuring that everything looks picture perfect in all browsers, you can always right a hack for specific browsers wink

I hope this helps.
Re: Php Script Review Please/abeg/anyone?! by Nobody: 6:43pm On Mar 24, 2008
the problem has to do with upper and lower margins when working on heavy sites

I care much about every detail in all browsers(display-wise) and am addicted to using tables over CSS
There is a guy at my ex-workplace who just cant stand it but thats just me
Re: Php Script Review Please/abeg/anyone?! by my2cents(m): 7:02pm On Mar 24, 2008
webdezzi, it shdnt matter. Again, you can control that via CSS. Take a random sampling of sites I have done. Look at pages with a lot of text and note the use of P tags. All you have to do is hv a generic css call like so (called style resetting):

p { margin: 0;}

Then, assign an id to the P tags you will use (or class if you will use a lot of them) like so (for example):

p.content { margin: 5px 0; }

Please note that certain tags don't work well/behave consistently with padding (the distance b/w an element and its container) but do better across browsers with margins (the distance b/w neighboring elements).

It's all in the box model. If you understand that, then as I said, you have nothing to worry about. Each browser has its difference, yes. But you don't have to make your P tags 10px in IE and 7px in FF just to make the site a carbon copy of itself across the board. Differences are allowed. The main thing is consistency.

Just give it a try. If you need help, if I have time, I don't mind lending a hand. For starters, give me a site you have done and let me show you how it could be implemented.

I bet once you grasp it, you won't use tables/BRs again (or if you do, very sparingly) wink
Re: Php Script Review Please/abeg/anyone?! by Nobody: 8:46pm On Mar 24, 2008
whao, looks to me like "object oriented CSS"

will read the box model thing when am less busy n let u know if i need help, thanks very much

(1) (Reply)

Please I Need Your Criticisms On This Website I Just Finished Developing! / актеры фильма сумерки сумерки скачать бесплатно онлай / Filesonic Premium Reseller At Good Price

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 28
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.