...

View Full Version : Info from Rows Into Columns



ivains
10-06-2004, 08:13 PM
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:





$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:




$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 == 0 || $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>";

Hawkmoon
10-07-2004, 03:12 AM
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

ivains
10-07-2004, 10:42 AM
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:



# 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???

4xz
10-07-2004, 03:26 PM
Dunno why, but I have a feeling your problem is this line:


$row=$rows[0];

Don't know what

$database->loadObjectList();
returns tho, so hard to figure.

Hawkmoon
10-08-2004, 08:10 AM
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:


$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:


$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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum