MartynA
-
Posts
3 -
Joined
-
Last visited
Never
Posts posted by MartynA
-
-
Thanks; close but no cigar.
Your code gave me an error so I looked up the eval syntax and came up with
[code]eval("print \"\$row2->user$variable\";");[/code]
However, that doesn't output anything. At all. What I am doing wrong?
-
Hi,
I hope one of you guys can help, I have a slight problem involving arrays and variables:
I have an object array, $row2 populated with data pulled from mysql. Hence $row2->name grabs the name part of the query.
Now, i want to do a foreach loop to display some of these, specifically user2, user7 etc.
Long story short, how do I concatenate $row2->user with the array key - or any thing else for that matter:
[code]$variable = "7";
print "$row2->user" . "$variable";
[/code]
This doesn't work, and only outputs 7, not the contents of $row2->user7.
I suspect I'm missing something obvious here, anyone wanna fill me in?
Thanks,
Mart
Concatenation of two variables (sort of)
in PHP Coding Help
Posted
Try changing your mysql_fetch to mysql_fetch_assoc(), then you would reference the field with $row2['user']
and the code to print:
[code]<?php print $row2['user'] . $variable; ?>[/code]
The next question is ... why do you want to do this? Maybe if you explain what you want to do, we can come up with an easier way of doing it.
Ken
[/quote]
Thanks Ken, that did it. For any future reference, I was wanting to foreach through an array containing values such as 5,7,6 and then echo out the equivalent, e.g. $row2->user$valueinarray. That way I could define what information I wanted printing just by passing an array to the function.
Thanks, and sorry for not explaining myself so well.