0

I was going over a tutorial on pagination and I was confused about why a concatenation dot was placed in an area, I thought it was unnecessary and thought I the poster of the tutorial video would get an error, but they didnt...so when I implemented the code and it worked fine but as a test I removed the concatenation and the code didnt work as it should.

here is the code.

I am use to concatenation looking like this

$limit = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows;

but further down the tutorial the concatenation looked like this, in front of the =operator

$list = '';
$list .='<a href="testpage.php?id='.$username.'">' .$into. '</a>Click Here'

Thanks for any explanations given

tru
  • 117
  • 1
  • 2
  • 9
  • its `$list =$list.'' .$into. 'Click Here'` like `+=` – Ronser Nov 22 '14 at 13:37
  • There are 2 different situations, in one it builds a dynamic sql query in the other it outputs different links, probably in a loop. – Mihai Nov 22 '14 at 13:40
  • yes the output will be in a loop, but i thought the first $list variable is saying $list will be a string and the second $list variable is defining that string. If I output the string twice you get 2 strings...none containing a variable in the beginning so I am still confused on why a concatenation is required before the =operator – tru Nov 22 '14 at 13:44
  • For each iteration of that loop `.=` it builds a new link `'' anotherblah 'Click Here'` and so on. – Mihai Nov 22 '14 at 13:48

2 Answers2

2

Concatenation before an equal sign could be referred to as 'append'

e.g.

$a="hello";
$a.=" world";
echo $a;

The output would be:

hello world

The line:

$a.=" world";

is similar to:

$a=$a." world";
DLastCodeBender
  • 327
  • 1
  • 13
1
$list .='<a href="testpage.php?id='.$username.'">' .$into. '</a>Click Here'

is like

$list =$list.'<a href="testpage.php?id='.$username.'">' .$into. '</a>Click Here'

just like += operator

its better to just search for your problem before posting a question

reference Here

Community
  • 1
  • 1
Ronser
  • 1,855
  • 6
  • 20
  • 38
  • I thank you for your answer but why do people on here get so snippy, I did research it and I did not find the answer that is why I asked. Again I thank you for attempting to answer my question but the added assumption and criticism was very unnecessary, it would have just been better for you not to answer if the question affected you so. But again thank you for answering – tru Nov 22 '14 at 13:52
  • 1
    I too had the same difficulty at the beginning @tru thats why I have answered. As days pass you will learn to query your problems in a better way. Our main motive is that the OP has atleast tried something before posting a question that's why we keep repeating this. – Ronser Nov 22 '14 at 13:58
  • @Rosner No problem, I will try to research better, and I will make sure I include where and how i have attempted in my post. Even thought the link you provided didnt answer the question in a way I understood it was an extremely useful and valuable link. I didnt understand your answer, but the above responder DLastCodeBender answered in a way that comprehended to me and as a result I understood what your why trying to relay to me in your answer. Thanks again – tru Nov 22 '14 at 14:29
  • you are welcome!!! and your questions answer is in that link. check `.= Assignment Operators` in that link – Ronser Nov 22 '14 at 15:16