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 01-06-2004, 08:02 PM   #1
mabans
PHP Loser
 
mabans's Avatar
 
Join Date: May 2001
Location: San Diego California
Posts: 62
My Art Display

Now this works but for some reason it gives me a weird display near the bottom of the page. you can see by following this link.

http://69.13.156.225/test/includes/m...php?show_cat=1

I do plan on have the overall display to be in 2 columns as well as breaking it up into different pages. I do want to see if my overall technique is well done as well as some input on why I'm getting an odd display at the bottome. thanks in avance.




PHP Code:
<?php

//The Required Files to access the data base
require("../../../includes/configs/config.cfg");
require(
"../../../includes/configs/select_db.cfg");
//The Required Files to access the data base

$show=$_GET['show_cat'];

$sql = "SELECT * FROM `poster` WHERE category=$show ORDER BY 'code' ASC";

$results = mysql_query($sql) or die ("Could not do, what you ask of me, sorry man. Check your Code!");

    while (
$results_row = mysql_fetch_array($results))
{
    
extract($results_row);

        
// This display the image artwork//
    
echo "<table cellspacing=5 cellpadding=0 border=0 width=100%>"
        
."<tr>"
        
."<td align=left valign=top width=35>"
        
."<a href=full_view.php?show_cat="
        
.$results_row['ID']
        .
">"
        
."<br><img src=../../../images/"
        
.$results_row['imagethumb']
        .
">"
        
."</a></td>"
        
// This display the image artwork//
        
        
."<td align=left valign=top height=167>"
        
        
// This is the information table with all the proper artwork info//
        
."<table cellpadding=2 cellspacing=0 border=0 height=136 width=100%>"
        
."<tr>"
        
."<td>"

        
// This is the art Item Code //
        
."<div class=unnamed1>"
        
."<a href=full_view.php?show_cat="
        
.$results_row['ID']
        .
">"
        
.$results_row['code']
        .
"</a>"
        
."</td>"
        
."</tr>"
        
// This is the art Item Code //

        // This is the Artwork Name //

        
."<tr>"
        
."<td bgcolor=#eaeaea>"
        
."<div class=unnamed1><font color=#000000>"
        
.$results_row['postername']
        .
"</font></div>"
        
."</td>"
        
."</tr>";
        
        
// This is the Artwork Name //
        
        
        

        
        // This is the Artist Name //
        
$artist_id=$results_row['artist'];

$artist_sql = "SELECT * FROM `artist` WHERE ID=$artist";

$artist_results = mysql_query($artist_sql) or die ("Could not do, what you ask of me, sorry man. Check your Code!");
    while (
$artist_row = mysql_fetch_array($artist_results))
{
    
extract($artist_row);

        echo
"<tr>"
        
."<td>"
        
."<div class=unnamed1>"
        
.$artist_row['artistname']
        .
$artist_row['artistlastname']
        .
"</font></div>"
        
."</td>"
        
."</tr>"
        
        
// This is the Artist Name //

        // Poster Size Text //
        
        
."<tr>"
        
."<td>"
        
."<div class=unnamed1>Paper Size:</div>"
        
."</td>"
        
."</tr>"

        
// Poster Size Text //

        // Paper Size Info//
        
        
."<tr>"
        
."<td>"
        
."<div class=unnamed1>"
        
.$results_row['papersizeincheswt']
        .
" x "
        
.$results_row['papersizeinchesht']
        .
" In | "
        
.$results_row['papersizecmwt']
        .
" x "
        
.$results_row['papersizecmht']
        .
" Cm"
        
."</div>"
        
."</td>"
        
."</tr>"

        
// Paper Size Info//

        // Image Size Text //
        
        
."<tr>"
        
."<td>"
        
."<div class=unnamed1>Image Size:</div>"
        
."</td>"
        
."</tr>"

        
// Image Size Text //

        // Image Size Info//
        
        
."<tr>"
        
."<td>"
        
."<div class=unnamed1>"
        
.$results_row['imagesizeincheswt']
        .
" x "
        
.$results_row['imagesizeinchesht']
        .
" In | "
        
.$results_row['imagesizecmwt']
        .
" x "
        
.$results_row['imagesizecmht']
        .
" Cm"
        
."</div>"
        
."</td>"
        
."</tr>"

        
// Image Size Info//

        // Pricing Info //
        
        
."<tr>"
        
."<td>"
        
."<div class=unnamed1>"
        
."$"
        
.$results_row['price']
        .
"</div>"
        
."</td>"
        
."</tr>"
        
// Pricing Info //
        
."</td>"
        
."</tr>"
        
."</table>"
        
."</td>"
        
."</tr>"
        
."</table>";


        
// This is the information table with all the proper artwork info//

}
}
?>
__________________
I really hate the fact I don't know PHP as much as I should, but I'm getting there.
mabans is offline   Reply With Quote
Old 01-06-2004, 08:12 PM   #2
LordShryku
kung foo code monkey
 
LordShryku's Avatar
 
Join Date: Aug 2002
Location: Occupational Hypnotherapy
Posts: 7,473
Debugging becomes pretty much impossible when you have that much page, and all of the html is on one line. View the source of your rendered page. It's not pretty....
LordShryku is offline   Reply With Quote
Old 01-06-2004, 08:54 PM   #3
mabans
PHP Loser
 
mabans's Avatar
 
Join Date: May 2001
Location: San Diego California
Posts: 62
In that case I have limited the results to 30.

review here: http://69.13.156.225/test/includes/m...php?show_cat=1


$sql_=_"SELECT_*_FROM_`poster`_WHERE_category=$show_ORDER_BY_'code'_ASC LIMIT 30";


This seems to be the place where things go all crazy. I am looking into the HTML as we speak. But I am still willing to listen to Critiques on my coding style.
__________________
I really hate the fact I don't know PHP as much as I should, but I'm getting there.
mabans is offline   Reply With Quote
Old 01-06-2004, 08:55 PM   #4
mabans
PHP Loser
 
mabans's Avatar
 
Join Date: May 2001
Location: San Diego California
Posts: 62
Yikes! I see your point..

I have somewhat corrected the issue but I do see some problems with my table postioning
__________________
I really hate the fact I don't know PHP as much as I should, but I'm getting there.

Last edited by mabans; 01-06-2004 at 08:59 PM.
mabans is offline   Reply With Quote
Old 01-06-2004, 09:54 PM   #5
LordShryku
kung foo code monkey
 
LordShryku's Avatar
 
Join Date: Aug 2002
Location: Occupational Hypnotherapy
Posts: 7,473
I'm writing a version of the code you posted somewhat like I would do it, but a couple things I'll comment on:

You call extract after your mysql_fetch_array's, but I don't see you using it. If your not going to use it, no real reason to have it.

Your html attributes should be quoted. It'll save you a headache later on when you go to put a space in there and can't figure out why it only shows the first word.

Once I get done, I'll post the code....
LordShryku is offline   Reply With Quote
Old 01-06-2004, 10:06 PM   #6
LordShryku
kung foo code monkey
 
LordShryku's Avatar
 
Join Date: Aug 2002
Location: Occupational Hypnotherapy
Posts: 7,473
Ok, here it is: posted and attached (in case the post looks like crap). You see I break out of php to do the html. Even within a loop, this will still work, and it will produce nice, easy to read rendered source code. We had a thread about this a while ago that dalecosp started, and at the time, I never did this sort of thing. Since then, I've become a real stickler with how my rendered code looks, mainly for this reason of debugging. Plus, I'm just an anal bastard. Hope this helps give you some ideas. Also, I removed you're comments so mine would stick out to you.
PHP Code:
<?php
require_once("../../../includes/configs/config.cfg");
require_once(
"../../../includes/configs/select_db.cfg");
## require_once allows it to be called later without error
$show=$_GET['show_cat'];
$sql = "SELECT *
          FROM `poster`
         WHERE category="
.$show."
      ORDER BY 'code' ASC"
;
## I prefer to break out of strings with "." when calling a variable
$results = mysql_query($sql) or die(mysql_error());
## mysql_error will give a more detailed error of the problem

while($results_row = mysql_fetch_array($results)) {
    
extract($results_row);
?>
<table cellspacing="5" cellpadding="0" border="0" width="100%">
  <tr>
    <td align="left" valign="top" width="35"><a href="full_view.php?show_cat=<?php echo $results_row['ID']; ?>">
     <br /><img src=../../../images/<?php echo $results_row['imagethumb']; ?>"></a>
    </td>
    <td align="left" valign="top" height="167">
      <table cellpadding="2" cellspacing="0" border="0" height="136" width="100%">
        <tr>
          <td><div class=unnamed1><a href="full_view.php?show_cat=<?php echo $results_row['ID']; ?>"><?php echo $results_row['code']; ?></a></td>
        </tr>
        <tr>
          <td bgcolor="#eaeaea"><div class="unnamed1"><font color="#000000"><?php echo $results_row['postername']; ?></font></div></td>
        </tr>
<?php        
   $artist_id
=$results_row['artist'];
   
$artist_sql = "SELECT *
                    FROM `artist`
                   WHERE ID="
.$artist;

   
$artist_results = mysql_query($artist_sql) or die(mysql_error());
   while(
$artist_row = mysql_fetch_array($artist_results)) {
      
extract($artist_row);
?>
        <tr>
          <td><div class="unnamed1"><?php echo $artist_row['artistname']." ".$artist_row['artistlastname']; ?></div></td>
        </tr>
        <tr>
          <td><div class="unnamed1">Paper Size:</div></td>
        </tr>
        <tr>
          <td><div class="unnamed1"><?php echo $results_row['papersizeincheswt']." x "
                                              
.$results_row['papersizeinchesht']." In | "
                                              
.$results_row['papersizecmwt']." x "
                                              
.$results_row['papersizecmht']." Cm"; ?>
              </div>
          </td>
        </tr>
        <tr>
          <td><div class="unnamed1">Image Size:</div></td>
        </tr>
        <tr>
          <td><div class="unnamed1"><?php echo $results_row['imagesizeincheswt']." x "
                                              
.$results_row['imagesizeinchesht']." In | "
                                              
.$results_row['imagesizecmwt']." x "
                                              
.$results_row['imagesizecmht']." Cm"; ?>
              </div>
          </td>
        </tr>
        <tr>
          <td><div class="unnamed1">$<?php echo $results_row['price']; ?></div></td>
        </tr>
      </table>
    </td>
  </tr>
</table>"
<?php
   
}
}
?>
Attached Files
File Type: txt mabans.php.txt (3.0 KB, 73 views)
LordShryku is offline   Reply With Quote
Old 01-07-2004, 01:36 AM   #7
mabans
PHP Loser
 
mabans's Avatar
 
Join Date: May 2001
Location: San Diego California
Posts: 62
Seems a lot neater and leaner. Means faster load times. Gotta love that. I tried it and I got a PArse error 6. Debugging now to see if it'll work.
__________________
I really hate the fact I don't know PHP as much as I should, but I'm getting there.
mabans is offline   Reply With Quote
Old 01-07-2004, 02:04 AM   #8
mabans
PHP Loser
 
mabans's Avatar
 
Join Date: May 2001
Location: San Diego California
Posts: 62
I also tried to see what you were talking about with the extracting the Fetch Array but the script doesn't seem to work if I don't include it in t he code. Is there another leaner way I can approach it?

Also thanks for all your input it's really cool your helping me out..
__________________
I really hate the fact I don't know PHP as much as I should, but I'm getting there.
mabans is offline   Reply With Quote
Old 01-07-2004, 02:12 AM   #9
mabans
PHP Loser
 
mabans's Avatar
 
Join Date: May 2001
Location: San Diego California
Posts: 62
It seemed to be some odd Charact Insertsion that I got when I just copied and pasted it. it worked fine sorry.
__________________
I really hate the fact I don't know PHP as much as I should, but I'm getting there.
mabans is offline   Reply With Quote
Old 01-07-2004, 04:33 PM   #10
mabans
PHP Loser
 
mabans's Avatar
 
Join Date: May 2001
Location: San Diego California
Posts: 62
To expand on what you were doing. I'm working on a method so I can get these results but in a 2 column view. So far I see my method being the best way to go.

This is how it's shaping up. I also took your advice about the whole extracting rows issue. so that is now gone.

here's the link: http://69.13.156.225/test/includes/m...php?show_cat=1


PHP Code:
<?PHP
//The Required Files to access the data base
require("../../../includes/configs/config.cfg");
require(
"../../../includes/configs/select_db.cfg");
//The Required Files to access the data base

$columns = 2;

$show=$_GET['show_cat'];

$query = "SELECT * FROM `poster` WHERE category=".$show ." ORDER BY 'code' ASC LIMIT 60";

$result = mysql_query($query) or die(mysql_error());

$num_rows = mysql_num_rows($result);

echo
"<TABLE BORDER=\"0\" WIDTH=q\"500\">\n";

for(
$i = 0; $i < $num_rows; $i++) {

$poster = mysql_fetch_array($result);

if(
$i % $columns == 0) {

        echo
"<TR>\n";

}

        echo
"<TD>"

        
.$poster['code']

        
// This display the image artwork//
        
."<!---- This display the image artwork--->\n"
        
."<table cellspacing=5 cellpadding=0 border=0 width=100%>\n"
        
."<tr>\n"
        
."<td align=left valign=top width=35>\n"
        
."<a href=full_view.php?show_cat="
        
.$poster['ID']
        .
">\n"
        
."<br>\n<img src=../../../images/"
        
.$poster['imagethumb']
        .
">\n"
        
."</a>\n</td>\n"
        
."</tr></table>"
        
."<!---- This display the image artwork--->\n"
        
// This display the image artwork //

        
."</TD>\n";

if((
$i % $columns) == ($columns - 1) || ($i + 1) == $num_rows) {

echo
"</TR>\n";

}
}
echo
"</TABLE>\n";
?>
__________________
I really hate the fact I don't know PHP as much as I should, but I'm getting there.
mabans 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 12:51 PM.






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.