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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:15:09+00:00 2026-06-18T07:15:09+00:00

am having a problem with a bit of code. I am trying to generate

  • 0

am having a problem with a bit of code.

I am trying to generate a unique name to insert into a database.

i have created the following function which checks to see if the name already exists:

function checkExists($database_reelfilm, $reelfilm, $mySlug, $locVal){
        $mmid_rs_slugCheck = "-1";
        if (isset($mySlug)) {
          $mmid_rs_slugCheck = $mySlug;
        }
        $mmid2_rs_slugCheck = "-1";
        if (isset($locVal)) {
          $mmid2_rs_slugCheck = $locVal;
        }
        mysql_select_db($database_reelfilm, $reelfilm);
        $query_rs_slugCheck = sprintf("SELECT * FROM locations_loc WHERE locations_loc.slug_loc = %s AND locations_loc.id_loc != %s", GetSQLValueString($mmid_rs_slugCheck, "text"),GetSQLValueString($mmid2_rs_slugCheck, "int"));
        $rs_slugCheck = mysql_query($query_rs_slugCheck, $reelfilm) or die(mysql_error());
        $row_rs_slugCheck = mysql_fetch_assoc($rs_slugCheck);
        $totalRows_rs_slugCheck = mysql_num_rows($rs_slugCheck);
        if($totalRows_rs_SlugCheck > 0){
            return true;
        }else{
            return false;
        }
    };

i then create a loop to checking if the variable name exists, if it does i want it to add the value of the counter to the variable name then recheck to see if that exists until i have a unique name which i can then save to my db.

$updateVal = slugify($row_rs_locations['name_loc']);
        $newSlug = slugify($row_rs_locations['name_loc']);
        $locVal = $row_rs_locations['id_loc'];
        //echo(slugify($row_rs_locations['name_loc']));
        $checkCount = 1;
        $isDupe = '<BR>';
        while(checkExists($database_reelfilm, $reelfilm, $newSlug, $locVal)){
            $isDupe = 'Duplicate Added ' . $checkCount . ' to slug...<BR>';
            $newSlug = $newVal . $checkCount;
            $checkCount ++;
        }
        if($updateVal != $newVal){
            $updateVal = $newSlug;
        }

I am obviously doing something wrong, I need the while loop on the next iteration to use the newSlug value set in the loop, from my various attempts i am not at all sure if this is possible.

Whats the best way to accomplish this?

  • 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-18T07:15:10+00:00Added an answer on June 18, 2026 at 7:15 am

    $newVal is not ever given a value, but it is used twice (second block of code). I think you need something like:

    $newSlug = slugify($row_rs_locations['name_loc']);
    $newVal = $newSlug;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a problem with the following bit of code. I am trying
Hi I'm having a bit of a problem with my code I'm trying to
I am having a bit of a problem trying to get this code to
I am having a problem with bit of code. This is the code $test
I'm having a bit of a problem using FieldOffset correctly with arrays. The code
I'm having a bit of a problem with this code. The program gives me
I'm having a little bit of problem with my derived class. Basically I have
Hi having a bit of a problem what I'm trying to do is once
I'm trying to wrap div with specific html code but I'm having problem using
I'm having a bit of a problem trying to import data from a CSV

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.