vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   What's wrong with this code? (https://vborg.vbsupport.ru/showthread.php?t=68331)

Davey 08-14-2004 09:16 AM

What's wrong with this code?
 
Table coming up blank. Everything else was peachy.
I kind of troubleshot it down to roughly where it is, seems my fetch_template() calls aren't doing their job properly.
Called from DB, if my query wasn't successful, surely it'd have fetched the error template (no num_rows)
Anyway... the stuff.

File: guild.php
Incompleted.
PHP Code:

<?php

error_reporting
(E_ALL & ~E_NOTICE);

define('NO_REGISTER_GLOBALS'1);
define('THIS_SCRIPT''guild');

// precache templates used by all actions
$globaltemplates = array(
'members',
'treasury'
);

// precache templates used by specific actions
$actiontemplates = array(
    
'members' => array(
        
'guild_memberrow',
        
'guild_memberslist'
    
),
);

if (empty(
$_REQUEST['do']))
{
    
$_REQUEST['do'] = 'members';
}

require_once(
"./global.php");

if (
$_REQUEST['do'] == 'members')
{
    
// build the query
    
$memberlistquery $DB_site->query("
        SELECT *
        FROM " 
TABLE_PREFIX "user
        WHERE '8' IN (membergroupids)
        ORDER BY username ASC
    "
) or die("mysql error");
    
$endtemplate '';
    
// check if there are any members from this group
    
if ($DB_site->num_rows($memberlistquery) == '0')
    {
        eval(
'$endtemplate = "' fetch_template('guild_error_nomembers') . '";');
    }
    
// start getting the users
    
while ($memberlist $DB_site->fetch_array($memberlistquery))
    {
        eval(
'$endtemplate .= "' fetch_template('guild_memberrow') . '";');
    }
    
// done
    
$templatename 'guild_memberslist';

}

$navbits = array();
$navbits[$parent] = 'Guild Members';
$navbits construct_navbits($navbits);
eval(
'$navbar = "' fetch_template('navbar') . '";');
eval(
'print_output("' fetch_template($templatename) . '");');

?>

Template: guild_memberslist
Code:

$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
<title>$vboptions[bbtitle]</title>
$headinclude
</head>
<body>
$header

$navbar

<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<tr>
<td class="tcat" colspan="6" style="text-align: center; vertical-align: middle">
<strong>$vbphrase[guild_memberlist]</strong>
</td>
</tr>
<tr>
<td class="tcat" colspan="1" style="text-align: center; vertical-align: middle">
<strong>$vbphrase[guild_desc_username]</strong>
</td>
<td class="tcat" colspan="1" style="text-align: center; vertical-align: middle">
<strong>$vbphrase[guild_desc_rank]</strong>
</td>
<td class="tcat" colspan="1" style="text-align: center; vertical-align: middle">
<strong>$vbphrase[guild_desc_class]</strong>
</td>
<td class="tcat" colspan="1" style="text-align: center; vertical-align: middle">
<strong>$vbphrase[guild_desc_profession]</strong>
</td>
</tr>

$endtemplate

<tr>
<td class="tcat" colspan="7" style="text-align: center; vertical-align: middle">
<strong>$vbphrase[guild_memberlist]</strong>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>

$footer
</body>
</html>

Template: guild_memberrow
Code:

<tr>
<td style="text-align: center; vertical-align: middle">
<a href="member.php?u=$memberlist[userid]">$memberlist[musername]</a>
</td>
<td style="text-align: center; vertical-align: middle">
<if condition="$memberlist[field5]">
$memberlist[field5]
</if>
<if condition="!$memberlist[field5]">
Undisclosed.
</if>
</td>
<td style="text-align: center; vertical-align: middle">
<if condition="$memberlist[field6]">
$memberlist[field6]
</if>
<if condition="!$memberlist[field6]">
Undisclosed.
</if>
</td>
<td style="text-align: center; vertical-align: middle">
<if condition="$memberlist[field7]">
$memberlist[field7]
</if>
<if condition="!$memberlist[field7]">
Undisclosed.
</if>
</td>
</tr>

Template: guild_error_nomembers
Code:

<tr><td>There are no members in this group.</td></tr>
String: guild.php?do=members
Outcome: See attachment screenshot.

Colin F 08-14-2004 09:43 AM

It's probably not it, but you're missing <tr>'s around the two tcat rows.

Also, look in your database for how many rows should be returned.

CarCdr 08-14-2004 10:02 AM

If there are no rows retrieved, you will not see the error. Right after you set "$endtemplate" to the error message you set it to the empty string in the line:

$endtemplate = '';

Also, I would do the check for an empty $_REQUEST['do'] so that it is set before including global.php. This will allow it to pre-cache the $actiontemplates.

Finally, as Colin pointed out, I would fix your <TR>/<TD> tags before debugging much further.

Davey 08-14-2004 10:24 AM

OK well I did everything listed (check the code above).
The SQL in phpmyadmin returns 1 user (me)
I'm still getting nothing, not even an error message.
edit.-

Could it be I need something else included? Maybe I've set the $actiontemplates or $globaltemplates wrong? After all I don't understand what either do so I'm not sure if they're right or not.

Colin F 08-14-2004 10:40 AM

Try adding a $DB_site->data_seek(0,$memberlistquery); after the if(blabla =='0'){ bla }

Dean C 08-14-2004 11:03 AM

No wonder, put all this inside the if($_REQUEST['do']... bit:

PHP Code:

$navbits = array();
$navbits[$parent] = 'Guild Members';
$navbits construct_navbits($navbits);
eval(
'$navbar = "' fetch_template('navbar') . '";');
eval(
'print_output("' fetch_template($templatename) . '");'); 


Davey 08-14-2004 11:26 AM

@Dean C:
Are you sure??

The nav bits is nothing to do with listing the members.
It does output the page, it just doesn't output what it needs to.
If you look in the vBulletin 3 files, that is all at the bottom.

In the 'if($_REQUEST['do']...' bit, there is a bit at the end:

$templatename = 'template_name';//replace "template_name" with name of template.

@Colin F:
$test = $DB_site->data_seek(0,$memberlistquery);
echo $test;

Returns '1'.. (whatever that means, lol)

Davey 08-14-2004 11:30 AM

Oh and Dean, I did what you said...

PHP Code:

<?php

error_reporting
(E_ALL & ~E_NOTICE);

define('NO_REGISTER_GLOBALS'1);
define('THIS_SCRIPT''guild');

// precache templates used by all actions
$globaltemplates = array(
'members',
'treasury'
);

// precache templates used by specific actions
$actiontemplates = array(
    
'members' => array(
        
'guild_memberrow',
        
'guild_memberslist'
    
),
);

if (empty(
$_REQUEST['do']))
{
    
$_REQUEST['do'] = 'members';
}

require_once(
"./global.php");

if (
$_REQUEST['do'] == 'members')
{
    
// build the query
    /*
    SELECT * FROM vb3_user WHERE '8' IN (membergroupids) ORDER BY username ASC
    */
    
$memberlistquery $DB_site->query("
        SELECT *
        FROM " 
TABLE_PREFIX "user
        WHERE '8' IN (membergroupids)
        ORDER BY username ASC
    "
);
    
$endtemplate '';
    
// check if there are any members from this group
    
if ($DB_site->num_rows($memberlistquery) == '0')
    {
        eval(
'$endtemplate = "' fetch_template('guild_error_nomembers') . '";');
    }
    
// start getting the users
    
while ($memberlist $DB_site->fetch_array($memberlistquery))
    {
        eval(
'$endtemplate .= "' fetch_template('guild_memberrow') . '";');
    }
    
// done
    
$templatename 'guild_memberslist';

    
$navbits = array();
    
$navbits[$parent] = 'Guild Members';
    
$navbits construct_navbits($navbits);
    eval(
'$navbar = "' fetch_template('navbar') . '";');
    eval(
'print_output("' fetch_template($templatename) . '");');
}

?>

Still returns nothing but an empty table.

Dean C 08-14-2004 11:44 AM

Ok then debug it like so:

PHP Code:

error_reporting(E_ALL & ~E_NOTICE);

define('NO_REGISTER_GLOBALS'1);
define('THIS_SCRIPT''guild');

// precache templates used by all actions
$globaltemplates = array(
'members',
'treasury'
);

// precache templates used by specific actions
$actiontemplates = array(
    
'members' => array(
        
'guild_memberrow',
        
'guild_memberslist'
    
),
);

if (empty(
$_REQUEST['do']))
{
    
$_REQUEST['do'] = 'members';
}

require_once(
"./global.php");

if (
$_REQUEST['do'] == 'members')
{
    echo 
'one';
    
// build the query
    /*
    SELECT * FROM vb3_user WHERE '8' IN (membergroupids) ORDER BY username ASC
    */
    
$memberlistquery $DB_site->query("
        SELECT *
        FROM " 
TABLE_PREFIX "user
        WHERE '8' IN (membergroupids)
        ORDER BY username ASC
    "
);
    
$endtemplate '';
    
// check if there are any members from this group
    
if ($DB_site->num_rows($memberlistquery) == '0')
    {
        echo 
',two';
        eval(
'$endtemplate = "' fetch_template('guild_error_nomembers') . '";');
    }
    
// start getting the users
    
while ($memberlist $DB_site->fetch_array($memberlistquery))
    {
        echo 
',bits';
        eval(
'$endtemplate .= "' fetch_template('guild_memberrow') . '";');
    }
    
// done
    
$templatename 'guild_memberslist';

    
$navbits = array();
    
$navbits[$parent] = 'Guild Members';
    
$navbits construct_navbits($navbits);
    eval(
'$navbar = "' fetch_template('navbar') . '";');
    eval(
'print_output("' fetch_template($templatename) . '");');


What does it echo to the browser :)?

Davey 08-14-2004 11:53 AM

I didn't try that because I figured out the problem. I assume it would have echo()'ed "one" in the browser. :)
That bit is working fine.
Code:

<tr>
<td style="text-align: center; vertical-align: middle">
<a href="member.php?u=1">Davey</a>
</td>
<td style="text-align: center; vertical-align: middle">
Founder
</td>
<td style="text-align: center; vertical-align: middle">
Warrior
</td>
<td style="text-align: center; vertical-align: middle">
Carpentry
</td>
</tr>

The above works, displays fine. So this bug in my code is the $memberlist variable.

edit.- I have to eval() the $memberlist variable, no..?

Davey 08-14-2004 12:09 PM

I found the bug allright.
PHP Code:

while ($memberlist $DB_site->fetch_array($memberlistquery))
{
eval(
'$endtemplate .= "' fetch_template('guild_memberrow') . '";');
}
if (!
$memberlist['username'])
{
echo 
"something's wrong.";
}
// done
$templatename 'guild_memberslist'

See attachment.

Now how to fix that? lol

Dean C 08-14-2004 12:12 PM

Well i've no idea without looking at it fully. Are you not showing me some code? How does it output undisclosed?

Davey 08-14-2004 12:14 PM

I changed the templates to debug the <if> conditioning.
It'd look something like:

Code:

<td>
<if condition="$memberlist[field6]">
$memberlist[field6]
</if>
<if condition="!$memberlist[field6]">
Undisclosed.
</if>

edit.- That prooves that it's not <if> but it's the $memberlist fetched array which isn't doing as it should for whatever reason.

Dean C 08-14-2004 01:54 PM

You are going seriously wrong here ;) Where are you getting field6 from? You should be using the field username? Also if you're trying to get profile fields then you have to join the profilefield table (or whatever it is in vB3)

Davey 08-14-2004 02:32 PM

Code:

<tr>
<td style="text-align: center; vertical-align: middle">
<a href="member.php?u=$memberlist[userid]">$memberlist[musername]</a>
</td>
<td style="text-align: center; vertical-align: middle">
<if condition="$memberlist[field5]">
$memberlist[field5]
</if>
<if condition="!$memberlist[field5]">
Undisclosed.
</if>
</td>
<td style="text-align: center; vertical-align: middle">
<if condition="$memberlist[field6]">
$memberlist[field6]
</if>
<if condition="!$memberlist[field6]">
Undisclosed.
</if>
</td>
<td style="text-align: center; vertical-align: middle">
<if condition="$memberlist[field7]">
$memberlist[field7]
</if>
<if condition="!$memberlist[field7]">
Undisclosed.
</if>
</td>
</tr>

It's not returning anything, let alone the profile fields. Not that I understand JOIN'ing at all.
edit.- I've updated the code and templates in the first post.

Tigga 08-14-2004 04:31 PM

Try something like this instead:
PHP Code:

 $memberlistquery $DB_site->query(
SELECT user.*, userfield.*
FROM " 
TABLE_PREFIX "user AS user
LEFT JOIN " 
TABLE_PREFIX "userfield AS userfield USING (userid)
WHERE '8' IN (membergroupids) 
ORDER BY username ASC 
"
) or die("mysql error"); 


Davey 08-14-2004 06:26 PM

That didn't work any, still comes up blank.

Tigga 08-14-2004 06:37 PM

Try moving this part:

PHP Code:

if (empty($_REQUEST['do'])) 

    
$_REQUEST['do'] = 'members'


Below the call to global.php. It being above the call to global.php will create a problem... Other than that I don't see anything else wrong.

Davey 08-14-2004 06:44 PM

lol
Quote:

Originally Posted by CarCdr
Also, I would do the check for an empty $_REQUEST['do'] so that it is set before including global.php. This will allow it to pre-cache the $actiontemplates.

Who's right?
*confused*

Tigga 08-14-2004 06:51 PM

Keep that code below the call to global.php, then add this above to cache the templates:

$actiontemplates['none'] = &$actiontemplates['members'];

Davey 08-14-2004 06:58 PM

PHP Code:

$actiontemplates = array(
'members' => array(
'guild_memberrow',
'guild_memberslist'
),
);
$actiontemplates['none'] = &$actiontemplates['members']; 

Like that?

edit.- I still don't see why the fetch_array of $memberlist is causing it not to work properly. How come the problem is so obscure?

Davey 08-14-2004 10:03 PM

OK this is nothing to do with $DB_site.
This is something to do with the calling of $memberlist[value] in the templates.
Just check out the attachments.
edit.- So, what could be preventing the $memberlist[value] variable from doing its job? Is there something I missed out code-wise or a file or something I didn't require?

Tigga 08-14-2004 10:48 PM

Looks like the code you posted there is working just fine... To print out the additional fields you should just need to change the query back so that you're joining the userfield table. If it's still not working you may want to double check that field5,6 and 7 are the correct ones that you're trying to pull. And actually, it doesn't appear that those are... Are those hidden profile fields or something? From looking at the profiles on your site you don't even have any additional fields unless they're hidden from view.

Davey 08-14-2004 11:51 PM

They are hidden from view. Can you explain why the username isn't coming up in the first field? If what you said is true, at least the username should be showing up, no?

Tigga 08-14-2004 11:55 PM

You have $memberlist[musername] in your template. Remove the 'm' there and it will show the username. ;)

Davey 08-15-2004 12:54 AM

Nvm I was using vbindex and it was a bit of hassle to tell you the truth. I'm switching to your CMS tigga, I'll have to do everything manually that's all. :)
Thx for the support though everyone.


All times are GMT. The time now is 11:38 AM.

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.01482 seconds
  • Memory Usage 1,861KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (6)bbcode_code_printable
  • (8)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (26)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete