...

View Full Version : Make long statements on multiple lines?



rfresh
02-11-2010, 08:57 PM
I have a long query and would like to put it on multiple lines.

I would like to make this:


WHERE id = '%d'",mysql_real_escape_string($_SESSION["php_g_edit_employee_last_name"]),mysql_real_escape_string($_SESSION["php_g_edit_employee_first_name"]),mysql_real_escape_string($_SESSION["php_g_edit_employee_middle_name"]),mysql_real_escape_string($_SESSION["php_g_employee_cellular_provider"]),mysql_real_escape_string($php_employee_other_cellular_provider),mysql_real_escape_string($_SESSION["php_g_employee_cellular_phone"]));


into this:


WHERE id = '%d'",mysql_real_escape_string($_SESSION["php_g_edit_employee_last_name"]),
mysql_real_escape_string($_SESSION["php_g_edit_employee_first_name"]),
mysql_real_escape_string($_SESSION["php_g_edit_employee_middle_name"]),
mysql_real_escape_string($_SESSION["php_g_employee_cellular_provider"]),
mysql_real_escape_string($php_employee_other_cellular_provider),
mysql_real_escape_string($_SESSION["php_g_employee_cellular_phone"]));


where it is more readable.

Thanks...

Fumigator
02-11-2010, 09:26 PM
What's your question?

rfresh
02-11-2010, 09:48 PM
In my editor, how can I make the multiple query lines? When I try to do it I get a syntax error on my query string. I tried adding a period after each line but I guess that doesn't work.

I'd like the lines to LOOK something like this in my editor but the query string won't work if I do.



WHERE id = '%d'",mysql_real_escape_string($_SESSION["php_g_edit_employee_last_name"]),
mysql_real_escape_string($_SESSION["php_g_edit_employee_first_name"]),
mysql_real_escape_string($_SESSION["php_g_edit_employee_middle_name"]),
mysql_real_escape_string($_SESSION["php_g_employee_cellular_provider"]),
mysql_real_escape_string($php_employee_other_cellular_provider),
mysql_real_escape_string($_SESSION["php_g_employee_cellular_phone"]));

Fumigator
02-11-2010, 11:18 PM
That can't be the entire piece of code; it's not valid the first way you have it. I can't really help if I can't see the entire statement.

MattyUK
02-11-2010, 11:33 PM
What editor are you using?

do you need spaces after the commas?
I'm a little out of practice but I seem to recall it may have mattered to me once.

The whole statement would be helpful.

Len Whistler
02-12-2010, 12:12 AM
Can't you just hit Enter and Tab to make long query lines more readable? I use Gedit and am 90% sure it will be OK.


---------------------

rfresh
02-12-2010, 12:38 AM
No, entering new line and then tab does not work. I'm using EditPLus2 editor.

Here is the whole code structure of what I'd like to be able to do on multiple lines and not get this kind of error:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING

This example isn't too bad but I have some updates that contain a lot of fields so I have a lot of mysql_real_escape_string() lines and I'd just like to "see" them each on one line in my editor.



$php_SQL = sprintf("UPDATE Employees SET last_name = '%s'"
", first_name = '%s'"
", middle_name = '%s'"
" WHERE id = '%d'",
mysql_real_escape_string("Smith"),
mysql_real_escape_string("John"),
mysql_real_escape_string("J"),
mysql_real_escape_string(5));

rfresh
02-12-2010, 01:55 AM
I just got it to work by opening up the database before executing the sprintf() function. Entering enter and tab does work now. I would never have guessed that the database had to be open prior to using sprintf().

MattF
02-12-2010, 02:24 AM
$php_SQL = sprintf("UPDATE Employees SET last_name = '%s',
first_name = '%s',
middle_name = '%s',
WHERE id = '%d',
mysql_real_escape_string('Smith'),
mysql_real_escape_string('John'),
mysql_real_escape_string('J'),
mysql_real_escape_string(5)");

PappaJohn
02-12-2010, 02:35 AM
I would never have guessed that the database had to be open prior to using sprintf().
The database connection was necessary because of your use of mysql_real_escape_string()

JAY6390
02-12-2010, 03:17 AM
Like I mentioned in your previous thread it would be more advantageous to use the mressf function for these long queries with multiple values you need to run mysql_real_escape_string on at once, and would make it far more readable



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum