|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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:
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 |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
Whatever you want output in horizontally you will need to put between the:
<td> </td> |
|
#5
|
|||
|
|||
|
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:
So exactly where in between your <td></td> tags should I put it? Thanks again ******* |
|
#6
|
|||
|
|||
|
Replace my print statements with yours.
|
|
#7
|
|||
|
|||
|
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:
Thanks |
|
#8
|
|||
|
|||
|
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. |
|
#9
|
|||
|
|||
|
If you want to have 6 columns (3 of each heading), you should use "6" as your modulus operation...
PHP Code:
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 |
|
#10
|
|||
|
|||
|
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. |
|
#11
|
||||
|
||||
|
Did you print a "<tr>" before the while and a "</tr>" after it?
|
|
#12
|
|||
|
|||
|
???????
|