Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-07-2010, 01:12 AM
ragarcia87's Avatar
ragarcia87 ragarcia87 is offline
 
Join Date: Jun 2009
Location: Fort Smith
Posts: 65
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Help with if condition

Hello I have this array

PHP Code:
  if ( empty($array['thread_link']) ){
      
$array['thread_link'] = 0;
  } 
and it is defined by

PHP Code:
'thread' => $array['thread_link'], 
I am trying to create the condition

HTML Code:
	  <vb:if condition="$rep.thread != 0">
		<td  style="padding : 3px;"><a href="{$rep.thread}">View</a></td>
	  <vb:else />	
	    <td  style="padding : 3px;">n/a</td>
	 </vb:if>
but it doesnt work and only shows "n/a" on everyone where it should show a thread link for some.

is there another way i can say if $rep.thread doenst = 0 then show the thread link?
Reply With Quote
  #2  
Old 01-07-2010, 02:32 AM
BBR-APBT's Avatar
BBR-APBT BBR-APBT is offline
 
Join Date: Feb 2009
Location: Maryland
Posts: 946
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Where do you have $rep.thread defined in your code?

If your not sure if your variable is working try to use var_dump($var);
if it returns NULL you have a problem unless it is supposed to return NULL.
Reply With Quote
  #3  
Old 01-07-2010, 02:37 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You condition should be:
HTML Code:
<vb:if condition="$rep['thread'] != 0">
(Or maybe $thread['rep']?) But like BBR, I have no idea what that condition has to do with the other information you posted.
Reply With Quote
  #4  
Old 01-07-2010, 07:16 AM
consolegaming consolegaming is offline
 
Join Date: Jan 2007
Posts: 168
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think you need to provide more info than you have already. Is those first 2 sets of codes from plugins ye? And if so I presume you're trying to get that variable into the if statement ye?

I think it all depends on how this $rep['thread'] or $rep.thread is defined. If you're trying to define it inside a plugin then it needs to be registered or pre-registered (if used in an existing template). And then the format for using the variable (outside of the if statements as if statements are different) would be more like {vb:raw $rep.thread} (for your a href link.

But yeah for the if statement you cant use the same format. You do it the same way as you would use to. So yeah what Lynne suggested should be what you need for the if statement. Though it would still need to be registered inside the plugin. There's a few good vb4 articles which shoudl help:

https://vborg.vbsupport.ru/showthread.php?t=228078
https://vborg.vbsupport.ru/showthread.php?t=231525
Reply With Quote
  #5  
Old 01-07-2010, 12:35 PM
ragarcia87's Avatar
ragarcia87 ragarcia87 is offline
 
Join Date: Jun 2009
Location: Fort Smith
Posts: 65
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am sorry. Thank you consolegaming for the links I am reading them now. Oh yes I have seen these. Thanks though.

Here is the page, view_rep.php

PHP Code:
<?php
/**
 *@todo clean up
 */

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################

define('THIS_SCRIPT''view_rep');
define('CSRF_PROTECTION'true);  
// change this depending on your filename

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array('view_userrep',
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/path/to/your/forums');
require_once('./global.php');

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################


// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle 'Viewing rep';
global 
$vbulletin;
$vbulletin->input->clean_array_gpc('g', array('userid' => TYPE_INT)); 
$db $vbulletin->db;

$UserID $vbulletin->GPC['userid'];
// Get username
$UserResult $db->query_read("SELECT username FROM user WHERE userid = {$UserID} LIMIT 1"); 
$Username current($db->fetch_array($UserResult)); // No need for array to cached in php since it only has one value.
  

$result $db->query_read("SELECT repping_userid,rep_value,message,reason,thread_link FROM userrep WHERE repped_userid = {$UserID} ORDER BY timestamp DESC"); 

$arRep = array();

while (
$array $db->fetch_array($result))
{
  
// this code sucks!
  
if ($array['rep_value'] == 1){
      
// Postive show + img
      
$RatedIMG "/images/pos-rep.png";
      
$RatedText "Postive";
  }
  elseif (
$array['rep_value'] == -1) {
      
// Negative show - img
      
$RatedIMG "/images/neg-rep.png";
      
$RatedText "Negative";
  }
 
  if ( empty(
$array['thread_link']) ){
      
$array['thread_link'] = 0;
  }
  

  
$UserLinkResult $db->query_read("SELECT username FROM user WHERE userid = {$array['repping_userid']} LIMIT 1"); // get a link to user who did the rating.
  
$arUsername =  $db->fetch_array($UserLinkResult);
  if ( empty(
$arUsername) ){
    
$strUsername "System"
    
$UserLink "/";
  }
  else{
    
$strUsername current($arUsername); // No need for array to cached in php since it only has one value.
    
$UserLink "/member.php?{$array['repping_userid']}-{$strUsername}";
  }
  
  
$arRep[] = array('ratedimg' => $RatedIMG,
           
'ratedtext' => $RatedText,
           
'message' => $array['message'],
           
'reason' => $array['reason'],
           
'thread' => $array['thread_link'],
           
'userlink' => $UserLink,
           
'username' => $strUsername);




// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######
$navbits construct_navbits(array("view_rep.php?$session[sessionurl]u={$UserID}=> $vbphrase['irep'],'' => $Username));
$navbar render_navbar_template($navbits);
$templater vB_Template::create('view_userrep');
$templater->register_page_templates();
$templater->register('navbar'$navbar);
$templater->register('reparray'$arRep);
$templater->register('username'$Username);
$templater->register('pagetitle'$pagetitle);
print_output($templater->render());

?>


And here is the whole template page: view_userrep

HTML Code:
{vb:stylevar htmldoctype}
<html xmlns="https://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}">
<head>
	<!-- no cache headers -->
	<meta http-equiv="Pragma" content="no-cache" />
	<meta http-equiv="Expires" content="-1" />
	<meta http-equiv="Cache-Control" content="no-cache" />
	<!-- end no cache headers -->
	{vb:raw headinclude}
	<title>{vb:raw pagetitle}</title>
</head>
<body>

{vb:raw header}
{vb:raw navbar}
    
    <div class="blockhead">{$username}'s iRep Profile</div>
    <div class="blockbody">
      <div class="blockrow">
	<table cellpadding="5" cellspacing="1" border="1" width="100%" style="border: 1px solid #333333;">
	  <tr>
	    <th width="10%" style="text-align: center; font-weight: bold;">From</th>
	    <th width="20" style="text-align: center; font-weight: bold;">Rating</th>
	    <th width="10%" style="text-align: center; font-weight: bold;">Reason</th>
	    <th width="10%" style="text-align: center; font-weight: bold;">Thread URL</th>
	    <th width="70%" style="text-align: center; font-weight: bold;">Comment</th>
	  </tr>
	<vb:each from="reparray" value="rep">
	  <tr>
	 
	    <vb:if condition="$rep.username">
	      <td  style="padding : 3px;"><a href="{vb:var rep.userlink}" title="{$rep.username} user profile">{$rep.username}</a></td>
	    <vb:else />
	      <td  style="padding : 3px;font-weight:bold;text-align:center;">System</td>
	    </vb:if> 
	    
	    
	    <td style="text-align: center;"><img src="{vb:var rep.ratedimg}" alt="{vb:var rep.ratedtext}" /></td>
	    <td style="padding : 3px;">{vb:var rep.reason}</td>
	    
	  <vb:if condition="$rep.thread != 0">
		<td  style="padding : 3px;"><a href="{$rep.thread}">View</a></td>
	  <vb:else />	
	    <td  style="padding : 3px;">n/a</td>
	 </vb:if>
	    
	    <td>{vb:var rep.message}</td>

	  </tr>
	</vb:each>
	</table>

      </div>
    </div>
    
    {vb:raw footer}
  </body>
</html>

If I change it to:
HTML Code:
	  <vb:if condition="$rep.thread">
		<td  style="padding : 3px;"><a href="{$rep.thread}">View</a></td>
	 </vb:if>
then it works and shows the thread link but some of them do not have values and need to show "n/a"
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:47 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03690 seconds
  • Memory Usage 2,254KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_html
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete