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 06-16-2012, 01:07 PM
qpurser qpurser is offline
 
Join Date: Jul 2011
Posts: 275
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default check my php/sql code pls....

Just started to play around with php and sql stuff but don't feel that comfortable with it yet.
I am trying to create a custom page with a member list on the fly. Our member list changes almost every 2 weeks and I wanted my users to be able to get an actual member list without me having to create one every time and post it somewhere.
I tried my coding as below out and works pretty well.
However I wanted to be sure I didn't forget anything that mitt use a lot of server resources. For example do I have to clear the sql request after the page is created? If so how do I do that.

Also I would like to add the "join date" field next to the username. When I just put in "join date" I get just that numeric number from the DB. How do I convert it to a readable date?

Thanks for any help or suggestions

Code:
<table width="100%" cellspacing="3" cellpadding="20">
<center><b><u><font color=#855b63 size=6>Memberlist <center></b></u></font>
<br />
<br />

<?php



$result_q = $vbulletin->db->query_read("SELECT username, joindate FROM user
									   WHERE user.usergroupid <> '12' AND user.usergroupid = '9' AND user.membergroupids <> '13'
   AND user.membergroupids NOT LIKE '%12%' ORDER 
    BY user.username");


if ($vbulletin->db->num_rows($result_q) >0)

{
	
     $i = 0;
    $max_columns = 4;
	
     while ($result_r = $vbulletin->db->fetch_array($result_q))
	
    {
		
	    // make the variables easy to deal with
      // extract($row);
	

       // open row if counter is zero
       if($i == 0)
          echo "<tr>";	
		  if($result_q != "" && $result_q != null)
		  
          echo "<td><center><font color=#855b63 size=3>$result_r[username] <center></font></td>";
    
       // increment counter - if counter = max columns, reset counter and close row
       if(++$i == $max_columns) 
       {
           echo "</tr>";
           $i=0;
       }  // end if 
   } // end while
} // end if results

// clean up table - makes your code valid!
if($i < $max_columns)
{
    for($j=$i; $j<$max_columns;$j++)
        echo "<td>&nbsp;</td>";
}
 ?>
</tr>
<form><input type="button" value=" Print this page "
onclick="window.print();return false;" /></form>
</table>
Reply With Quote
  #2  
Old 06-16-2012, 01:48 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't think you have to worry about resources. If you're someone who likes to have everything cleaned up you could add $vbulletin->db->free_result($result_q), but I don't think it will make any difference.

As for the date, you can use the vbdate() function to format the value, like:

Code:
$datestr = vbdate($vbulletin->options['dateformat'], $joindate);
Reply With Quote
  #3  
Old 06-16-2012, 02:40 PM
qpurser qpurser is offline
 
Join Date: Jul 2011
Posts: 275
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thx for your quick help.
I tried to put the $datestr at several places in my script but no luck finding where to put it.
When I put it below the first "if" statement the it kinda worked but everybody had the same join date in the list.

Where should I put it?

thx again
Reply With Quote
  #4  
Old 06-16-2012, 02:47 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You'd want the $datestr line to be after the while() but before it's displayed (of course). I just meant to post an example, but I guess I should have just used the actual join date from the row you're reading:


Code:
$datestr = vbdate($vbulletin->options['dateformat'], $result_r['joindate']);
Reply With Quote
  #5  
Old 06-16-2012, 03:18 PM
qpurser qpurser is offline
 
Join Date: Jul 2011
Posts: 275
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
You'd want the $datestr line to be after the while() but before it's displayed (of course). I just meant to post an example, but I guess I should have just used the actual join date from the row you're reading:
You always should consider there are some very stupid people here who can't figure out things by themselves....

Just kidding with you.
Works great now.
Really appreciate your quick help
Reply With Quote
  #6  
Old 06-16-2012, 03:34 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by qpurser View Post
You always should consider there are some very stupid people here who can't figure out things by themselves....
lol, yeah, I wouldn't put it exactly like that, but sometimes it's difficult to know because the people posting vary from complete non-programmers trying to modify code to experts who tell me my answer is stupid (well, OK, that only happened once because most people aren't that rude). But in this case the code you needed was so close to what I posted that I can see it was confusing not to just post what you needed.


If you have a busy forum and you expect this page to be displayed a lot (and it's not constantly changing - and you don't need it to be instanly up to date), you could save the results in the datastore and only recalculate them periodically. But unless all that's true, or you just want to learn how to do it, it's probably not necessary.
Reply With Quote
  #7  
Old 06-16-2012, 05:02 PM
qpurser qpurser is offline
 
Join Date: Jul 2011
Posts: 275
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
If you have a busy forum and you expect this page to be displayed a lot (and it's not constantly changing - and you don't need it to be instanly up to date), you could save the results in the datastore and only recalculate them periodically. But unless all that's true, or you just want to learn how to do it, it's probably not necessary.
This is still chinese to me how to do that but a good hint.
Going to try to find some threads regarding this how to write my query into the datastore and retrieve it
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 12:50 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.04892 seconds
  • Memory Usage 2,222KB
  • 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
  • (3)bbcode_code
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)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