Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-06-2004, 07:13 PM   PM User | #1
ivains
New to the CF scene

 
Join Date: Sep 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
ivains is an unknown quantity at this point
Info from Rows Into Columns

I'm stumped???

I got the columns going correctly. Let say I want to display the last 5 rows of information and I want it to display 3 columns per row. I get the columns; however, it displays only the very last row 5 times.

I think it has to do something with the way I'm calling up the query, but I'm not having any success.

Any suggestions would be gratefully appreciated.

Here is the query:



PHP Code:
$query="SELECT 
    t1.id, t1.obj_cat, t1.obj_title, t1.obj_publish, 
    t1.obj_pub_start, t1.obj_pub_stop, t2.img_id, t2.obj_img1, t3.cat_id, t3.cat_name 
FROM 
    #__estateagent_object AS t1    
    LEFT JOIN #__estateagent_images AS t2 ON t2.img_id=t1.id    
    LEFT JOIN #__estateagent_category AS t3 ON t3.cat_id=t1.obj_cat 
WHERE 
    ( 
        ( 
            ( 
                ( 
                    t1.obj_pub_start >= '0000-00-00 00:00:00' 
                    AND 
                    t1.obj_pub_start <= '$todate 23:59:59' 
                ) 
                AND 
                ( 
                    t1.obj_pub_stop <= '$todate 23:59:59' 
                    AND 
                    t1.obj_pub_stop >= '$todate 00:00:00' 
                ) 
            ) 
            OR 
            ( 
                ( 
                    t1.obj_pub_start >= '0000-00-00 00:00:00' 
                    AND 
                    t1.obj_pub_start <= '$todate 23:59:59' 
                ) 
                AND 
                t1.obj_pub_stop >= '$todate 23:59:59' 
            ) 
            OR 
            ( 
                t1.obj_pub_stop >= '$todate 00:00:00' 
                AND 
                t1.obj_pub_stop <= '$todate 23:59:59' 
            ) 
            OR 
            ( 
                t1.obj_pub_start = '0000-00-00 00:00:00' 
                AND 
                t1.obj_pub_stop = '0000-00-00 00:00:00' 
            ) 
        ) 
        AND 
            t1.obj_publish='1' 
    ) 
ORDER BY t1.id DESC LIMIT $HowMany"


# Query the database          
$database->setQuery$query ); 
$rows $database->loadObjectList(); 
$row=$rows[0]; 

Here is the column code:


PHP Code:
$b $HowMany// numbers to count for 
$i 0// incrementor 
$z $NumberOfCols// how many cols per row 

echo "<div align='$TableAlign'><table width='$TableWidth' border='$TableBorder' cellspacing='0' cellpadding='3'><tr>"

    while(
$i $b
        { 
            if(
$i == || $i == $a
                { 
                    echo 
"<tr>"
                    
$a $a $z// the beginning ist always $a + cols per row or zero 
                    
$e $a 1// the end ist always $a - 1 ; 
                    
if ($e $b// if the end ist geater then our count 
                        

                            
$e $b 1// we make $b - 1 and thats the end tag 
                        

                } 
                 
if(
$id != $row->img_id) { 
  
$sm_pic "<img src='".$picturepath."thmb_".$row->obj_img1."' border='0' alt='$row->obj_title'>";   
} else { 
  
$sm_pic "<img src='"$mosConfig_live_site."/components/com_estateagent/obj_pictures/nopic.png' border='0' alt='$row->obj_title'>";   


                echo 
"<td width='100%'> <a 
href='index.php?option=com_estateagent&Itemid=0&func=showObject&objid=$row->id'><b>$row->cat_name</b><br>$sm_pic<br><font 
size='1'>$row->obj_title</font></a> </td>"

              
            if (
$i == $e
                { 
                    echo 
"</tr>"
                } 
            
$i++; 
        } 

echo 
"</tr></table></div>"
__________________
Thanks
:) Ivan
ivains is offline   Reply With Quote
Old 10-07-2004, 02:12 AM   PM User | #2
Hawkmoon
Regular Coder

 
Join Date: Apr 2004
Location: Los Angeles
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Hawkmoon is an unknown quantity at this point
FYI (and I'm just trying to help) I think you might have a lot more luck with this post if you really narrowed the problem down and just posted a "little" bit of code.

For what it's worth,
-Hawkmoon
Hawkmoon is offline   Reply With Quote
Old 10-07-2004, 09:42 AM   PM User | #3
ivains
New to the CF scene

 
Join Date: Sep 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
ivains is an unknown quantity at this point
Quote:
FYI (and I'm just trying to help) I think you might have a lot more luck with this post if you really narrowed the problem down and just posted a "little" bit of code.

For what it's worth,
OK. I am trying to display my results in columns instead of rows. My table comes out OK, but only the last result is displayed in every column. So if my results are 'A', 'B', 'C' and I have 3 columns it comes out A A A vs A B C. I think it has something to do with the way I am calling it up from this code:

Code:
# Query the database           
$database->setQuery( $query );  
$rows = $database->loadObjectList();  
$row=$rows[0];
Any help with the code will be gratefully appreciated.

I hope I did better this time???
__________________
Thanks
:) Ivan
ivains is offline   Reply With Quote
Old 10-07-2004, 02:26 PM   PM User | #4
4xz
Regular Coder

 
Join Date: Aug 2004
Location: localhost
Posts: 163
Thanks: 0
Thanked 1 Time in 1 Post
4xz is an unknown quantity at this point
Dunno why, but I have a feeling your problem is this line:

Code:
$row=$rows[0];
Don't know what
Code:
$database->loadObjectList();
returns tho, so hard to figure.
4xz is offline   Reply With Quote
Old 10-08-2004, 07:10 AM   PM User | #5
Hawkmoon
Regular Coder

 
Join Date: Apr 2004
Location: Los Angeles
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Hawkmoon is an unknown quantity at this point
Way Better

It looks like you are missing some loop mechanism

Let's say $database->loadObjectList(); returns an array with the values "A","B","C"

Then your code would need to read as follows:
Code:
$rows = $database->loadObjectList();
foreach($rows as $key=>$letter) {
  echo("rows[" . $key . "]=" . $letter . "<br>"); 
}
//This would output:
//rows[0]=A
//rows[1]=B
//rows[2]=C
The other possibility is that you keep calling $rows[0] and the array key doesn't change...in which case you would just keep getting "A"
Example:
Code:
$row = $row[0];
echo($row) //Will always return just "A"

//However:
$letterA = $row[0];
$letterB = $row[1];
$letterC = $row[2];

echo("$letterA,$letterB,$letterC");  //Will return "A,B,C"
Let me know how it goes.

-Hawkmoon
Hawkmoon is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:28 AM.


Advertisement
Log in to turn off these ads.