Feedback?
am 19.10.2007 13:28:09 von KyeAs a real pleb with the below being my first actual "real" script written
from scratch, could anybody please constructively criticise what should be
changed???
Thanks again for everybody's help
--
Yours Sincerely
Kye
---START CODE---
$category = "SELECT * FROM `links_categories` ORDER BY category ASC LIMIT
0 , 30" or die('Error, query failed');
$catlist = mysql_query($category) or die('Error, query failed');
echo "
?>
if ( isset($_POST[dropdown]) ) {
$heading = mysql_query("SELECT links_categories.category,
links_categories.cat_id FROM links_categories WHERE $_POST[dropdown] =
links_categories.cat_id") or die('Error, Heading select failed');
while ($row = mysql_fetch_array($heading, MYSQL_NUM))
{
$head = $row[0];
$catshow = $row[1];
}
} else {
$head = "Markets, Fairs, Fetes and Field Days";
$catshow = "3";
}
echo $head; ?>
links.date_added, links.display, links.fk_category,
links_categories.category, links.link_id FROM links, links_categories where
links.fk_category = links_categories.cat_id AND $catshow =
links_categories.cat_id ORDER BY name ASC" or die('Error, query failed');
$result = mysql_query($query) or die('Error, query failed');
while ($row = mysql_fetch_array($result, MYSQL_NUM)){
if ($row[5] = 1) {
echo "
| ||
| ||
Added to Database :"; list($year,$month,$day)=split("-",$row[4]); $display_date=date(" F d, Y",mktime(0,0,0,$month,$day,$year)); echo $display_date; echo " |
";
}
}?>
Re: Feedback?
am 19.10.2007 14:20:43 von henriOn Fri, 19 Oct 2007 11:28:09 +0000, Kye wrote:
> As a real pleb with the below being my first actual "real" script
> written from scratch, could anybody please constructively criticise what
> should be changed???
>
> Thanks again for everybody's help
well, does it at least do what you want it to do? otherwise, I don't see the point in giving "constructive criticism" to code that does what it's supposed to do.
Re: Feedback?
am 19.10.2007 14:26:23 von Kye> well, does it at least do what you want it to do? otherwise, I don't see
> the point in giving "constructive
> criticism" to code that does what it's supposed to do.
Yes it does do precisely what I wrote it to do, but it feels very
cumbersome. I am sure that it is also riddled with glitches, but I do not
have the knowledge to see what I should improve as of yet.
--
Yours Sincerely
Kye
Re: Feedback?
am 19.10.2007 15:53:31 von Steve"Kye"
news:dx0Si.1797$CN4.915@news-server.bigpond.net.au...
> As a real pleb with the below being my first actual "real" script written
> from scratch, could anybody please constructively criticise what should be
> changed???
yes...don't be a fucking dweeb! we spend our days cleaning up bad code. what
makes you think we'd want to look at more?
Re: Feedback?
am 19.10.2007 15:55:22 von Steve"Henri"
news:4718a11b$0$12795$426a74cc@news.free.fr...
> On Fri, 19 Oct 2007 11:28:09 +0000, Kye wrote:
>
>> As a real pleb with the below being my first actual "real" script
>> written from scratch, could anybody please constructively criticise what
>> should be changed???
>>
>> Thanks again for everybody's help
>
> well, does it at least do what you want it to do? otherwise, I don't see
> the point in giving "constructive criticism" to code that does what it's
> supposed to do.
so, you like driving your yugo? sorry, i like to go fast and in
style...without worrying about bursting into flames. you obviously are still
in the noobish category as well.
Re: Feedback?
am 19.10.2007 23:53:30 von henriOn Fri, 19 Oct 2007 08:55:22 -0500, Steve wrote:
> "Henri"
> news:4718a11b$0$12795$426a74cc@news.free.fr...
>> On Fri, 19 Oct 2007 11:28:09 +0000, Kye wrote:
>>
>>> As a real pleb with the below being my first actual "real" script
>>> written from scratch, could anybody please constructively criticise
>>> what should be changed???
>>>
>>> Thanks again for everybody's help
>>
>> well, does it at least do what you want it to do? otherwise, I don't
>> see the point in giving "constructive criticism" to code that does what
>> it's supposed to do.
>
> so, you like driving your yugo? sorry, i like to go fast and in
> style...without worrying about bursting into flames. you obviously are
> still in the noobish category as well.
ya, right
Re: Feedback?
am 20.10.2007 00:13:55 von colin.mckinnonOn 19 Oct, 12:28, "Kye"
> As a real pleb with the below being my first actual "real" script written
> from scratch, could anybody please constructively criticise what should be
> changed???
>
> Thanks again for everybody's help
>
> --
> Yours Sincerely
> Kye
>
> ---START CODE---
>
>
OK Kye, you asked for it....
There are no comments - I shouldn't have to reverse engineer you're
code to work out what its supposed to do and neither should you - the
very first line after
program is supposed to do. Most folk also keep some rough versioning
info here too.
> $category = "SELECT * FROM `links_categories` ORDER BY category ASC LIMIT
> 0 , 30" or die('Error, query failed');
Variable assignments always work - why are you planning for a scenario
where it doesn't? (or die...). Most serious programmers would work to
a style guide which cover SQL as well as PHP. Your variable names seem
sensible-ish so far - personally I usually insist on database name
prefixing and using some formatting with SQL statements, e.g.
$get_categories = "SELECT *
FROM maindb.links_categories
ORDER BY category
LIMIT 0,30";
This makes it easier to read and (for example) insert things like
"WHERE user='" . $_SESSION['current_user'] . "'"
You've used no modularity at all within your code - you haven't even
divided it into modes of operation, although it does seem to have sort
of a preparation stage and sort of a presentation stage. It's much too
long - learn how to use functions (and classes) also think about
putting common code into 'include' files.
> $catlist = mysql_query($category) or die('Error, query failed');
By line 2 your code has failed - did you really write the rest of the
code above without even testing this? The reason it failed is because
you did not issue a mysql_connect() unless it was via an auto-prepend
(this is very bad practice). When an error occurs, you make the
program bomb out without even trying to find out what the error was.
> echo "
Re: Feedback?
am 20.10.2007 02:09:20 von KyeThankyou for the critique. I have replied throughout.
> OK Kye, you asked for it....
>
> There are no comments - I shouldn't have to reverse engineer you're
> code to work out what its supposed to do and neither should you - the
> very first line after
> program is supposed to do. Most folk also keep some rough versioning
> info here too.
Ths is a very good point. I will have to make sure that I get into the habit
of using commenting to ensure that processes are remembered. Thankyou.
>> $category = "SELECT * FROM `links_categories` ORDER BY category ASC
>> LIMIT
>> 0 , 30" or die('Error, query failed');
>
> Variable assignments always work - why are you planning for a scenario
> where it doesn't? (or die...). Most serious programmers would work to
> a style guide which cover SQL as well as PHP. Your variable names seem
> sensible-ish so far - personally I usually insist on database name
> prefixing and using some formatting with SQL statements, e.g.
>
> $get_categories = "SELECT *
> FROM maindb.links_categories
> ORDER BY category
> LIMIT 0,30";
> This makes it easier to read and (for example) insert things like
> "WHERE user='" . $_SESSION['current_user'] . "'"
>
> You've used no modularity at all within your code - you haven't even
> divided it into modes of operation, although it does seem to have sort
> of a preparation stage and sort of a presentation stage. It's much too
> long - learn how to use functions (and classes) also think about
> putting common code into 'include' files.
>
>> $catlist = mysql_query($category) or die('Error, query failed');
>
> By line 2 your code has failed - did you really write the rest of the
> code above without even testing this? The reason it failed is because
> you did not issue a mysql_connect()
Its actually line 87, but you were only provided with the above information
so I understand that you can only comment on this information. The database
connection etc are all defined in the earlier protions of the page. This
chunk is my work so I was interected in learning what to fix in this chunk.
>unless it was via an auto-prepend
> (this is very bad practice). When an error occurs, you make the
> program bomb out without even trying to find out what the error was.
auto-prepend??? I am sorry but you have lost me. How do you mean about not
trying to find out what the error was? I thought that it was bad to leave
debug code in use after test mode was done,
>> echo "
Re: Feedback?
am 20.10.2007 19:08:57 von posOn Fri, 19 Oct 2007 11:28:09 GMT, "Kye"
>As a real pleb with the below being my first actual "real" script written
>from scratch, could anybody please constructively criticise what should be
>changed???
>
>Thanks again for everybody's help
Couple things that I learned along the way, and some of it from the helpful ppl
of this group.
1. Use functions or other code to 'figure out' data first, load it into
variables, then at the end of your page, start echo()ing out the HTML: Send
your $catlist to a function that will load the html into a var:
$list = myListFunc($catlist);
function myListFunc($list){
$html = "";
return $html;
}
2. You can avoid a bunch of switch, if/else stuff if you can use the info you
allready have:
instead of:
switch ($row[0]){
case "1":
echo '';
break;
etc etc
you can do
echo '';
Re: Feedback?
am 20.10.2007 19:59:59 von grossespinneHi, just one hint:
This statement:
> $heading = mysql_query("SELECT links_categories.category,
> links_categories.cat_id FROM links_categories WHERE $_POST[dropdown] =
> links_categories.cat_id") or die('Error, Heading select failed');
might be a security risk because it could allow mysql injection into
your database.
I mean an attacker could change the value of $_POST[dropdown] to be
some valid
mysql code and thus manipulate your databse. To fix this you should
use
mysql_real_escape_string() on each variable that holds input from the
user.