INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Question regarding mySql and select line continue

Question regarding mySql and select line continue

Question regarding mySql and select line continue

(OP)
I'm attempting to rewrite all my asp/mssql in php/mysql and I have a problem with continuing the select statement string on a separate/second line.
In asp my Select statement would look partially like this -

strSQL = "SELECT books.recid AS recid, books.date_created AS cdate, "
strSQL = strSQL & "books.au_fname AS fname, books.au_mname AS mname, "
strSQL = strSQL & "books.au_lname AS lname, books.title AS title "


and it worked just fine but in mySQl/php I cannot get the darn thing to work. It works fine when I keep the select statement line to a single line but when I go to a second line...well. I've tried different combinations of syntax but no luck.

My working mysql/php looks like this - $sql = "select blog-recid as recid, picdesc as pdesc from blogpic order by blog-recid; "

I would like it to look like this ----

$sql = "SELECT blog_recid as recid, picdesc as pdesc, picowner as powner; "
"FROM blogpic; "
"ORDER BY blog_recid; "

I would appreciate any help someone may be willing to give me. Riley


RE: Question regarding mySql and select line continue

Hi

First of all, this is pure PHP question and has nothing to do with any SQL dialect.

Then do not put semicolons ( ; ) in the middle of SQL statement.

Your options would be :

CODE --> PHP

// concantenate strings
$sql = "SELECT blog_recid as recid, picdesc as pdesc, picowner as powner " .
"FROM blogpic " .
"ORDER BY blog_recid ";

// append strings
$sql = "SELECT blog_recid as recid, picdesc as pdesc, picowner as powner ";
$sql .= "FROM blogpic ";
$sql .= "ORDER BY blog_recid ";

// use a single multiline string
$sql = "SELECT blog_recid as recid, picdesc as pdesc, picowner as powner
FROM blogpic
ORDER BY blog_recid";

// same as above with heredoc notation
$sql = <<<END_OF_STRING
SELECT blog_recid as recid, picdesc as pdesc, picowner as powner
FROM blogpic
ORDER BY blog_recid
END_OF_STRING; 

Feherke.
feherke.ga

RE: Question regarding mySql and select line continue

(OP)
Thank you very much for the help and I'll make sure I'm in the php forum next time. Riley

RE: Question regarding mySql and select line continue

While Feherke has given you all the options, you could also do with your old way, just use the PHP way to concatenate strings with dot, not with ampersand. The whole rest of development langauges uses a plus as concatentaion operator, but that aside it's simply also possible to stay with your old way and simply replace & with .

CODE

strSQL = "SELECT books.recid AS recid, books.date_created AS cdate, ";
 strSQL = strSQL . "books.au_fname AS fname, books.au_mname AS mname, ";
 strSQL = strSQL . "books.au_lname AS lname, books.title AS title; "; 

As you see you also need semicolons at the end of each line, but outside the strings, each PHP command needs to end with a semicolon, you execute three assigment commands here in this code version. The only semicolon needed inside the strings is at the very end of the sql query, that's optional with a single query and is the only thing related to MySQL in your code.

PHP like most any langauge differs form VB in not needing a command continuation character like VBs underline. Continuation of code needs no specific character, even in Feherkes "use a single multiline string" example. Instead you end every command with a semicolon. Outside of any string.

Bye, Olaf.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close