Jump to content

Why Echo does not work on php variable the second and third time?


the5thace
Go to solution Solved by trq,

Recommended Posts

The variable $q_words[$loop_count-1]  is shown in the top besides Did you mean? but it fails to come up inside of the hyperlink. Any ideas to why?

 

 

 

<?php
if ($_POST['query'])


{
    $query = ($_POST['query']);
    $q_words = explode (" ", $query); 
    $loop_count = 0;
    $q_count = count(q_words);
    $s_count = 0;
    $ss_count = 0;
    while ($loop_count <= $q_count )
    {
        $query = 'http://www.dictionaryapi.com/api/v1/references/collegiate/xml/'.$q_words[$loop_count].'?key=135a6187-af83-4e85-85c1-1a28db11d5da';
        $xml = new SimpleXMLIterator(file_get_contents($query));
        
        foreach ($xml -> suggestion as $suggestion[$s_count])
        {
            $s_count++;
        }
        if ($s_count > 1)
        {     
            echo ('<h4>Did you mean ....? '.$q_words[$loop_count-1].'</h4>');
            while ($ss_count <=$s_count)
            {
            echo '<a href = "AllinOneMonstaaa.php?query='.$q_words[loop_count-1].' '.$suggestion[$ss_count].'">'.$q_words[loop_count-1].' '.$suggestion[$ss_count].'</a><br>';
            $ss_count++;
            }
        
        }
     $loop_count++;   
    }
}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.