Jump to content

Need Help w/Functions


Grimloch

Recommended Posts

Hello again folks,

  I need some coding help. I am working with PHP-Fusion ver7 and am converting an old Fusion6 'Classified Ads' mod to work w/Fusion7. I am running MySQL5 and PHP5 on the server. The script displays categories and sub-categories w/ the # of ads in each one. Heres where I am:

 

1) I want to be able to display sub-cats w/the (parent main cat 'title') displayed ONCE for every group of (sub-cats 'under' that main cat). Here is an image of what it looks like now.

newSubcats.jpg

And here is the code that produces this output:

//Sub categories in new table
echo "<table width='100%' border='0' cellspacing='2' cellpadding='1'><tr><br />\n";
	echo "<td width='100%' align='center' class='tbl2'><strong><big><u>".$locale['CLS_0020']."</u></big></strong></td>\n";
	echo "</tr><tr>\n";
	echo "<td valign='top' width='100%'>";
	$result1 = dbquery("SELECT cid, title, description, image, parentid FROM ".DB_CLASSIFIED_CATEGORIES." WHERE status='1' AND  parentid >0 ORDER BY parentid LIMIT $frontcat");
		while(list($cid1, $title1, $description1, $image1, $parentid1) = dbarraynum($result1))
		{
	[color RED]  $title=getparentMain($parentid1,$title1);
echo "<strong><big><u>".$title."</u></big></strong>";  [END COLOR RED]
		$count2=dbcount("(*)", $db_prefix."classified", " cid='$cid1' AND status='1'");
		echo "<table cellspacing='2' cellpadding='2' width='100%' border='0'><tr>\n";
		echo "<td valign='middle'>";
		if($image1) {
		echo "<a href='".FUSION_SELF."?op=view_ad&cid=".$cid1."'><img src='".INFUSIONS."classified_ads_panel/images/cat/".$image1."' alt='".$title1."' border='0'></a>(<strong>".$count2." ";
		if($count2>1 || $count2<1) {
		echo $locale['CLS_0120'];
		} else {
		echo $locale['CLS_0119'];
		}
		echo "</strong>)";
		} else {
		echo "<a href='".FUSION_SELF."?op=view_ad&cid=".$cid."'><strong>".$title1."</strong></a>(<strong>".$count2." ";
		if($count2>1 || $count2<1) {
		echo $locale['CLS_0120'];
		} else {
		echo $locale['CLS_0119'];
		}
		echo "</strong>)";
		}
		echo "</td>\n";
		echo "</tr><tr>\n";
		echo "<td>".$description1."</td>\n";
		echo "</tr>\n</table>\n";
		}

 

The code in RED is the new code/function I created to GET just the parent/main category 'title' rather than the entire link which would be:

Main Cat/Sub-Cat ( # of ads )

 

This is the 'original function' code:

function getparent($parentid,$title) 
{
global $locale, $db_prefix, $userdata;
$result = dbquery("SELECT cid, title, parentid from ".DB_CLASSIFIED_CATEGORIES." WHERE cid=$parentid");
list($cid, $ptitle, $pparentid) = mysql_fetch_row($result);
mysql_free_result($result);
if ($ptitle!="") $title=$ptitle."/".$title;
if ($pparentid!=0) 
{
	$title=getparent($pparentid,$title);
}
    return $title;
}

 

And this is my 'new function' code:

function getparentMain($parentid,$title) 
{
global $locale, $db_prefix, $userdata;
$result = dbquery("SELECT cid, title, parentid from ".DB_CLASSIFIED_CATEGORIES." WHERE cid=$parentid");
list($cid, $ptitle, $pparentid) = mysql_fetch_row($result);
mysql_free_result($result);
if ($ptitle!="") $title=$ptitle;
if ($pparentid!=0) 
{
	$title=getparentMain($title);
}
    return $title;
}

 

This new function gives me what I want; just the main-cat 'title' but since the function has to appear inside the 'while loop' it gets that main-cat title every time thru the loop for every sub-cat title. This is what I need to display:

 

MAIN CAT1 TITLE

  Sub-Cat1 Title( 0 ads )

  Sub-Cat2 Title( 5 ads )

  Sub-Cat3 Title( 1 ad )

etc.etc.etc.....

 

MAIN CAT2 TITLE

  Sub-Cat1 Title( 0 ads )

  Sub-Cat2 Title( 5 ads )

  Sub-Cat3 Title( 1 ad )

etc.etc.etc.....

 

I also need to display the sub-cats in 2 colums instead of only one.

I hope this makes sense and that someone can point me in the right direction to go from here. I am fairly new at PHP and am trying to really get into and understand the inner workings of functions and how to handle their output.

Thanks... :D

Link to comment
Share on other sites

I also need to display the sub-cats in 2 colums instead of only one.

 

Well, I have figured out how to display categories and sub-categories in 2 colums instead of one, so I am making progress. Here is what it looks like now:

 

new2colCats.jpg

 

I 'AM' trying to work this out...

:)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.