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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:37:43+00:00 2026-05-20T02:37:43+00:00

I have an input that takes tag names, with a space between them. Then

  • 0

I have an input that takes tag names, with a space between them. Then I explode it into an array and loop through the array once per tag. If the tag doesn’t exist, I want it added to my tags table, and again to my coupon_tags table. If it exists, just the coupon_tags table. My code worked when it handled one tag at a time, but with multi-tag handling it broke. No matter the existence of a tag, my code will always say that it exists, which means that it sees a non-zero result for the amount of rows containing that tag.

Perhaps there is an easier way to test for the existence of something in a MySQL table, rather than how I did it (selecting all rows that contain the tagName I have, then seeing if the amount of rows is one or zero)?

I have the following code:

$splitTags = explode(" ", $tag);

foreach($splitTags as $i){
     echo $splitTags[$i] . "<br/>";
     $resTags = mysql_num_rows(mysql_query("SELECT * FROM tags WHERE tagName = '$splitTags[$i]'"));
//if tag doesn't already exist, create it. either way, append this coupon's id to the list id's related to this tag and add a space
     if($resTags > 0)
     {
        $tagQueRes = mysql_query("SELECT tagID FROM tags WHERE tagName = '$splitTags[$i]'");
        $row = mysql_fetch_assoc($tagQueRes);
        $tagID = $row["tagID"];
        echo "Tag Exists" . "<br/>";
     }
     else
     {
        $tagID = mysql_num_rows(mysql_query("SELECT * FROM tags")) + 1;
            mysql_query("INSERT INTO tags (tagName, tagID) VALUES ('$splitTags[$i]','$tagID')");
        echo "New Tag Added" . "<br/>";
     }
     mysql_query("INSERT INTO coupon_tags (tagID, couponID) VALUES ('$tagID', '$newID')");
}
  • 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-20T02:37:43+00:00Added an answer on May 20, 2026 at 2:37 am
    $splitTags = explode(" ", $tag);
    foreach ($splitTags as $key=>$val)
    {
      // replace $splitTags[$i] with $val
      ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that takes an input string and then runs the string
I have an input box that takes values from 0-100. I want to prevent
I have a perl program that takes input and output file arguments, and I'd
I have a form on my website that takes input from a text area
I have a Perl script that takes user input and creates another script that
I have an application that takes some input and generates configuration files as output.
I have this function that takes the input of a, runs a calculation and
I have a google map that takes and put coordinates from input fields .
Hi I have a textbox that takes a username input. When the user submits
If I have a 3 layer web forms application that takes user input, I

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.