/    Sign up×
Community /Pin to ProfileBookmark

Problem Displaying Mult Columns…

Hi Everyone,

Im writing a module to display the last property entries from the db. I got it to work vertically with no problem, but when I change the parameter to display it horizontal I get the following:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in X:wampserverwwwXXXXXmodulesmod_ea_latestpic.php on line 114.

This is Line 114:

[CODE]$count = mysql_num_rows($query); [/CODE]

It also only displays the last entry only, no matter if I have it set to display 2, 3, 4 etc.

This is my entire code:

[code=php]
# Module Parameter Settings
$HowMany = @$params->HowMany ? $params->HowMany : ‘5’;
$Alignment = @$params->Alignment ? $params->Alignment : ‘1’;
$LineColor1 = @$params->LineColor1 ? $params->LineColor1 : ‘#FFFFFF’;
$LineColor2 = @$params->LineColor2 ? $params->LineColor2 : ‘#EBE7E7’;
$NumberOfCols = @$params->NumberOfCols ? $params->NumberOfCols : ‘4’;
$ColumnWidth = @$params->ColumnWidth ? $params->ColumnWidth : ‘25%’;

### DONT EDIT BELOW THIS LINE #################################################

# Set path to thumbnails
$picturepath = $mosConfig_live_site.$ea_picpath.”/”;

$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];

# Put the output on screen for Vertical Alignment

if ($Alignment == ‘1’) {

foreach($rows as $row) {

$content .= “<center><a href=’index.php?option=com_estateagent&Itemid=0&func=showObject&objid=$row->id’><b>$row->cat_name</b><br>”;

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’>”;
}

$content .= “$sm_pic”;

$content .= “<br><font size=’1′>$row->obj_title</font></a></center><br>”;

}
}

# Put the output on screen for Horizontal Alignment

if ($Alignment == ‘2’) {

$content .=”<div align=’center’><table width=’100%’ border=’1′ cellspacing=’2′ cellpadding=’0′><tr>”;

$count = mysql_num_rows($query);

for($i=0; $i<$count; $i++)
{
$r = mysql_fetch_array($query);
$id=$r[“id”];
$obj_cat=$r[“obj_cat”];
$obj_title=$r[“obj_title”];
$obj_publish=$r[“obj_publish”];
$obj_pub_start=$r[“obj_pub_start”];
$obj_pub_stop=$r[“obj_pub_stop”];
$img_id=$r[“img_id”];
$obj_img1=$r[“obj_img1”];
$cat_id=$r[“cat_id”];
$cat_name=$r[“cat_name”];
}
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’>”;
}

$content .=”<td
align=’center’ width=’$ColumnWidth’><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%3==2);

$content .=”</tr></table></div>”;

}
[/code]

Any help would be gratefully appreciated.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ivainsauthorSep 30.2004 — Ok I got my column problem resolved now my problem is its only picking up the very last property and displaying by the quantity I set in the parameter $HowMany. It might have something to do with the way I query my db, but I'm not sure.

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


This is what I changed in the parameters (Actually I added to make the table configurable:
[CODE]
# Module Parameter Settings
$HowMany = @$params->HowMany ? $params->HowMany : '5';
$Alignment = @$params->Alignment ? $params->Alignment : '1';
$TableWidth = @$params->TableWidth ? $params->TableWidth : '100%';
$TableBorder = @$params->TableBorder ? $params->TableBorder : '1';
$TCellSpacing = @$params->TCellSpacing ? $params->TCellSpacing : '2';
$TCellPadding = @$params->TCellPadding ? $params->TCellPadding : '0';
$TableAlign = @$params->TableAlign ? $params->TableAlign : 'center';
$NumberOfCols = @$params->NumberOfCols ? $params->NumberOfCols : '4';
$ColumnWidth = @$params->ColumnWidth ? $params->ColumnWidth : '25%';
[/CODE]


This is what I change in the script from a snipplet I found:
[CODE]
### Put the output on screen for Horizontal Alignment

if ($Alignment == '2') {

$b = $HowMany ; //numbers to count for
$i = 0; // incrementor
$z = $NumberOfCols; // how much cols ?

echo "<div align='$TableAlign'><table width='$TableWidth' border='$TableBorder' cellspacing='$TCellSpacing' cellpadding='$TCellPadding'>";

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='$ColumnWidth'> <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 "</table></div>";

}
[/CODE]


Any help would be gratefully appreciated...
Copy linkTweet thisAlerts:
@ivainsauthorOct 06.2004 — 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 that; however, it displays only the 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:

[code=php]
$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];
[/code]


Here is the column code:

[code=php]
$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>";

[/code]
×

Success!

Help @ivains spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...