icon Get the most out of Surmunity, read our tips here! Need an interesting blog to read? You've got to read the Surpass Blog! | Welcome! Please register to access all of our features.

» Surpass Web Hosting Forums » Discussions » PHP, MySQL » Need some help here please!!!

PHP, MySQL General PHP questions. Or go to our PHPsuexec Forum >>

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread
Old October 23rd, 2004, 10:09 AM   #1 (permalink)
Registered User
Comfy Contributor
 
blaze's Avatar
 
Joined in Aug 2004
Lives in Las Vegas
Hosted on pass11, pass12
187 posts
Gave thanks: 0
Thanked 0 times
Need some help here please!!!

Hi everyone. I currently have two problems.

1) I am using a featured ad script that displays data results on the home page. I am stuck in figuring out how to wrap those results after a certain number of results. These results are thumbnail images.

I want to wrap these thumbnails after 6 images, so it automatically creates a new row of thumbnails, etc. Here is an example for what I would like to achieve:



How can I achieve this? Here is the code.

PHP Code:
<?php

# Get params
$count intval$params->get'count') );
$direction $params->get'direction''vertical' );

# Get total number of published featured items
$database->setQuery"SELECT COUNT(*) AS total FROM #__hp_properties AS p"
    
"\nLEFT JOIN #__hp_prop_types AS t ON t.id=p.type"
    
.    "\nWHERE p.published=1 AND p.approved=1 AND t.published=1"
    
"\n AND p.featured=1"
    
"\n    AND (publish_up = '0000-00-00 00:00:00' OR publish_up <= NOW())"
    
"\n    AND (publish_down = '0000-00-00 00:00:00' OR publish_down >= NOW())");
$total $database->loadResult();

# Get Itemid, determine if the HP component is published
$database->setQuery("SELECT id FROM #__menu"
    
.    "\nWHERE link='index.php?option=com_hotproperty'"
    
.    "\nLIMIT 1");
$Itemid $database->loadResult();

# Get all featured property
$database->setQuery"SELECT p.* FROM #__hp_properties AS p"
        
"\nLEFT JOIN #__hp_prop_types AS t ON p.type = t.id"
        
"\nLEFT JOIN #__hp_featured AS f ON f.property = p.id"
        
"\nWHERE p.published='1' AND p.approved='1' AND t.published='1'"
        
"\n    AND (publish_up = '0000-00-00 00:00:00' OR publish_up <= NOW())"
        
"\n    AND (publish_down = '0000-00-00 00:00:00' OR publish_down >= NOW())"
        
.    "\nAND p.featured='1'"
        
"\nORDER BY f.ordering ASC"
        
"\nLIMIT 0, ".$count );
    
$featured $database->loadObjectList();
?>
<table cellpadding="1" cellspacing="1" border="0" width="100%">
<?php if ($direction == 'horizontal') echo "<tr>"?>
<?php 
foreach($featured AS $f) { 
    unset(
$thumb);
    
# Get the first thumbnail of the property
    
$database->setQuery"SELECT thumb, title FROM #__hp_photos"
        
"\nWHERE property='".$f->id."'"
        
"\nORDER BY ordering ASC"
        
"\nLIMIT 0,1");
    
$database->loadObject($thumb);

    if (
$thumb->thumb <> '') {
        
$thumb_imgsize GetImageSize ($mosConfig_absolute_path.$hp_imgdir_thumb.$thumb->thumb); 
    } else {
        
$thumb_imgsize GetImageSize ($mosConfig_absolute_path.$hp_imgdir_thumb.$hp_img_noimage_thumb); 
    }

?>
  <?php if ($direction == 'vertical') echo "<tr>"?><td align="center">
        <a href="
    <?php echo sefRelToAbs('index.php?option=com_hotproperty&task=view&id='.$f->id.'&Itemid='.$Itemid); ?>"><?php echo '<img '.$thumb_imgsize[3].' border="0" src="'.$mosConfig_live_site."/".$hp_imgdir_thumb.((!empty($thumb->thumb)) ? $thumb->thumb $hp_img_noimage_thumb).'" alt="'.$thumb->title.'">'?><br />
    <?php echo $f->name?></a></td><?php if ($direction == 'vertical') echo "</tr>"?>
 <?php ?>
<?php 
if ($direction == 'horizontal') echo "</tr>"?>
</table>

<?php if ($total $count) { 
echo 
'<a href="'
    
.    sefRelToAbs('index.php?option=com_hotproperty&task=viewfeatured&Itemid='.$Itemid)
    .    
'">'._HP_MOREFEATURED.'</a>';
?>

2) My second problem is allowing this script to choose the thumbs to be displayed at random. I have a random image script also used, but it can only show one image at a time. I would like to combine that random code with this featured ad code above. They are both similar in code, so I am sure this can be done -- I just do not know how to combine these two togther.

Here is the code for the random script:

PHP Code:
<?php

# Get Itemid, determine if the HP component is published
$database->setQuery("SELECT id FROM #__menu"
    
.    "\nWHERE link='index.php?option=com_hotproperty'"
    
.    "\nLIMIT 1");
$Itemid $database->loadResult();

# Get total of available properties with at least one thumbnail photo
$database->setQuery"SELECT DISTINCT p.name, p.id FROM #__hp_properties AS p"
        
"\nLEFT JOIN #__hp_prop_types AS t ON p.type = t.id"
        
"\nLEFT JOIN #__hp_featured AS f ON f.property = p.id"
        
"\nLEFT JOIN #__hp_photos AS photo ON photo.property = p.id"
        
"\nWHERE p.published='1' AND p.approved='1' AND t.published='1'"
        
.    "\n AND photo.id >= 0"
        
"\n    AND (publish_up = '0000-00-00 00:00:00' OR publish_up <= NOW())"
        
"\n    AND (publish_down = '0000-00-00 00:00:00' OR publish_down >= NOW())"
        
.    "\n GROUP BY photo.property");

$properties $database->loadObjectList();

$total count($properties);

global 
$id$option$task;

# Select a random number. Select again if the random number returns the same property, user is viewing
do {
    
# Seed and get the random number
    
srand((double)microtime()*88101967);
    
$choose rand(0,($total-1));
} while (
$option == "com_hotproperty" && $task == "view" && $id == $properties[$choose]->id && $total 1);

# Get the first thumbnail of the property
$database->setQuery"SELECT thumb, title FROM #__hp_photos"
    
"\nWHERE property='".$properties[$choose]->id."'"
    
"\nORDER BY ordering ASC"
    
"\nLIMIT 0,1");
$database->loadObject($thumb);

# Print
?><table cellpadding="1" cellspacing="1" border="0" width="100%">
<tr><td align="center">
<?php
echo '<a href="'
    
.    sefRelToAbs('index.php?option=com_hotproperty&task=view&id='.$properties[$choose]->id.'&Itemid='.$Itemid)
    .    
'">';
echo 
'<img border="0" src="'.$mosConfig_live_site."/".$hp_imgdir_thumb.(($thumb->thumb <> '') ? $thumb->thumb $hp_img_noimage_thumb).'" alt="'.$thumb->title.'">';
echo 
'<br />'.$properties[$choose]->name."</a>";
?>
</td></tr>
</table>
Thank you in advance!!!

-- BlaZe --
__________________
-- BlaZe --
............
blaze is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old October 23rd, 2004, 10:51 AM   #2 (permalink)
Surpass Fan
Comfy Contributor
 
pbflash's Avatar
 
Joined in Sep 2004
209 posts
Gave thanks: 0
Thanked 0 times
You don't need a seperate script to randomize them. Change the following:

# Get all featured property
$database->setQuery( "SELECT p.* FROM #__hp_properties AS p"
. "\nLEFT JOIN #__hp_prop_types AS t ON p.type = t.id"
. "\nLEFT JOIN #__hp_featured AS f ON f.property = p.id"
. "\nWHERE p.published='1' AND p.approved='1' AND t.published='1'"
. "\n AND (publish_up = '0000-00-00 00:00:00' OR publish_up <= NOW())"
. "\n AND (publish_down = '0000-00-00 00:00:00' OR publish_down >= NOW())"
. "\nAND p.featured='1'"
. "\nORDER BY RAND"
. "\nLIMIT 0, ".$count );

This should randomize the selections. I'll look at it a little more for your first problem.
__________________
Pass14
www.tqwebservices.com
www.autoappraisalsunlimited.com
www.clevelandlayne.com
Pass18
www.estateagency.com.au

Some people drink deeply from the fountain of knowledge. Others just gargle.
pbflash is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old October 23rd, 2004, 10:55 AM   #3 (permalink)
Surpass Fan
Comfy Contributor
 
pbflash's Avatar
 
Joined in Sep 2004
209 posts
Gave thanks: 0
Thanked 0 times
Also, this looks like part of a real estate script. Have you looked at Open-Realty? You can install it from the control panel and it's a pretty powerful program. I have done a lot of work with it and created some custom mods. Their support forums are great.

Demo Site:
http://www.open-realty.org/demo.html

Forums:
http://www.open-realty.org/support/
__________________
Pass14
www.tqwebservices.com
www.autoappraisalsunlimited.com
www.clevelandlayne.com
Pass18
www.estateagency.com.au

Some people drink deeply from the fountain of knowledge. Others just gargle.
pbflash is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old October 23rd, 2004, 11:11 AM   #4 (permalink)
Surpass Fan
Comfy Contributor
 
pbflash's Avatar
 
Joined in Sep 2004
209 posts
Gave thanks: 0
Thanked 0 times
Try this----Edited to change ordering.
PHP Code:
<?php 

# Get params 
$count intval$params->get'count') ); 
$direction $params->get'direction''vertical' ); 

# Get total number of published featured items 
$database->setQuery"SELECT COUNT(*) AS total FROM #__hp_properties AS p" 
    
"\nLEFT JOIN #__hp_prop_types AS t ON t.id=p.type" 
    
.    "\nWHERE p.published=1 AND p.approved=1 AND t.published=1" 
    
"\n AND p.featured=1" 
    
"\n    AND (publish_up = '0000-00-00 00:00:00' OR publish_up <= NOW())" 
    
"\n    AND (publish_down = '0000-00-00 00:00:00' OR publish_down >= NOW())"); 
$total $database->loadResult(); 
$num 1
# Get Itemid, determine if the HP component is published 
$database->setQuery("SELECT id FROM #__menu" 
    
.    "\nWHERE link='index.php?option=com_hotproperty'" 
    
.    "\nLIMIT 1"); 
$Itemid $database->loadResult(); 

# Get all featured property 
$database->setQuery"SELECT p.* FROM #__hp_properties AS p" 
        
"\nLEFT JOIN #__hp_prop_types AS t ON p.type = t.id" 
        
"\nLEFT JOIN #__hp_featured AS f ON f.property = p.id" 
        
"\nWHERE p.published='1' AND p.approved='1' AND t.published='1'" 
        
"\n    AND (publish_up = '0000-00-00 00:00:00' OR publish_up <= NOW())" 
        
"\n    AND (publish_down = '0000-00-00 00:00:00' OR publish_down >= NOW())" 
        
.    "\nAND p.featured='1'" 
        
"\nORDER BY f.ordering RAND"" 
        . "
nLIMIT 0".$count ); 
    $featured = $database->loadObjectList(); 
?> 
<table cellpadding="
1" cellspacing="1" border="0" width="100%"> 
<?php if ($direction == 'horizontal') echo "
<tr>"; ?> 
<?php foreach($featured AS $f) { 
    unset($thumb); 
    # Get the first thumbnail of the property 
    $database->setQuery( "
SELECT thumbtitle FROM #__hp_photos" 
        
"\nWHERE property='".$f->id."'" 
        
"\nORDER BY ordering ASC" 
        
"\nLIMIT 0,1"); 
    
$database->loadObject($thumb); 

    if (
$thumb->thumb <> '') { 
        
$thumb_imgsize GetImageSize ($mosConfig_absolute_path.$hp_imgdir_thumb.$thumb->thumb); 
    } else { 
        
$thumb_imgsize GetImageSize ($mosConfig_absolute_path.$hp_imgdir_thumb.$hp_img_noimage_thumb); 
    } 

?> 
    <?PHP if ($num == 6){
        echo 
'<br />';
        
$num 1}
    
?>    
  <?php if ($direction == 'vertical') echo "<tr>"?><td align="center"> 
        <a href=" 
    <?php echo sefRelToAbs('index.php?option=com_hotproperty&task=view&id='.$f->id.'&Itemid='.$Itemid); ?>"><?php echo '<img '.$thumb_imgsize[3].' border="0" src="'.$mosConfig_live_site."/".$hp_imgdir_thumb.((!empty($thumb->thumb)) ? $thumb->thumb $hp_img_noimage_thumb).'" alt="'.$thumb->title.'">'?><br /> 
    <?php echo $f->name?></a></td><?php if ($direction == 'vertical') echo "</tr>"?> 
<?php ?> 
<?php if ($direction == 'horizontal') echo "</tr>"?> 
</table> 

<?php if ($total $count) { 
echo 
'<a href="' 
    
.    sefRelToAbs('index.php?option=com_hotproperty&task=viewfeatured&Itemid='.$Itemid
    .    
'">'._HP_MOREFEATURED.'</a>'
    
$num $num 1
?>
I had no way to test it so if it doesn't work let me know what kind of errors you get.
__________________
Pass14
www.tqwebservices.com
www.autoappraisalsunlimited.com
www.clevelandlayne.com
Pass18
www.estateagency.com.au

Some people drink deeply from the fountain of knowledge. Others just gargle.

Last edited by pbflash; October 23rd, 2004 at 11:25 AM..
pbflash is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old October 23rd, 2004, 11:11 AM   #5 (permalink)
Registered User
Comfy Contributor
 
blaze's Avatar
 
Joined in Aug 2004
Lives in Las Vegas
Hosted on pass11, pass12
187 posts
Gave thanks: 0
Thanked 0 times
Quote:
Originally Posted by pbflash
You don't need a seperate script to randomize them. Change the following:

# Get all featured property
$database->setQuery( "SELECT p.* FROM #__hp_properties AS p"
. "\nLEFT JOIN #__hp_prop_types AS t ON p.type = t.id"
. "\nLEFT JOIN #__hp_featured AS f ON f.property = p.id"
. "\nWHERE p.published='1' AND p.approved='1' AND t.published='1'"
. "\n AND (publish_up = '0000-00-00 00:00:00' OR publish_up <= NOW())"
. "\n AND (publish_down = '0000-00-00 00:00:00' OR publish_down >= NOW())"
. "\nAND p.featured='1'"
. "\nORDER BY RAND"
. "\nLIMIT 0, ".$count );

Well, I appreciate the help -- but that doesn't appear to work. I get a few errors:

Notice: Unknown column 'RAND' in 'order clause' in /home/*****/public_html/*****/database.php on line 184

Warning: Invalid argument supplied for foreach() in /home/*****/public_html/*****/mod_hp_featuredprop_wpic.php on line 56

Any other suggestions??? Oh, and yes, this is a real estate script -- but it is far better than Open-realty and is a Component for Mambo.
__________________
-- BlaZe --
............
blaze is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old October 23rd, 2004, 11:16 AM   #6 (permalink)
Surpass Fan
Comfy Contributor
 
pbflash's Avatar
 
Joined in Sep 2004
209 posts
Gave thanks: 0
Thanked 0 times
Try me last post. I edited to change the ordering value.
__________________
Pass14
www.tqwebservices.com
www.autoappraisalsunlimited.com
www.clevelandlayne.com
Pass18
www.estateagency.com.au

Some people drink deeply from the fountain of knowledge. Others just gargle.
pbflash is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old October 23rd, 2004, 11:25 AM   #7 (permalink)
Surpass Fan
Comfy Contributor
 
pbflash's Avatar
 
Joined in Sep 2004
209 posts
Gave thanks: 0
Thanked 0 times
I edited it again. Forgot a semi-colon.
__________________
Pass14
www.tqwebservices.com
www.autoappraisalsunlimited.com
www.clevelandlayne.com
Pass18
www.estateagency.com.au

Some people drink deeply from the fountain of knowledge. Others just gargle.
pbflash is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old October 23rd, 2004, 11:32 AM   #8 (permalink)
Registered User
Comfy Contributor
 
blaze's Avatar
 
Joined in Aug 2004
Lives in Las Vegas
Hosted on pass11, pass12
187 posts
Gave thanks: 0
Thanked 0 times
Well, I pasted your coding in place of the original and I get this error:

Parse error: parse error, unexpected T_VARIABLE in /home/*****/public_html/modules/mod_hp_featuredprop_wpic.php on line 37

I have copied all the coding this time so you can see the line error as it is in the php file. The line error is:

$database->setQuery("SELECT id FROM #__menu"

PHP Code:
<?php

/**
* Hot Property's Featured Property Module with Pictures
*
* [at]package Hot Property 0.9
* [at]copyright (C) 2004 Lee Cher Yeong
* [at]url [url]http://www.Mosets.com/[/url]
* [at]author Lee Cher Yeong <cy[at]mosets.com>
**/

defined'_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

# Include the config file
require( $mosConfig_absolute_path.'/administrator/components/com_hotproperty/config.hotproperty.php' );

# Include the language file. Default is English
if ($hp_language=='') {
    
$hp_language='english';
}
include_once(
'components/com_hotproperty/language/'.$hp_language.'.php');

# Get params 
$count intval$params->get'count') ); 
$direction $params->get'direction''vertical' ); 

# Get total number of published featured items 
$database->setQuery"SELECT COUNT(*) AS total FROM #__hp_properties AS p" 
    
"\nLEFT JOIN #__hp_prop_types AS t ON t.id=p.type" 
    
.    "\nWHERE p.published=1 AND p.approved=1 AND t.published=1" 
    
"\n AND p.featured=1" 
    
"\n    AND (publish_up = '0000-00-00 00:00:00' OR publish_up <= NOW())" 
    
"\n    AND (publish_down = '0000-00-00 00:00:00' OR publish_down >= NOW())"); 
$total $database->loadResult(); 
$num 
# Get Itemid, determine if the HP component is published 
$database->setQuery("SELECT id FROM #__menu" 
    
.    "\nWHERE link='index.php?option=com_hotproperty'" 
    
.    "\nLIMIT 1"); 
$Itemid $database->loadResult(); 

# Get all featured property 
$database->setQuery"SELECT p.* FROM #__hp_properties AS p" 
        
"\nLEFT JOIN #__hp_prop_types AS t ON p.type = t.id" 
        
"\nLEFT JOIN #__hp_featured AS f ON f.property = p.id" 
        
"\nWHERE p.published='1' AND p.approved='1' AND t.published='1'" 
        
"\n    AND (publish_up = '0000-00-00 00:00:00' OR publish_up <= NOW())" 
        
"\n    AND (publish_down = '0000-00-00 00:00:00' OR publish_down >= NOW())" 
        
.    "\nAND p.featured='1'" 
        
"\nORDER BY f.ordering RAND"" 
        . "
nLIMIT 0".$count ); 
    $featured = $database->loadObjectList(); 
?> 
<table cellpadding="
1" cellspacing="1" border="0" width="100%"> 
<?php if ($direction == 'horizontal') echo "
<tr>"; ?> 
<?php foreach($featured AS $f) { 
    unset($thumb); 
    # Get the first thumbnail of the property 
    $database->setQuery( "
SELECT thumbtitle FROM #__hp_photos" 
        
"\nWHERE property='".$f->id."'" 
        
"\nORDER BY ordering ASC" 
        
"\nLIMIT 0,1"); 
    
$database->loadObject($thumb); 

    if (
$thumb->thumb <> '') { 
        
$thumb_imgsize GetImageSize ($mosConfig_absolute_path.$hp_imgdir_thumb.$thumb->thumb); 
    } else { 
        
$thumb_imgsize GetImageSize ($mosConfig_absolute_path.$hp_imgdir_thumb.$hp_img_noimage_thumb); 
    } 

?> 
    <?PHP if ($num == 6){ 
        echo 
'<br />'
        
$num 1
    
?>     
  <?php if ($direction == 'vertical') echo "<tr>"?><td align="center"> 
        <a href=" 
    <?php echo sefRelToAbs('index.php?option=com_hotproperty&task=view&id='.$f->id.'&Itemid='.$Itemid); ?>"><?php echo '<img '.$thumb_imgsize[3].' border="0" src="'.$mosConfig_live_site."/".$hp_imgdir_thumb.((!empty($thumb->thumb)) ? $thumb->thumb $hp_img_noimage_thumb).'" alt="'.$thumb->title.'">'?><br /> 
    <?php echo $f->name?></a></td><?php if ($direction == 'vertical') echo "</tr>"?> 
<?php ?> 
<?php if ($direction == 'horizontal') echo "</tr>"?> 
</table> 

<?php if ($total $count) { 
echo 
'<a href="' 
    
.    sefRelToAbs('index.php?option=com_hotproperty&task=viewfeatured&Itemid='.$Itemid
    .    
'">'._HP_MOREFEATURED.'</a>'
    
$num $num 
?>
__________________
-- BlaZe --
............

Last edited by blaze; October 23rd, 2004 at 11:34 AM..
blaze is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote