duffy832 Posted January 10, 2010 Share Posted January 10, 2010 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. Quote Link to comment Share on other sites More sharing options...
trq Posted January 10, 2010 Share Posted January 10, 2010 You might want to mention what template library it is your using as the idea of templates does not exist within native php. Quote Link to comment Share on other sites More sharing options...
duffy832 Posted January 10, 2010 Author Share Posted January 10, 2010 Sorry The template file is Profile.tpl and the PHP page it is sourcing is profile.php Quote Link to comment Share on other sites More sharing options...
trq Posted January 10, 2010 Share Posted January 10, 2010 Sorry, but that still doesn't help. Templates are not part of php, so you need to tell us what template library / engine you are using. Quote Link to comment Share on other sites More sharing options...
duffy832 Posted January 10, 2010 Author Share Posted January 10, 2010 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. Quote Link to comment Share on other sites More sharing options...
teamatomic Posted January 10, 2010 Share Posted January 10, 2010 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 Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 10, 2010 Share Posted January 10, 2010 agree with the below poster but also i want to add this is not a php template system... This current code is xml, php , and a database mate..... all that flash coding to just add a contact via there name, via there id in a link lol. Quote Link to comment Share on other sites More sharing options...
duffy832 Posted January 10, 2010 Author Share Posted January 10, 2010 Thanks for you help and feedback. I am quite new to this... I understand the concept but don't know the syntax well enough to know how to write that. If it wouldn't be too much trouble how would I write that check? Thanks again. Quote Link to comment Share on other sites More sharing options...
teamatomic Posted January 10, 2010 Share Posted January 10, 2010 ha-ha hee-hee Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.