vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   check my php/sql code pls.... (https://vborg.vbsupport.ru/showthread.php?t=284503)

qpurser 06-16-2012 01:07 PM

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>


kh99 06-16-2012 01:48 PM

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);

qpurser 06-16-2012 02:40 PM

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

kh99 06-16-2012 02:47 PM

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']);

qpurser 06-16-2012 03:18 PM

Quote:

Originally Posted by kh99 (Post 2340077)
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

kh99 06-16-2012 03:34 PM

Quote:

Originally Posted by qpurser (Post 2340090)
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.

qpurser 06-16-2012 05:02 PM

Quote:

Originally Posted by kh99 (Post 2340093)
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


All times are GMT. The time now is 10:06 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.01041 seconds
  • Memory Usage 1,736KB
  • 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
  • (3)bbcode_code_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)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