Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Wish to show results in specific way
Old 06-04-2005, 05:26 PM Wish to show results in specific way
Skilled Talker

Posts: 79
Trades: 0
Hello

I'm just in the process of making a website for a guy selling art. The artworks etc are stored in a database and I'm using PHP/mySQL to access and show the results.

Normally, I'd just show the results vertically down the page, however, he would like the results to be 3 per line.

for example

PHP Code:
+-----------------+-----------------------+--------------+
|                          |                              |                       |
|          
entry 1   |          entry 2       |     entry 3     |
|                          |                              |                       |
|                          |                              |                       |
+------------------+---------------------+------------- --+ 
and then to go down the page like that, that is, 6 entries would be displayed in 2 rows of 3 entries as above

Does anyone have any helpful pointers for this? Some code would be helpful, to demonstrate. Otherwise, some keywords to search Google with.

Thanks in advance, all help is much appreciated
hamish
__________________

Please login or register to view this content. Registration is FREE
secure and fully automated computer data backup for small and medium sized companies.


Please login or register to view this content. Registration is FREE

Last edited by hamish; 06-04-2005 at 05:29 PM..
hamish is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-04-2005, 06:10 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
The mod operator will be helpful here.
Say you wanted to output this as a table, you would write code a bit like this:

PHP Code:

$result
=mysql_query("query here to get the pictures");

echo 
"<table><tr>";

$i 1;
while(
$row mysql_fetch_array($result)) {
  echo 
"<td>";
  echo
"<img src='".$row['theimage']."' alt= etc...";
  echo 
"</td>";
  if((
$i 3) == 0) echo "</tr><tr>";
  
$i++;
}

echo 
"</tr></table>"
The % operator is the mod or remainder operator, and returns the remainder of dividing one number by another - so 1 % 3 is 1 since 1 / 3 is 0 remainder 1.
38 % 3 = 2 since 38/3 = 12 remainder 2. This allows you to express the "start a new row every 3 pictures", since starting from 0 we have:
0%3=0
1%3=1
2%3=2
3%3=0 (3/3 = 1 rem 0)
4%3=1
etc...

zero comes around every 3, so we increment $i in the loop and when i%3==0 we print "</tr><tr>" to start a new row.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 06-05-2005, 12:08 PM
Skilled Talker

Posts: 79
Trades: 0
Thank you!

thank looks just like what I need!!!

I'll spend tomorrow doing htat, and get back to you. Thanks so much.

hamish
__________________

Please login or register to view this content. Registration is FREE
secure and fully automated computer data backup for small and medium sized companies.


Please login or register to view this content. Registration is FREE
hamish is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Wish to show results in specific way
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.12325 seconds with 12 queries