vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Random Number, if duplicate? (https://vborg.vbsupport.ru/showthread.php?t=107564)

Red Blaze 02-09-2006 07:26 PM

I wouldn't want to run into a problem if two albums have the same key.

Paul M 02-09-2006 07:28 PM

What problem exactly ?

Red Blaze 02-09-2006 07:30 PM

What I want is to filter the albums by a key. I just want one album per key. If two albums is to have the same key, both albums would be displayed. I do not want that. I want them to be displayed individually.

Paul M 02-09-2006 07:31 PM

Prefix it with the userid then.

Marco van Herwaarden 02-09-2006 07:33 PM

Use an autoincrement albumid as identification, the random key as password.

Red Blaze 02-09-2006 07:34 PM

Is it really THAT difficult to do? I'm not trying to find short cuts. I'm trying to learn more PHP.

Marco van Herwaarden 02-09-2006 07:42 PM

Well it is not difficult to do, just generate a number, check in the database if it is already used, and generate another number if it was in use.

We only trying to help you find the best solution to your problem.

Red Blaze 02-09-2006 07:52 PM

Well, Im trying to find out how to create that loop. Which I'd like to learn how it's done. Thanks for trying to help. -_-'

Marco van Herwaarden 02-09-2006 08:01 PM

Something like (not tested):
PHP Code:

while (!$newid)
{
    
$newid rand();
    
$existingid $vbulletin->db->query_read("SELECT albumid FROM " TABLE_PREFIX "myalbumtable
            WHERE albumid = 
$newid");
    
    
// Those the generated key already exist?
    
if ($existingid['albumid'] == $newid)
    {
        unset 
$newid;
    }



Paul M 02-09-2006 09:15 PM

Quote:

Originally Posted by Sonikku
Is it really THAT difficult to do? I'm not trying to find short cuts. I'm trying to learn more PHP.

It's not difficult, just pointless. If you want to learn then learn that you don't need to do some things. :)


All times are GMT. The time now is 06:12 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.02389 seconds
  • Memory Usage 1,728KB
  • 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
  • (1)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete