Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Sep 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Regular Coder
    Join Date
    Apr 2004
    Location
    Los Angeles
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    New to the CF scene
    Join Date
    Sep 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    4xz
    4xz is offline
    Regular Coder
    Join Date
    Aug 2004
    Location
    localhost
    Posts
    163
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.

  • #5
    Regular Coder
    Join Date
    Apr 2004
    Location
    Los Angeles
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •