PHP question

Don Erickson derick at zeni.net
Sun Apr 4 23:29:30 CDT 2004


Brian D wrote:

> I'm trying to do something inside a for loop. I know
> ther must be a better way than this, but it was the
> best I could come up with. I need to embed double
> qoutes and PHP variables in a single string. The best
> I could figure out was an echo with single quotes and
> preiods before and after te variables
> 
> echo '<td><a
> href="'.$DYN_menu[$i]->URL.'">'.$DYN_menu[$i]->TITLE.'</a>&nbsp;
> |&nbsp;&nbsp;</td>'; 

For starters, variables between single tics don't get expanded in php.
So, you need to use double quotes on the echo command.  Just escape the 
quotes that you need to keep the html from breaking out on spaces. 
Also, I don't know what the "->" in your code does, but I see what it is 
supposed to do.  Does this really work in associative arrays?  I've not 
seen it before.

I'd try something like:

while ($DYN_menu[$i]) {
     foreach ($DYN_menu[$i] as $URL => $TITLE) {
         echo "<td><a href="$URL">$TITLE</a>&nbsp;&nbsp;&nbsp;</td>";
     }
$i++;
}

Regards,

-Don




More information about the Kclug mailing list