Jump to content

PHP template help


duffy832

Recommended Posts

Ok, I don't know if anyone can help me but I am using PHP templates to make a site. I am a newbie and so I am finding this quite difficult so I thought I would ask some folks much better than me.

 

I have two pages at work here; profile.tpl and profile.php.

 

The profile page has <Zone> tags in it. I am attempting to pulll a list of contacts from the database and display the picture and user information. This part works fine.

 

The part I am having trouble with is displaying a different zone if there are no users to associated with the current profile.

 

I am using a if statement to do this (I did not write this if statement so forgive my ignorance about how it works) and I want an else to take place if there is no contacts that will display an alternative zone.

 

This is the code from the profile template page:

 

<ZONE contactsTab enabled>

                    <div class="dashContent">

                    <LOOP contactEntity>

                          <div style="float:left;">

                            <a href="?L=users.profile&id={contact.id}">

                              <img src="system/image.php?file={contact.mainpicture}" alt="[Picture {150}]" hspace="2" border="0" id="picture" /></a>

                            <br />

                            <a href="?L=users.profile&id={contact.id}">{contact.username}</a></div>

                  </LOOP contactEntity>

               

                        <ZONE addtocontactstab enabled>

                        <a href="?L=contacts.adduser&id={user.id}">[Add {user.username} to my contacts list {8225}]</a>

                      </ZONE addtocontactstab enabled>

                    <div class="clear"></div>

                    </div>

                </ZONE  contactsTab enabled>

               

                <ZONE contacts disabled>

                <div>This user does not have any contacts at this time.</div>

                </ZONE>

 

This is the code from the supporting PHP page:

 

$userContactsArray = unpk(_fnc("user", $_GET["id"], "contacts"));

 

$i=0;

 

 

if (is_array($userContactsArray)) foreach($userContactsArray as $userContactGroup => $contactsUsersArray) {

 

 

if (is_array($contactsUsersArray)) foreach($contactsUsersArray as $contactsUserID) {

 

 

$thirdUserContactsArray = unpk(_fnc("user", $contactsUserID, "contacts"));

 

 

if (is_array($thirdUserContactsArray) && _fnc("in_multiarray", $thirdUserContactsArray, $_GET["id"])) {

 

 

if ($i==0) $tpl->Zone("contactsTab", "enabled");

 

 

 

$contactEntityArray[$i]["contact.username"] = _fnc("user", $contactsUserID, "username");

$contactEntityArray[$i]["contact.id"] = $contactsUserID;

$contactEntityArray[$i]["contact.mainpicture"] = _fnc("user", $contactsUserID, "mainpicture");

 

$i++;

 

}

}

 

 

}

 

else $tpl ->Zone("contacts", "disabled");

 

 

if (isset($contactEntityArray)) $tpl -> Loop("contactEntity", $contactEntityArray);

 

Any help solving this would be more greatly appreciated.

 

I am at your mercy.

Link to comment
Share on other sites

I downloaded PHPizabi to create a simple social network.

 

In this engine <ZONE> tags are used to slug in information. I assume this tpl extension is unique to this engine.

 

I think I understand how to make the <ZONE> tag work in the template what I don't know is how the IF statement in the PHP works. I seems to check if there is anything in the contacts field in the database. If there is it loops through them loading the picture and the user information on the page.

 

If there is no content in the contact field it shows the temp profile image and {contac.username} instead of nothing and I think it's because there is no else statement but I don't know how to write that.

 

Of course I could be wrong.

 

Link to comment
Share on other sites

check for $userContactsArray being an array // $userContactsArray is an array of arrays

 

foreach grouping in the array it loops through each group as a user

 

makes array $thirdUserContactsArray

 

makes the username-ID-picture of the count($i) into the above array

 

increases the count($i++)

 

loop through again until it runs out of array data populating the $contactEntityArray

 

ELSE

refer to the first line in my reply. if its empty the contacts are disabled

//

IF

the array $contactEntityArray is not empty

it loops through it populating the template

 

...or something close to that

 

 

HTH

Teamatomic

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.