PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old August 27th, 2003, 01:36 AM
lobos34 lobos34 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: San Francisco
Posts: 17 lobos34 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Creating columns in a PHP page

Hello again everyone,

I could really use some help with a php page I am trying to design.

What I want to do:
I am working on a review web site for a friend, I would like to pull the fields (lets say "image", "company" and "title" and then have them link to the reviews ) from the MySQL database, have them show up in the browser 5 rows down and 5 col across. I have the 5 rows down working perfectly. I cannot for the life of me get 5 col across. Here is the code I have working (Only 3 rows down at this time).



PHP Code:
<?php
         
include("header.inc");
        
// display individual record

        
if ($id) {

       
$result mysql_query("SELECT * FROM reviews WHERE id=$id",$db);

        
$myrow mysql_fetch_array($result);
   
         echo 
"<center><br><table border=0 width=650>\n";
   
        
printf("<tr><td>%s &nbsp; &nbsp; &nbsp; &nbsp;%s </td><td>"$myrow["image"], $myrow["mpgs"]);
   
     
printf("%s\n<br><tr><td>"$myrow[""]);
   
     
printf("<b>Title:</b> %s\n<br><tr><td>"$myrow["title"]);
   
     
printf("<b>Company:</b> %s\n<br><tr><td>"$myrow["company"]);
    
     
printf("<b>Cast:</b> %s\n<br><tr><td>"$myrow["cast"]);

     
printf("<b>Director:</b> %s\n<br><tr><td>"$myrow["director"]);
   
     
printf("<b>Review:</b> %s\n<br><tr><td>"$myrow["review"]);
   
     
printf("<b>Links:</b>%s\n<br><tr><td>"$myrow["links"]);
   
     echo 
"</td></tr></table></center>\n";
} else {

    
// show employee list

   
$result mysql_query("SELECT * FROM reviews",$db);

    if (
$myrow mysql_fetch_array($result)) {

      
// display list if there are records to display

      
do {
       echo 
"<center><br><table border=1 width=250><tr>\n";
       
printf("<td><a href=\"%s?id=%s\">%s\n %s</a></td>\n"$PHP_SELF,$myrow["id"],$myrow["title"],$myrow["company"]);
       echo 
"</table></center></tr>\n";
       
      } while (
$myrow mysql_fetch_array($result));
       
    } else {
        
      
// no records to display

      
echo "Sorry, no records were found!";    

    }

     }

      include(
"footer.inc");

       
?>


I can get this to work perfect, but I cannot figure out how to get 5 colomns across.

Any help or php snipets Even a link to a tutorial on how to create cols in php. would be appreciated

Reply With Quote
  #2  
Old August 27th, 2003, 06:17 PM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
This snippet should help you (taken from: http://laidbak.net/phpsample/columnsplit/)
Code:
<table border="2">
<th colspan="100%">Raw Index Sample</th>
<?php
    for ($row=1; $row <= $numrows; $row++)
    {
        // Initialize Cells
        $cell = 0;
?>
        <tr>
<?php
        for ($col=1; $col <= $numcols; $col++)
        { 
?>
                <td>
<?php 
    if ($col===1) {
        print $cell += $row;
    } else {
        print $cell += $numrows; 
    }
?>
        </td>
<?php
        }
?>
        </tr>
<?php
    }
?>
</table>
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
  #3  
Old August 27th, 2003, 07:30 PM
lobos34 lobos34 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: San Francisco
Posts: 17 lobos34 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks laidbak,

I am sort of new at this so (at the risk of sounding stupid) exactly where in the code above would I put your code. I tested it a couple of times and got it to put the rows using your table
example:
title company
title company
title company
But what I want is :
title company | title company | title company

if you could tell me where to put it in the code I would appreciate it.

Thanks

Reply With Quote
  #4  
Old August 27th, 2003, 10:04 PM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
Whatever you want output in horizontally you will need to put between the:

<td> </td>

Reply With Quote
  #5  
Old August 27th, 2003, 10:51 PM
lobos34 lobos34 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: San Francisco
Posts: 17 lobos34 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for the info laidbak, but I am still getting it in rows not columns.

This is where I am confused:
you said put what I want Horz between the: <td> </td>
I did that and it worked fine but still only in rows. You have this in between there
PHP Code:
<td>
<?
php 
    
if ($col===1) {
        print 
$cell += $row;
    } else {
        print 
$cell += $numrows
    }
?>
        </td>

This is what I want to come out horz:
<?php
printf
("<a href=\"%s?id=%s\">%s\n %s</a>\n",*$PHP_SELF,$myrow["id"],$myrow["title"],$myrow["company"]);
?> 


So exactly where in between your <td></td> tags should I put it?

Thanks again

*******

Reply With Quote
  #6  
Old August 27th, 2003, 11:45 PM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
Replace my print statements with yours.

Reply With Quote
  #7  
Old August 28th, 2003, 12:09 AM
lobos34 lobos34 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: San Francisco
Posts: 17 lobos34 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Ok now it comes up blank. No error codes, nothing just three blank table rows I am at a loss.
here is the code could you take a look and see where I am screwing it up?
PHP Code:
<body>
<?
php
include("header.inc");
// display individual record

if ($id) {

   
$result mysql_query("SELECT * FROM reviews WHERE id=$id",$db);

   
$row mysql_fetch_array($result);
   
   echo 
"<center><br><table border=0 width=650>\n";
   
   
printf("<tr><td>%s &nbsp; &nbsp; &nbsp; &nbsp; %s</td><td>"$row["image"], $row["mpgs"]);
   
   
printf("%s\n<br><tr><td>"$row[""]);
   
   
printf("<b>Title:</b> %s\n<br><tr><td>"$row["title"]);
   
   
printf("<b>Company:</b> %s\n<br><tr><td>"$row["company"]);
    
   
printf("<b>Cast:</b> %s\n<br><tr><td>"$row["cast"]);

   
printf("<b>Director:</b> %s\n<br><tr><td>"$row["director"]);
   
   
printf("<b>Review:</b> %s\n<br><tr><td>"$row["review"]);
   
   
printf("<b>Links:</b>%s\n<br><tr><td>"$row["links"]);
   
   echo 
"</td></tr></table></center>\n";
} else {

    
// show employee list

   
$result mysql_query("SELECT * FROM reviews",$db);

    if (
$row mysql_fetch_array($result)) {

      
// display list if there are records to display

      
do {
       
       
?> 
       <table border=2 >
<th colspan=20%>
</th>
<?php
    
for ($row=1$row <= $numrows$row++)
    {
        
// Initialize Cells
        
$cell 0;
?>
        <tr>
<?php
        
for ($col=1$col <= $numcols$col++)
        { 
?>
                <td>

<?php 
      
if ($col===1) {
        
printf("<a href=\"%s?id=%s\">%s\n %s</a>\n"$PHP_SELF$row["id"], $row['title'], $row['company']);
    } else {
        
printf("<a href=\"%s?id=%s\">%s\n %s</a>\n"$PHP_SELF$row["id"], $row['title'], $row['company']);
    }
?>
        </td>
<?php
        
}
?>
        </tr>
<?php
    
}
?>
</table>
<?php
       
      
} while ($row mysql_fetch_array($result));
       
    } else {
        
      
// no records to display

      
echo "Sorry, no records were found!";    

    }

}

include(
"footer.inc");

?> 


Thanks

Reply With Quote
  #8  
Old August 28th, 2003, 02:12 AM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
I should have been more clear... my code wasn't supposed to be copy ready. In other words, you just pasted my code and glued your code into certain spots and it is not going to work like that.

The code I gave you was for you to see how it was done... I wasn't trying to do it for you.

Basically, you need to use the foreach statement and write out the proper <tr> <td> tags and place your variables where they are to be output.

I suggest mocking this up in straight html first, then it will be a matter of sticking the proper php code in between.

time for bed... good night.

Reply With Quote
  #9  
Old August 30th, 2003, 06:26 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
If you want to have 6 columns (3 of each heading), you should use "6" as your modulus operation...

PHP Code:
 $i = ( int )0;  // Temporary counter

while ($row mysql_fetch_array($result){
   if (( 
$i ) == 0){
     echo(
"</tr><tr>");  // This ends the row and starts a new one
   
} else {
     echo(
"<td>Col Data</td>");
   }
   
$i++;



This will create a new row everytime your counter is a multiple of 6. I hope that clears up some of the confusion...
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Reply With Quote
  #10  
Old September 24th, 2003, 12:39 AM
lobos34 lobos34 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: San Francisco
Posts: 17 lobos34 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hey FrankieShakes

Thanks for the code it worked out great, and It only took me half a day to get it to work ( i'm such a newbe).

Half of an hour later:
oops sorry I have to take that back, it's not creating a new row. It only does one row across and stops there?

Last edited by lobos34 : September 24th, 2003 at 01:04 AM.

Reply With Quote
  #11  
Old September 24th, 2003, 06:50 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Did you print a "<tr>" before the while and a "</tr>" after it?

Reply With Quote
  #12  
Old September 25th, 2003, 12:45 AM
lobos34 lobos34 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: San Francisco
Posts: 17 lobos34 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
???????