Combining Strings

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Combining Strings

Post by Bigun »

I'm trying to construct a MySQL query, and I'm wondering how to combine plain text with a variable to make one single sect of plain text.

Like so:

Code: Select all

$query="SELECT `users`.`u-email` FROM users WHERE (`users`.`u-email`" && $email && ")";
I'm sure my syntax is *WAY* off, but it's so you get the general idea of what I'm trying to do.

This kind of function is hard to google.

So, how do I do it?
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Post by Bigun »

Forgive me...

Turns out a simple PHP tutorial had a few examples..
GM
Forum Contributor
Posts: 365
Joined: Wed Apr 26, 2006 4:19 am
Location: Italy

Re: Combining Strings

Post by GM »

Bigun wrote:I'm trying to construct a MySQL query, and I'm wondering how to combine plain text with a variable to make one single sect of plain text.

Like so:

Code: Select all

$query="SELECT `users`.`u-email` FROM users WHERE (`users`.`u-email`" && $email && ")";
I'm sure my syntax is *WAY* off, but it's so you get the general idea of what I'm trying to do.

This kind of function is hard to google.

So, how do I do it?

Code: Select all

$query = "SELECT `users`.`u-email` FROM users WHERE `users`.`u-email`='$email'";
If you use double quotes "string" then PHP automatically interprets any variables it finds within them. If you us single quotes 'string' PHP does not interpret the variables.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Combining Strings

Post by Christopher »

Bigun wrote:I'm trying to construct a MySQL query, and I'm wondering how to combine plain text with a variable to make one single sect of plain text.
You should really have a quick read through the online PHP manual. It is probably one of the best manuals of any language. Do a quick tour through the Language Reference section and the common library sections for: Arrays, Date and Time, Filesystem, Misc., Strings.

I often just keep a browser window open to the online manual when I program. I like that they list related functions with every function, plus user contribited notes at the bottom. I learn something new every time I look something up.
(#10850)
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Re: Combining Strings

Post by Bigun »

arborint wrote:
Bigun wrote:I'm trying to construct a MySQL query, and I'm wondering how to combine plain text with a variable to make one single sect of plain text.
You should really have a quick read through the online PHP manual. It is probably one of the best manuals of any language. Do a quick tour through the Language Reference section and the common library sections for: Arrays, Date and Time, Filesystem, Misc., Strings.

I often just keep a browser window open to the online manual when I program. I like that they list related functions with every function, plus user contribited notes at the bottom. I learn something new every time I look something up.
Trust me, an hour into programming, I have firefox open with at least 12 or so tabs.
Post Reply