Jump to content


Photo

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

echo php loop

Best Answer trq, 19 July 2013 - 08:21 AM

You are missing the $ off the variable $loop_count

You really should have error reporting enabled when developing. Go to the full post


  • Please log in to reply
1 reply to this topic

#1 the5thace

the5thace

    Member

  • Members
  • PipPip
  • 26 posts

Posted 19 July 2013 - 07:37 AM

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++;   
    }
}

 



#2 trq

trq

    Advanced Member

  • Administrators
  • 30,923 posts
  • LocationSydney, Australia.

Posted 19 July 2013 - 08:21 AM   Best Answer

You are missing the $ off the variable $loop_count

You really should have error reporting enabled when developing.

http://thorpesystems.com | http://proemframework.org | http://github.com/trq

SmtpCatcher - A very simple mock sendmail useful for testing PHP mail scripts.
OPM - My Linux package manager.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com