11 replies
I have a php scrip what allows to register and to login. My first problem:I need a piece of php script what will set the maximum number of users can register. I store the usernames , the passwords and an the number of the user (i mean 1 , 2 , ...). Another problem is want to create something like a map with little pieces of images. Each piece to have as background the image1 , I need a code what to add a piece from this "map" for every user when he registers randomly ( I mean the user with number one to get the piece with any number , else than one). And i need to use as background image2 for those pieces what are already taken. Any idea what i can do? I want to use php.

Sorry for my bad english!
#images #map #php
  • Profile picture of the author chaos69
    Originally Posted by coolboycsaba View Post

    I have a php scrip what allows to register and to login. My first problem:I need a piece of php script what will set the maximum number of users can register.
    I store the usernames , the passwords and an the number of the user (i mean 1 , 2 , ...).
    Its not good relying on the user number [which i assume is the pkey]. You should check if registration is open before allowing signup.

    This will return true if the current user count is less than the maximum number you allow. if true, allow signup, else notify user that registration is full.

    SELECT count(*)<MAX_USERS FROM your_user_table WHERE active is true;

    MAX_USERS should be the maximum number of users.
    your_user_table .... well, the table you store your users in.
    You may or may not have active so remove if not applicable.


    Another problem is want to create something like a map with little pieces of images. Each piece to have as background the image1 , I need a code what to add a piece from this "map" for every user when he registers randomly ( I mean the user with number one to get the piece with any number , else than one). And i need to use as background image2 for those pieces what are already taken. Any idea what i can do? I want to use php.
    Im not sure I follow what you are trying to achieve, can you give an example?
    Signature
    Best Ways To Make Money Online

    Eight bytes walk into a bar. The bartender asks, “Can I get you anything?”
    “Yeah,” reply the bytes. “Make us a double.”
    {{ DiscussionBoard.errors[1505202].message }}
  • Profile picture of the author coolboycsaba
    Thanks for chaos it was realy helpful!
    I need something like this:
    When somebody registers he will get randomly a piece from the "map". The pieces what are allready taken are in red , the free pieces are green.
    Signature
    {{ DiscussionBoard.errors[1505370].message }}
    • Profile picture of the author chaos69
      Ahhh right ok - that makes a LOT more sense now, thanks

      This should be quite simple actually but as with anything there are LOADS of ways to do this.

      Personally, I would create another table, for example 'map' that contains a key [1-25] and uid columns. The uid is a foreign key to the uid in the users table.

      To get a random key that isnt taken use this;

      SELECT `key` FROM `map` WHERE `uid` is null ORDER BY RAND() LIMIT 1;

      When you create a user, be sure to add an entry into the map table so that the userid is inserted alongside
      that key.

      Make sense?

      Later, if you need to get the users info along with their key;

      SELECT u.uid, u.name, m.key FROM users as u INNER JOIN map as m ON (u.uid=m.uid) WHERE u.uid = your user id

      If you need to display the map it should be very simple.

      You either make the map pieces in Gimp/photoshop first and use 2 for loops to display them as you have based on wether a user has that piece or not; You can select the entire map table and process this if the uid is null or not....

      Alternatively, do the same but use GD to draw each piece on the fly.
      Signature
      Best Ways To Make Money Online

      Eight bytes walk into a bar. The bartender asks, “Can I get you anything?”
      “Yeah,” reply the bytes. “Make us a double.”
      {{ DiscussionBoard.errors[1505448].message }}
  • Profile picture of the author coolboycsaba
    Thanks man !
    I`ve started learning php only this week so I know only the basics but thanks for your very useful answers !
    Signature
    {{ DiscussionBoard.errors[1505566].message }}
    • Profile picture of the author chaos69
      No problem.

      Feel free to shoot me a pm if you have any problems doing it or if you need any specific examples getting this to work.
      Signature
      Best Ways To Make Money Online

      Eight bytes walk into a bar. The bartender asks, “Can I get you anything?”
      “Yeah,” reply the bytes. “Make us a double.”
      {{ DiscussionBoard.errors[1505620].message }}
  • Profile picture of the author coolboycsaba
    I can`t send you pms because i have less than 50 posts. Hope you read this:d . I`m facing some problems doing this map.
    This should be quite simple actually but as with anything there are LOADS of ways to do this.

    Personally, I would create another table, for example 'map' that contains a key [1-25] and uid columns. The uid is a foreign key to the uid in the users table.

    To get a random key that isnt taken use this;

    SELECT `key` FROM `map` WHERE `uid` is null ORDER BY RAND() LIMIT 1;

    When you create a user, be sure to add an entry into the map table so that the userid is inserted alongside
    that key.

    Make sense?

    Later, if you need to get the users info along with their key;

    SELECT u.uid, u.name, m.key FROM users as u INNER JOIN map as m ON (u.uid=m.uid) WHERE u.uid = your user id

    If you need to display the map it should be very simple.

    You either make the map pieces in Gimp/photoshop first and use 2 for loops to display them as you have based on wether a user has that piece or not; You can select the entire map table and process this if the uid is null or not....
    Could you please write this more detailed?
    Signature
    {{ DiscussionBoard.errors[1512341].message }}
    • Profile picture of the author chaos69
      Originally Posted by coolboycsaba View Post

      I can`t send you pms because i have less than 50 posts. Hope you read this:d . I`m facing some problems doing this map.

      Could you please write this more detailed?
      Sure - do you mean the creating user part, or displaying the map?
      Signature
      Best Ways To Make Money Online

      Eight bytes walk into a bar. The bartender asks, “Can I get you anything?”
      “Yeah,” reply the bytes. “Make us a double.”
      {{ DiscussionBoard.errors[1513858].message }}
  • Profile picture of the author coolboycsaba
    My first problem is: Somehow I need first to generate the map, but i need a map with 10.000 pieces so i need a script to create it. I`m think the best is to generate a html table and to add a display:block link to each already taken piece linking to the user who owns that piece.
    2nd problem: The uid is the user id ? - and if it is i need to add the users id to the both tables (users and map) ?
    Signature
    {{ DiscussionBoard.errors[1513903].message }}
    • Profile picture of the author chaos69
      Originally Posted by coolboycsaba View Post

      My first problem is: Somehow I need first to generate the map, but i need a map with 10.000 pieces so i need a script to create it. I`m think the best is to generate a html table and to add a display:block link to each already taken piece linking to the user who owns that piece.

      hmmm.... 10k pieces? You might want to split that into seperate pages because it will take some time to generate. it depends how large they are really, but it might slow things down otherwise.....

      You can build a map with something like the following; [using 5x5 as per yuor example]

      index.php
      <html>
      <head>
      <title>map test 1</title>
      </head>
      <?php
      print "<table>";
      for($x=1; $x<6;$x++)
      {
      print "<tr>";
      for($y=1;$y<6;$y++)
      {
      print "<td>";
      $count=$y + (5*($x-1));

      # Here - you should check if the map number has been taken by a user and set the color accordingly.
      # I've used 12 and 17 as examples
      if($count == 12 or $count == 17) $color='red';
      else $color='green';

      print '<a href="link.to.your.users.page"><img src="imgt.php?color='.$color.'&num='.$count.'"></a>';
      print "</td>";
      }
      print "</tr>";
      }
      print "</table>";
      ?>

      </html>


      Then this to create the image......

      imgt.php
      <?php

      # You might want to check $_GET['color'] is a valid color etc first..... as with $_GET['num'] or if not set, display an error or
      # redirect to index page......

      $color=$_GET['color'];
      $im = ImageCreate(50,50);
      $white = ImageColorAllocate($im,0xFF,0xFF,0xFF);
      $black = ImageColorAllocate($im,0x00,0x00,0x00);
      $green = ImageColorAllocate($im,0x00,0xFF,0x00);;
      $red = ImageColorAllocate($im,0xFF,0x00,0x00);

      $font = 4;
      $width = ImageFontWidth($font) * strlen(
      $_GET['num']);
      $height = ImageFontHeight($font);

      ImageFilledRectangle($im,0,0,50,50,$$color);
      imagestring ($im, $font, 0, 0, $_GET['num'], $black);
      ImagePNG($im);

      ?>



      2nd problem: The uid is the user id ? - and if it is i need to add the users id to the both tables (users and map) ?
      Yah - insert the user into your user table first, assuming you have userid [or uid] as the pkey...... When you are done, then add it into the map table as well. You can use mysql_insert_id or such to get the previously added userid.
      Signature
      Best Ways To Make Money Online

      Eight bytes walk into a bar. The bartender asks, “Can I get you anything?”
      “Yeah,” reply the bytes. “Make us a double.”
      {{ DiscussionBoard.errors[1513923].message }}
  • Profile picture of the author coolboycsaba
    thanks man , your the best!
    Signature
    {{ DiscussionBoard.errors[1514011].message }}
  • Profile picture of the author customertools
    Cool little project, especially for only a week into PHP.. I was still doing hello worlds! a week into it! LOL
    {{ DiscussionBoard.errors[1520583].message }}

Trending Topics