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

  • SEARCH
  • Home
  • 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 7876365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:09:22+00:00 2026-06-03T03:09:22+00:00

I have a loop where it query’s mysql for a search but the search

  • 0

I have a loop where it query’s mysql for a search but the search will change by the end of the query.
What i found out with my coding is which i did not now is that i can’t reassign a variable to a new search query, or not correctly anyways.

I have added echo’s to see what it’s doing.

Lets say John is assigned to $preg_split

What i am trying to do is to match a character with a database if one the first characters in the database for example J matches then assign the second character from $pre_split which is o so $char would be jo

So the variable $char in the beginning should be updated with jo

Instead for some reason which i’m sure that i just did not write my code correct is that it echo’s o an not jo..

So i’m a bit puzzled why its the second character and not the first.

$NG_implode = implode("", $preg_split);

$NG_split = str_split($NG_implode, 1);
$i = '0';
$ia = '1';
$ib = '0';
$ic = '1';
$char = $NG_split[$ib];


foreach ($NG_split as $char)
{

    $NG_select_like = "SELECT word FROM checklist_filter WHERE word LIKE '".$char."%'";
    $NG_query = mysql_query($NG_select_like) or die(mysql_error());
    $NG_row = mysql_fetch_row($NG_query);
    $chars = str_split($char, 1);
    $row = str_split($NG_row[0], 1);
        if ($chars[$i] == $row[$i])
        {

            $char = $char.$NG_split[$ia];

            $ia++;
            $i++;
            if ($char == $NG_row[0]){break;}
            }else{$ib++; $char = $NG_split[$ib];}

    }
  • 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-03T03:09:23+00:00Added an answer on June 3, 2026 at 3:09 am

    $char gets set to the next value of $NG_split in every new iteration of the foreach loop , so the value you’re assigning to $char inside your foreach loop won’t be there anymore next time. Can’t you simply do this?

    <?php
    $str = "John";
    $len = strlen($str);
    
    $arr = array();
    $i = 0;
    while($i < $len) { 
        $arr[] = substr($str,0,$len-$i);
        $i++;
    } 
    
    var_dump($arr);
    ?>
    

    Now if you iterate over $arr you should be able to build the queries you’re interested in. There’s probably an even more efficient way to get the results you’re looking for using a regular expression in MySQL but it would help if you could share a bit more about your use case for this.

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

Sidebar

Related Questions

I have a loop (based on an array - which could grow but NOT
I do have a loop which store data into mysql... /connect to your database
I have a main report which loop over query's data on detail1 band. In
I have a linq to objects query in a recursive loop and afraid when
I'm pretty new to jQuery/JS. But I have loop in jQuery where I would
I have a loop for(aI = antiviral_data.begin(); aI != antiviral_data.end();) { for(vI = viral_data.begin();
I have a while loop from a query called $result . Inside this while
I have a for loop that writes the results of a query into a
I have a loop going which adds results from my database. The values are
I have created a query block with begin/end and want to run that in

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.