PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old October 16th, 2009, 10:37 PM
speckledapple speckledapple is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Sep 2009
Posts: 20 speckledapple User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 40 m 5 sec
Reputation Power: 0
Grabbing certain records in certain order

Hi, I am trying to figure out how to strip out records from my database in a way that is in order. For instance, column one of my table on the page will have products 1-5 while column two will have 6-10 and so on and so forth. But as you can see below my statement only takes into account all the records in the database. I need to break that up and whether its by having one statement do it all for each column or separate code for each column. As long as the result is what I am looking for. *Note I repeated the same product just to serve as an example of what I am trying to do. Thanks.

PHP Code:
<?
            $result
=mysql_query("SELECT * from products");
            while(
$row=mysql_fetch_array($result)){
        
?>
        <tr>
            <td><img src="<?=$row['picture']?>" />
                <b><?=$row['name']?></b><br />
                <?=$row['description']?><br />
                    Price:<big style="color:green">
                        $<?=$row['price']?></big><br /><br />
                    <input type="button" value="Add to Cart" onclick="addtocart(<?=$row['id']?>)" /></td>
            <td><img src="<?=$row['picture']?>" />
                <b><?=$row['name']?></b><br />
                <?=$row['description']?><br />
                    Price:<big style="color:green">
                        $<?=$row['price']?></big><br /><br />
                    <input type="button" value="Add to Cart" onclick="addtocart(<?=$row['id']?>)" /></td>
            <td><img src="<?=$row['picture']?>" />
                <b><?=$row['name']?></b><br />
                <?=$row['description']?><br />
                    Price:<big style="color:green">
                        $<?=$row['price']?></big><br /><br />
                    <input type="button" value="Add to Cart" onclick="addtocart(<?=$row['id']?>)" /></td>
            <td><img src="<?=$row['picture']?>" />
                <b><?=$row['name']?></b><br />
                <?=$row['description']?><br />
                    Price:<big style="color:green">
                        $<?=$row['price']?></big><br /><br />
                    <input type="button" value="Add to Cart" onclick="addtocart(<?=$row['id']?>)" /></td>
        </tr>
        <tr>
        <td><img src="<?=$row['picture']?>" />
                <b><?=$row['name']?></b><br />
                <?=$row['description']?><br />
                    Price:<big style="color:green">
                        $<?=$row['price']?></big><br /><br />
                    <input type="button" value="Add to Cart" onclick="addtocart(<?=$row['id']?>)" /></td>
            <td><img src="<?=$row['picture']?>" />
                <b><?=$row['name']?></b><br />
                <?=$row['description']?><br />
                    Price:<big style="color:green">
                        $<?=$row['price']?></big><br /><br />
                    <input type="button" value="Add to Cart" onclick="addtocart(<?=$row['id']?>)" /></td>
            <td><img src="<?=$row['picture']?>" />
                <b><?=$row['name']?></b><br />
                <?=$row['description']?><br />
                    Price:<big style="color:green">
                        $<?=$row['price']?></big><br /><br />
                    <input type="button" value="Add to Cart" onclick="addtocart(<?=$row['id']?>)" /></td>
            <td><img src="<?=$row['picture']?>" />
                <b><?=$row['name']?></b><br />
                <?=$row['description']?><br />
                    Price:<big style="color:green">
                        $<?=$row['price']?></big><br /><br />
                    <input type="button" value="Add to Cart" onclick="addtocart(<?=$row['id']?>)" /></td>
        </tr>
        <tr>
          <td><img src="<?=$row['picture']?>" />
                <b><?=$row['name']?></b><br />
                <?=$row['description']?><br />
                    Price:<big style="color:green">
                        $<?=$row['price']?></big><br /><br />
                    <input type="button" value="Add to Cart" onclick="addtocart(<?=$row['id']?>)" /></td>
            <td><img src="<?=$row['picture']?>" />
                <b><?=$row['name']?></b><br />
                <?=$row['description']?><br />
                    Price:<big style="color:green">
                        $<?=$row['price']?></big><br /><br />
                    <input type="button" value="Add to Cart" onclick="addtocart(<?=$row['id']?>)" /></td>
            <td><img src="<?=$row['picture']?>" />
                <b><?=$row['name']?></b><br />
                <?=$row['description']?><br />
                    Price:<big style="color:green">
                        $<?=$row['price']?></big><br /><br />
                    <input type="button" value="Add to Cart" onclick="addtocart(<?=$row['id']?>)" /></td>
            <td><img src="<?=$row['picture']?>" />
                <b><?=$row['name']?></b><br />
                <?=$row['description']?><br />
                    Price:<big style="color:green">
                        $<?=$row['price']?></big><br /><br />
                    <input type="button" value="Add to Cart" onclick="addtocart(<?=$row['id']?>)" /></td>
        </tr>
        <tr>
          <td><img src="<?=$row['picture']?>" />
                <b><?=$row['name']?></b><br />
                <?=$row['description']?><br />
                    Price:<big style="color:green">
                        $<?=$row['price']?></big><br /><br />
                    <input type="button" value="Add to Cart" onclick="addtocart(<?=$row['id']?>)" /></td>
            <td><img src="<?=$row['picture']?>" />
                <b><?=$row['name']?></b><br />
                <?=$row['description']?><br />
                    Price:<big style="color:green">
                        $<?=$row['price']?></big><br /><br />
                    <input type="button" value="Add to Cart" onclick="addtocart(<?=$row['id']?>)" /></td>
            <td><img src="<?=$row['picture']?>" />
                <b><?=$row['name']?></b><br />
                <?=$row['description']?><br />
                    Price:<big style="color:green">
                        $<?=$row['price']?></big><br /><br />
                    <input type="button" value="Add to Cart" onclick="addtocart(<?=$row['id']?>)" /></td>
            <td><img src="<?=$row['picture']?>" />
                <b><?=$row['name']?></b><br />
                <?=$row['description']?><br />
                    Price:<big style="color:green">
                        $<?=$row['price']?></big><br /><br />
                    <input type="button" value="Add to Cart" onclick="addtocart(<?=$row['id']?>)" /></td>
        </tr>
        <? ?>
        
    </table>

Reply With Quote
  #2  
Old October 16th, 2009, 11:28 PM
jamestrowbridge jamestrowbridge is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2008
Location: Cleveland, Ohio, USA
Posts: 411 jamestrowbridge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 18 h 54 m 24 sec
Reputation Power: 2
You could do something like this:

PHP Code:
<?php

$count
=1;

$result=mysql_query("SELECT * from products"); 
            while(
$row=mysql_fetch_array($result)){
if(
$count==1) {

echo 
"<tr><td>".$row['product']."</td>";
$count++;

} else if(
$count==2) {

echo 
"<td>".$row['product']."</td></tr>";
$count=1;

}

}

?>


I'd recommend that you put each DB column in a separate cell.
__________________
Sir, a desire of knowledge is the natural feeling of mankind; and every human being, whose mind is not debauched, will be willing to give all that he has to get knowledge.

Reply With Quote
  #3  
Old October 17th, 2009, 12:49 AM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
What I had to do long ago when I had multiple columns like this was do a table inside a table type of thing so the output was something like:
Code:
<table>
  <tr>
    <td>
      <table>
        <tr>
          <td>Item 1</td>
          <td>Item 2</td>
          <td>Item 3</td>
          <td>Item 4</td>
          <td>Item 5</td>
        </tr>
      </table>
    </td>
    <td>
      <table>
        <tr>
          <td>Item 6</td>
          <td>Item 7</td>
          <td>Item 8</td>
          <td>Item 9</td>
          <td>Item 10</td>
        </tr>
      </table>        
    </td>
  </tr>
</table>

Reply With Quote
  #4  
Old October 18th, 2009, 12:23 AM
speckledapple speckledapple is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Sep 2009
Posts: 20 speckledapple User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 40 m 5 sec
Reputation Power: 0
Quote:
Originally Posted by jamestrowbridge
You could do something like this:

PHP Code:
<?php

$count
=1;

$result=mysql_query("SELECT * from products"); 
            while(
$row=mysql_fetch_array($result)){
if(
$count==1) {

echo 
"<tr><td>".$row['product']."</td>";
$count++;

} else if(
$count==2) {

echo 
"<td>".$row['product']."</td></tr>";
$count=1;

}

}

?>


I'd recommend that you put each DB column in a separate cell.


I am not sure how to implement what you wrote. I think I understand the coding but how would the yield the result of putting different products in the columns?

Reply With Quote
  #5  
Old October 18th, 2009, 01:20 AM
jamestrowbridge jamestrowbridge is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2008
Location: Cleveland, Ohio, USA
Posts: 411 jamestrowbridge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 18 h 54 m 24 sec
Reputation Power: 2
PHP Code:
<?php 
//set count to 1
$count=1
//query DB
$result=mysql_query("SELECT * from products");  
            while(
$row=mysql_fetch_array($result)){
//If count is 1, then do the below- start row and display cell 1 (for column 1)
if($count==1) { 

?>
        <tr> 
            <td><img src="<?=$row['picture']?>" /> 
                <b><?=$row['name']?></b><br /> 
                <?=$row['description']?><br /> 
                    Price:<big style="color:green"> 
                        $<?=$row['price']?></big><br /><br /> 
                    <input type="button" value="Add to Cart" onclick="addtocart(<?=$row['id']?>)" /></td>
<?php
//add 1 to count to bring to 2
$count++; 
//if count is equal to 2, do the below (display cell two (for column two) and end the row
} else if($count==2) { 

?>
            <td><img src="<?=$row['picture']?>" /> 
                <b><?=$row['name']?></b><br /> 
                <?=$row['description']?><br /> 
                    Price:<big style="color:green"> 
                        $<?=$row['price']?></big><br /><br /> 
                    <input type="button" value="Add to Cart" onclick="addtocart(<?=$row['id']?>)" /></td></tr>

<?php
//reset count to 1 to start the process over
$count=1





?>


This should give you a table like this, each number is a product:
1 2
3 4
5 6
7 8
etc

if you want to put each item in a separate cell, just use Llama's example

Reply With Quote
  #6  
Old October 18th, 2009, 01:47 AM
jamestrowbridge jamestrowbridge is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2008
Location: Cleveland, Ohio, USA
Posts: 411 jamestrowbridge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 18 h 54 m 24 sec
Reputation Power: 2
See above, but if you are looking for newspaper style columns, you'll have to check out:
http://www.w3.org/TR/css3-multicol/

Which seems to be the most efficient way of doing it. Gives you (in theory) (if you do 3 columns):
1 6 11
2 7 12
3 8 13
4 9 14
5 10 15

Reply With Quote
  #7  
Old October 18th, 2009, 02:41 AM
speckledapple speckledapple is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Sep 2009
Posts: 20 speckledapple User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 40 m 5 sec
Reputation Power: 0
your methods great. Now i understand thank you!!

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Grabbing certain records in certain order


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek