Asked  2 Years ago    Answers:  5   Viewed   55 times

please check the following code.

$imagebaseurl = 'support/content_editor/uploads/$name';

The $imagebaseurl is a variable that is containing a link to my image folder (uploads) and inside the folder I have some other folders which are named after my users name. for example: I have a user who's name is john, so the the link should look like this-> support/content_editor/uploads/john.

The main idea is when any user is logged in and browses his image gallery I want to take him to his own gallery which basically is named after his name.

When he will visit the gallery the value of $name in the link will come from the user's login name (from session). Now the problem is as you probably have already understood that the placement of $name in the above link is wrong and that is why it is not working. I am getting this whole URL> (support/content_editor/uploads/$name) instead of (support/content_editor/uploads/john)

Now could you please tell me how to use the $name in this $imagebaseurl = 'support/content_editor/uploads/$name';

 Answers

2
$imagebaseurl = 'support/content_editor/uploads/' . $name;

or

$imagebaseurl = "support/content_editor/uploads/{$name}";

Note that if you use double quotes, you can also write the above as:

$imagebaseurl = "support/content_editor/uploads/$name";

It's good though to get in the habit of using {$...} in double quotes instead of only $..., for times where you need to insert the variable in a string where it's not obvious to PHP which part is the variable and which part is the string.

If you want the best performance, use string concatenation with single quotes.

Saturday, December 17, 2022
1

You should point to your vendor/autoload.php at Settings | PHP | PHPUnit when using PHPUnit via Composer.

This blog post has all the details (with pictures) to successfully configure IDE for such scenario: http://confluence.jetbrains.com/display/PhpStorm/PHPUnit+Installation+via+Composer+in+PhpStorm

Related usability ticket: http://youtrack.jetbrains.com/issue/WI-18388

P.S. The WI-18388 ticket is already fixed in v8.0

Sunday, July 31, 2022
 
4

On Mac OS X environment variables available in Terminal and for the normal applications can be different, check the related question for the solution how to make them similar.

Note that this solution will not work on Mountain Lion (10.8).

Sunday, November 6, 2022
1

Two reasons:

  • Better readability (you know the array is initialized at this point)
  • Security - when running on a system with register_globals enabled a user could add e.g. hello[moo]=something to the query string and the array would already be initialized with this. $hello = array(); overwrites this value though since a new array is created.
Sunday, October 30, 2022
 
2

In my installation of SQL Server 2008 R2, it simply doesn't compile. The parser complains about there being incorrect syntax near =.

I believe it must have something to do with mixing value assignment and data retrieval in a single SELECT statement, which is not allowed in SQL Server: you can have either one or the other. Since, when you assign values, the row set is not returned but the EXISTS predicate expects it to be, the assignment cannot be allowed in that context, so, to avoid confusion, perhaps, the limitation must have been imposed explicitly.

Your workaround, which you are talking about in a comment, is a decent one, but might not work well somewhere in the middle of a batch when the variable has already got a value before the assignment. So I would probably use this workaround instead:

SELECT @myvar = ...
IF @@ROWCOUNT > 0 ...

As per MSDN, the @@ROWCOUNT system function returns the number of rows read by the query.

Thursday, November 3, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 

Browse Other Code Languages