473,395 Members | 1,411 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

how do I query with a string as part of the where clause?

36
Hi

I am having a problem with a query. I am trying to query my oracle database for a certain number corresponding to at least 4 other fields of information. Anyway I dont know what is going on but the query doesnt work unless I pull out the part of the clause which contains a string. All other where clauses contain integers stored into php variables but for some reason it doesnt like the string. I would appreciate if someone could take a look at this for me. Heres the code and I threw some comments in to further explain what I am trying to do . Thanks for looking.

Peace
Expand|Select|Wrap|Line Numbers
  1. //I get the value of thie variable from a drop down menu which stores it in a 
  2. //session variable.  The contents of the variable is a string.  
  3. $call_put2 = $_SESSION['opt_cp_vals'][$opt_indx];
  4.  
  5.  
  6. // Here is the query the problem is when I put $call_put2 it does not work
  7. //Without it, it does work.  I tried escaping the string with single double and no 
  8. // quote but it still does not work
  9. $query7 = "select count(strike) from surfaces where undl_indx = $undl_indx and strike = $user_input_strike and expire_date = $expire_date1 and call_put = \'$call_put2\' ";
  10.  
Jul 25 '07 #1
5 1354
mwasif
802 Expert 512MB
Did you try without single quotes?

[PHP]$query7 = "select count(strike) from surfaces where undl_indx = $undl_indx and strike = $user_input_strike and expire_date = $expire_date1 and call_put = '$call_put2' ";[/PHP]
Escape the quotes in $call_put2.
Jul 25 '07 #2
orfiyus
36
I dont remember if I tried this before. I thought I did and that it just didnt work. But it just worked with the single quotes just now after you told me to try it. I didnt even have to escape in $call_put2. Im so tired and Ive been staring at this script all day. It took me 20 min to get my post coherent enough for another person to understand it. Anyway thanks for taking the time to look through this and respond.
Peace
Jul 25 '07 #3
pbmods
5,821 Expert 4TB
Heya, orfiyus.

Not sure about Oracle, but here's how I'd do it for MySQL:

Expand|Select|Wrap|Line Numbers
  1. $query7 = "
  2. SELECT
  3.         COUNT(`strike`)
  4.             AS `count`
  5.     FROM
  6.         `surfaces`
  7.     WHERE
  8.     (
  9.             `undl_indx` = '{$undl_indx}'
  10.         AND
  11.             `strike` = '{$user_input_strike}'
  12.         AND
  13.             `expire_date` = '{$expire_date1}'
  14.         AND
  15.             `call_put` = '{$call_put2}'
  16.     )";
  17.  
Note the use of backticks, and that all values are quoted. Again, Oracle might want you to do things a little differently.

I also like to enclose variables in double-quoted strings in curly-braces, but this is not strictly necessary.
Jul 25 '07 #4
orfiyus
36
Thanks pb but I already got it working. If it aint broke dont fix it. Although the way you typed is easier on the eyes. I ll go back and fix it at the end if I have time.

Peace
Jul 25 '07 #5
pbmods
5,821 Expert 4TB
Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Jul 25 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: aj70000 | last post by:
This is my query select ano,max(date),a_subject from MY_TAB where table_name='xyz' and ano=877 group by a_subject,ano order by a_subject ANO max(Date) A_Subject 877 2005-01-20...
14
by: signaturefactory | last post by:
I am trying the following query in and oleDbCommand: SELECT PartLocations.LocationName, Sum(PartsJournal.Quantity) AS SumOfQuantity, PartsJournal.PartsLotNumber FROM PartLocations INNER JOIN...
2
by: Seth Delaney | last post by:
I have a form with multiple unbound text boxes which serves as a "search form". I can enter my search parameters in the various boxes as needed and click okay. My records are then filtered to...
7
by: Riley DeWiley | last post by:
I am continually amazed by SQL's ability to humble me .... I have a toy query into a toy database that looks just like this: SELECT . FROM f, fw, w WHERE f.id = fw.fid and fw.wid = w.id and...
4
by: carl.barrett | last post by:
Hi, I have a list box that displays 2 columns. Behind it sits a query with five columns. These are Column1 (DOB), column2 (a concatenated string of Surname Forname, Title), Column3 (Surname),...
3
by: dskillingstad | last post by:
I'd appreciate any help I can get. I'm not sure what I'm doing wrong, but.... I've searched these groups for some solutions but no luck. I have an unbound form (frmSearch), with several unbound...
24
by: clare at snyder.on.ca | last post by:
I have a SQL query I need to design to select name and email addresses for policies that are due and not renewed in a given time period. The problem is, the database keeps the information for every...
5
by: sara | last post by:
I have reports that run from a form where the user can choose a date range, or they run automatically for a week in the "Weekly Reports" option. I created 2 queries and 2 reports - one query...
8
by: p | last post by:
I'm trying to put a query into VBA code and its giving me difficulties. I would like to put the following query: SELECT tbl_Workload.Priority, tbl_Workload.Number AS Num, tbl_Workload.Name,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.