Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6949235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:55:39+00:00 2026-05-27T13:55:39+00:00

I have created a random string generator. What happens is that the user would

  • 0

I have created a random string generator. What happens is that the user would click on a button and by using letters A and B it will construct a 3 letter string like these for example:

AAA
AAB
ABA
ABB
BAA
BAB
BBA
BBB

Now what I want is my random string generation to link with the “SessionId” column which is in the “Session” Table of my database where these strings will be stored in. What I want is the button to generate a string which is not in the database. For example look below (SessionId in Session Table):

Session Id

AAA
AAB

As these two sessions (string AAA and AAB) are in the database the generator should not display these two strings at all when clicking on the button and generating the strings as they are already in the database. Later on I want the genrated string to be stored in the database but at the moment I just want my generator to generate strings that are already in the database.

Does anyone know how to link this to my “Session Id” field in the “Session” Table and generate strings which are not in the database?

My code is in jsfiddle so you can see how the button works and the code used, click here to see

Below is my php code I am using at moment. This php code will let me connect to database and all user to enter a courseId in the textbox, if courseId is in textbox then user can enter else it will display an alert. Below is code:

      <?php

              $username="xxxxxxxxxxx";
              $password="xxxxxx";
              $database="mobile_app";

              mysql_connect('localhost',$username,$password);
              @mysql_select_db($database) or die("Unable to select database");

              foreach (array('courseid') as $varname) {
                $courseid = (isset($_POST[$varname])) ? $_POST[$varname] : '';
              }

            ?>


<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<p>Course ID: <input type="text" name="courseid" value="<?php echo $courseid; ?>" /><input type="submit" value="Submit" name="submit" /></p>      <!-- Enter User Id here-->
            </form>

            <?php
    if (isset($_POST['submit'])) {
        $query = "
                     SELECT cm.CourseId, cm.ModuleId, 
                     c.CourseName,
                     m.ModuleName
                     FROM Course c
                     INNER JOIN Course_Module cm ON c.CourseId = cm.CourseId
                     JOIN Module m ON cm.ModuleId = m.ModuleId
                     WHERE
                     (c.CourseId = '".mysql_real_escape_string($courseid)."')
                     ORDER BY c.CourseName, m.ModuleId
                     ";



    $num = mysql_num_rows($result = mysql_query($query));
        mysql_close()

;
?>

updated php code below:

<?php

      $username=xxx";
      $password="xxx";
      $database="mobile_app";


      $is_there = true;

      $con = mysql_connect('localhost',$username,$password);
      @mysql_select_db($database, $con) or die("Unable to select database");

while( $is_there ){
    $id = id_generator(); // your function to generate id;
    $result = mysql_query( "SELECT SessionId FROM Session WHERE SessionId = '$id'" );
    if( mysql_num_rows( $result ) == 0 ) $is_there = false;
}




      foreach (array('courseid', 'sessionid') as $varname) {
        $$varname = (isset($_POST[$varname])) ? $_POST[$varname] : '';
      }

    ?>

    <h1>CREATING A SESSION</h1>

        <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
         <p>Course ID: <input type="text" name="courseid" value="<?php echo $courseid; ?>" /><input type="submit" value="Submit" name="submit" /></p>      <!-- Enter User Id here-->
        </form>

        <?php
if (isset($_POST['submit'])) {
    $query = "
                 SELECT cm.CourseId, cm.ModuleId, 
                 c.CourseName,
                 m.ModuleName
                 FROM Course c
                 INNER JOIN Course_Module cm ON c.CourseId = cm.CourseId
                 JOIN Module m ON cm.ModuleId = m.ModuleId
                 WHERE
                 (c.CourseId = '".mysql_real_escape_string($courseid)."')
                 ORDER BY c.CourseName, m.ModuleId
                 ";

    $num = mysql_num_rows($result = mysql_query($query));
    mysql_close();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:55:39+00:00Added an answer on May 27, 2026 at 1:55 pm

    Your code on the server should be like:

    $is_there = true;
    
    $con = mysql_connect( address , user, pass );
    mysql_select_db( DATABASE , $con );
    
    while( $is_there ){
        $id = id_generator(); // your function to generate id;
        $result = mysql_query( "SELECT * FROM your_table WHERE id = '$id'" );
        if( mysql_num_rows( $result ) == 0 ) $is_there = false;
    }
    

    This will stop when generated id is not found in the DB.

    <?php
    
                  ...
                  @mysql_select_db($database) or die("Unable to select database");
                  $courseid = "";
                  while( $is_there ){
                  $courseid = id_generator(); // your function to generate id;
                  $query = "
                         SELECT cm.CourseId, cm.ModuleId, 
                         c.CourseName,
                         m.ModuleName
                         FROM Course c
                         INNER JOIN Course_Module cm ON c.CourseId = cm.CourseId
                         JOIN Module m ON cm.ModuleId = m.ModuleId
                         WHERE
                         (c.CourseId = '".mysql_real_escape_string($courseid)."')
                         ORDER BY c.CourseName, m.ModuleId
                         ";
    
                  if( mysql_num_rows( $result = mysql_query($query) ) == 0 ) $is_there = false;
                  }
                  mysql_close();
                  echo "You generated code id: " . $courseid;
    
                  ?>...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would it be possible to generate a random, unique string using numbers and
I'm building an application that will have a user base, and I'm at the
I have a little script that is used to generate a random string of
I'm trying to create a trigger that will associate an unique random string to
Suppose we have a method that returns a random string : def return_random random
I have some code on my PHP powered site that creates a random hash
I have created a custom dialog for Visual Studio Setup Project using the steps
I have created a PHP-script to update a web server that is live inside
I have created a UserControl that has a ListView in it. The ListView is
I have created a C# class file by using a XSD-file as an input.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.