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 8961141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:49:07+00:00 2026-06-15T15:49:07+00:00

My code: echo <table width=’200px’ cellpadding=’5′ cellspacing=’0′><tbody>; $total = 500; for ($j = 0;

  • 0

My code:

echo "<table width='200px' cellpadding='5' cellspacing='0'><tbody>";

$total = 500;
for ($j = 0; $j < $total;$j++) {
    echo "<tr>";
    echo "<td>" . ($j+1) . "</td>";
    echo "<td>" . get_coupon_code() . "</td>";
    echo "</tr>";
}

function get_coupon_code() {
    $characters = 'ABCDEFGHJKLMNPQRSTUZWXYZ';
    $random_string_length = 8;
    $string = '';
    for ($i = 0; $i < $random_string_length; $i++) {
        $string .= $characters[rand(0, strlen($characters) - 1)];
    }
    return $string;
}

echo "</tbody></table>";

What would be the way to ensure that each code that’s generated is unique?

  • 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-06-15T15:49:08+00:00Added an answer on June 15, 2026 at 3:49 pm

    use static array variable to store your coupon codes and before returning the code ensure that it is not available in the array. Or more simpler, store the codes in an array handled in a session.

    function get_coupon_code() {
    $arr = $_SESSION['codes'];
        $characters = 'ABCDEFGHJKLMNPQRSTUZWXYZ';
        $random_string_length = 8;
        $string = '';
        for ($i = 0; $i < $random_string_length; $i++) {
            $string .= $characters[rand(0, strlen($characters) - 1)];
        }
    if (is_array($arr) && in_array($string, $arr))
    {
    return get_coupon_code();
    }
    else{
    $_SESSION['codes'][] = $string;
        return $string;
    }
    }
    

    Edited adding return to inner call of get_coupon_code()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have similar code <table width=1024 height=768> <tr> <td> <? echo $description; ?> </td>
Here is my code. <table border=1 style=width:800px> <?php $schedule_db = mysql_query(SELECT * FROM schedule
This is my Google Maps code (it works perfectly by itself): <table width=99%> <tr><td
In this image : The code of this page is : <table width=100% border=0
I have one ctp file where my code is :-- <table> <tr> <td width=50%><?php
PHP code: echo date(c); //out put like this 2012-06-19T20:37:44+05:30 echo date(d M, Y); //out
Look at the following code: ECHO A2 MKDIR -v /tmp/My Batch Script File Assignment
I have the following code: echo ' <td> <input type=button name=delete value=X onclick=clearSelection(this.form, '.$type.');this.form.submit();
So I have the following code: echo '<li><a href="'.$Website.$Elements[2].'/'.$Row["povezava"].'" class="leftMenuArticlesInactive"></a><li>'; $Website contains: http://www.somesite.com/test/ $Elements[2]
I'm using this code now echo $form->input('username'); How do I make sure the label

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.