Need hints on merging text variables into only one

04-11-04, 10:14 PM
|
|
Newbie Coder
|
|
Join Date: Apr 2004
Location: Montreal, Canada
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
Need hints on merging text variables into only one
Hi everyone, I am currently working to do my webpage using a templating system which will replace tags by text (ie: {HOME} to "Home") and it's doing good
The only problem I have now is when I want to replace one tag with lots of text such as tables with data. I tried this in a loop so it would do the same thing for every row of data that is in the mySQL table.
As you can see, it should replace $temp with the informations from the row in the mySQL table then add it to the $blabla variable right after the previous informations from the previous row(s). Like I said, it should work like this but it doesn't work like I thought it would work!
The code will show rows id: #1, #2, #1, #3, #1, #2 and #1 in this order when it should show all 5 rows and never repeat the same one. My table has 5 rows and it never showed me the fifth one.
Can anyone help me? Or does anyone know any other way to have a lot of data in a single variable?
Thanks all, Frank
|

04-12-04, 12:05 PM
|
 |
Community VIP
|
|
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
|
|
use the dot operator..
this way, PHP will append the new text at the end of the variable ..
it's that simple 
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
|

04-12-04, 01:11 PM
|
|
Newbie Coder
|
|
Join Date: Apr 2004
Location: Montreal, Canada
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hmm, it doesn't work, it adds even more text to the table (1,1,1,2,1,1,1,1,2, etc.)
Here's the full code of the loop:
By the way, this code is still a big draft..  I did try to modify the code to make it work in other ways but it always output a few times the same rows. Looks like it's always adding $blabla after $blabla itself, which doubles the data with the same data but it shouldn't do this! What do you think?
I would be glad if you could help me fixing this code 
Thanks, Frank
|

04-12-04, 02:31 PM
|
 |
Junior Code Guru
|
|
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi there,
Quote:
|
Originally Posted by Frank
Looks like it's always adding $blabla after $blabla itself, which doubles the data with the same data but it shouldn't do this! What do you think?
|
As NeverMind said, $foo .= $bar will append $bar to $foo, so if you wrote:
It's the same as this:
So what you want to do is this:
Hope this helps.
__________________
Blavv =|
|

04-12-04, 02:53 PM
|
|
Newbie Coder
|
|
Join Date: Apr 2004
Location: Montreal, Canada
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for the informations Blaw, it clarified a few things in my head now
I did what you told me and it still does the same thing, here's the modified code:
This code shows rows 1,2,1,3,1,2,1 in this order and then stops. It stops after 7 loops when there are 5 rows in the table and there is nothing in the code that tells it to stop after the seventh loop!
Anyone got a clue on this? Thanks, Frank
|

04-12-04, 05:48 PM
|
 |
Junior Code Guru
|
|
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi there,
Why do you have period after '</p>' ? Isn't it supposed to be semi-colon?
Anyway, you can surely achieve what you're doing with your approach, but more common one would be to use while loop this way:
In addition, you don't even need to check the num_rows if you are sure that there is always going to be 5 rows (or at least one row) returned from the query.
HTH.
__________________
Blavv =|
|

04-12-04, 05:58 PM
|
|
Newbie Coder
|
|
Join Date: Apr 2004
Location: Montreal, Canada
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Errm, the period after '</p>' was a typo error, thanks for pointing it out.
I tried your code and it WORKS! Wow, I still don't know what was the problem with my code, I'll comment it out and take a look at it in the near future.
Thanks for the help everyone! Frank
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|