Page 1 of 1

Combining Strings

Posted: Wed Jun 14, 2006 11:33 am
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?

Posted: Wed Jun 14, 2006 11:47 am
by Bigun
Forgive me...

Turns out a simple PHP tutorial had a few examples..

Re: Combining Strings

Posted: Wed Jun 14, 2006 11:49 am
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.

Re: Combining Strings

Posted: Wed Jun 14, 2006 4:47 pm
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.

Re: Combining Strings

Posted: Wed Jun 14, 2006 9:48 pm
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.