Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Old 11-08-2005, 11:46 AM SQL query
qnc
Skilled Talker

Posts: 74
Trades: 0
What is the correct syntax for the following/

PHP Code:
$sql="SELECT fam_ui FROM fam_data WHERE fam_i = $fam_i and in_i = $in_i";

$sql2="SELECT ui FROM raw_allele WHERE fam_ui++d_no == $fam_ui_result ++ $matches"
qnc is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-08-2005, 05:18 PM
Average Talker

Posts: 20
Location: Benevento
Trades: 0
http://www.w3schools.com/sql/sql_where.asp

and don't mix php variables and sql or you'll get confused with bigger queries and with the creation of more complex queries based on different conditions.

Anyway the first sql query could be correct if $fam_i and $in_i are integer values, the second query is wrong.
Concatenate variables and strings with the .(dot) to create any kind of string,
that's the best way to have a cleaner and more readable code that can be parsed faster by php.
__________________

Please login or register to view this content. Registration is FREE
j2be is offline
Reply With Quote
View Public Profile Visit j2be's homepage!
 
Old 11-08-2005, 06:23 PM
rungss's Avatar
Skilled Talker

Posts: 67
Name: Bijay Rungta
Location: Mumbai, India
Trades: 0
$sql="SELECT `fam_ui` FROM `fam_data` WHERE `fam_i` = '$fam_i and in_i = $in_i' ";
if the fields are anything other than integer
rungss is offline
Reply With Quote
View Public Profile Visit rungss's homepage!
 
Old 11-09-2005, 04:35 AM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
j2be: The dot . operator will concatenate two PHP variables, but in order to concatenate two SQL fields during the query you'll need to use the SQL function CONCAT(string1,string2)
PHP Code:
$sql2="SELECT ui FROM raw_allele WHERE CONCAT(fam_ui,d_no) = " $fam_ui_result $matches
rungss: you are missing some quotes in the where clause of the query.
PHP Code:
$sql="SELECT `fam_ui` FROM `fam_data` WHERE `fam_i` = '$fam_i' and in_i = '$in_i' "
Or if you want to separate the PHP and SQL:
PHP Code:
$sql="SELECT `fam_ui` FROM `fam_data` WHERE `fam_i` = '" $fam_i "' and in_i = '" $in_i' "; 
Personally I use a combination of PHP variables inside and outside the string - sometimes the variable cause confusion especially if they are parts of an array. Other times the quotes get confusing as to what is SQL and what is the edge of the PHP string.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)

Last edited by 0beron; 11-09-2005 at 02:01 PM..
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 11-09-2005, 10:57 AM
Average Talker

Posts: 20
Location: Benevento
Trades: 0
Quote:
Originally Posted by rungss
$sql="SELECT `fam_ui` FROM `fam_data` WHERE `fam_i` = '$fam_i and in_i = $in_i' ";
if the fields are anything other than integer
I'm talking ONLY about strings and variables concatenation in php!
__________________

Please login or register to view this content. Registration is FREE
j2be is offline
Reply With Quote
View Public Profile Visit j2be's homepage!
 
Reply     « Reply to SQL query
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.34063 seconds with 12 queries