To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > Code Critique

Code Critique Having someone critique your code is always a great way to hone the skills. Stop in and post your code to see what your peers may have done differently.

Reply
 
Thread Tools Rate Thread Display Modes
Old 11-20-2003, 09:27 PM   #1
MFKR
Member
 
Join Date: Jul 2003
Location: Washington State
Posts: 45
Article Script, Possible improvements?

here is a link to my article script. Any suggestions on how to shrink it down or make it more automated?
__________________
abcdefghijklmnopqrstuvwxyz
1234567890
MFKR is offline   Reply With Quote
Old 11-20-2003, 10:26 PM   #2
LordShryku
kung foo code monkey
 
LordShryku's Avatar
 
Join Date: Aug 2002
Location: Occupational Hypnotherapy
Posts: 7,473
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 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

Last edited by LordShryku; 11-20-2003 at 10:29 PM.
LordShryku is offline   Reply With Quote
Old 11-20-2003, 10:50 PM   #3
MFKR
Member
 
Join Date: Jul 2003
Location: Washington State
Posts: 45
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 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.
__________________
abcdefghijklmnopqrstuvwxyz
1234567890
MFKR is offline   Reply With Quote
Old 11-20-2003, 10:58 PM   #4
LordShryku
kung foo code monkey
 
LordShryku's Avatar
 
Join Date: Aug 2002
Location: Occupational Hypnotherapy
Posts: 7,473
Was untested, and just kinda slapped together. More of an idea for you than a full working piece.
LordShryku is offline   Reply With Quote
Old 11-20-2003, 10:59 PM   #5
MFKR
Member
 
Join Date: Jul 2003
Location: Washington State
Posts: 45
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.
__________________
abcdefghijklmnopqrstuvwxyz
1234567890
MFKR is offline   Reply With Quote
Old 11-20-2003, 11:11 PM   #6
planetsim
code | beer > sleep
 
Join Date: Sep 2002
Location: aus
Posts: 4,826
Just a suggestion keep HTML and PHP in a seperate file. It makes it so much easier to work with.
__________________
Dont be lazy Search
And use the Manual
Webmobo - Open Source News Script | Portfolio / Blog | Against TCPA
planetsim is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 03:47 AM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.