Click to See Complete Forum and Search --> : Article Script, Possible improvements?


MFKR
11-20-2003, 09:27 PM
here (http://www.hamfriedchicken.com/show.php) is a link to my article script. Any suggestions on how to shrink it down or make it more automated?

LordShryku
11-20-2003, 10:26 PM
Don't hate me...here's my suggestions

1) Your use of table's or layout is going to get a lot of heat around here. CSS is the best way to do it.

2) You sporadicly close out your table tags. Some have closing tags, some don't. You should be closing them all out.

3) Seems like a lot of coding being done for something that could be looped. I would create arrays for the sections and titles, and loop through them. Here's an example(working with your existing code)

<?php
include_once "header.php";
include_once "config.php";

$sections = array("Article",
"Concert Review",
"Lyrics",
"Philosphy",
"Story/Poem",
"Tutorial");

$titles = array("Articles",
"Concert Reviews",
"Lyrics",
"Philosphies",
"Stories/Poems",
"Tutorials");

?>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td align="left"><b><?=$titles[$i]?></b></td>
<td align="right">
<a href="articles.php?by=desc"><img src="images/up.gif" border="0"'></a>
<a href="articles.php?by=asc"><img src="images/down.gif" border="0"></a>
</td>
</tr>
</table>
<?php
for($i=0;$i<count($sections);$i++) {
if(isset($Result)) {
unset($Result);
}
if(isset($row)) {
unset($row);
}
$Result = mysql_query("SELECT *
FROM ".$sqlTable."
WHERE article_sec='".$sections[$i]."'
ORDER BY article_title ".$by);
while ($row = mysql_fetch_object($Result)) {
?>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td align="left"><a href="article.php?id=<?=$row->id?>"><?=$row->article_title?></td>
</tr>
</table>
<?php
}
}

include_once "footer.php";
?>

HTH

MFKR
11-20-2003, 10:50 PM
hmmmm didn't quite work. I copied and pasted. Listed all the articles by type only problem was it doesn't like seperate them.

here (http://www.hamfriedchicken.com/articles.php) is the original script as is...

Thanks for the array stuff though I'm going to mess around with them and see if I can come up with anything like I had it.

LordShryku
11-20-2003, 10:58 PM
Was untested, and just kinda slapped together. More of an idea for you than a full working piece.

MFKR
11-20-2003, 10:59 PM
I applaud you still. I wish I could whip up something that quickly I usually have to look over a script I've already got and rework it to accommidate my new idea. I'll keep at it.

planetsim
11-20-2003, 11:11 PM
Just a suggestion keep HTML and PHP in a seperate file. It makes it so much easier to work with.