473,385 Members | 1,324 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,385 software developers and data experts.

Simple Beginner Question about SELECT WHERE

I have this line, to select a controlled number of values.
Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query("SELECT * FROM AFL_BoE_Chapters WHERE ((boe_type='Chapter Index List') AND ('boe_required_level' >= '".$lvl."' )) ORDER BY boeID ASC")
$lvl is gotten from a number passed on via sessions.
It is used as a 'level' for the user.
So this result is supposed to select only the content that is of the same level as the user, or higher.

The problem is that it selects content which level is above the user, though it works otherwise, but if you might know why this happens.
Jan 25 '10 #1
2 1682
dgreenhouse
250 Expert 100+
At first look, I think you should drop the single-quotes surrounding the column name: boe_required_level.

i.e. 'boe_required_level' >= '".$lvl."' ) should be: boe_required_level >= '".$lvl."' )
- or should be: boe_required_level >= ".$lvl." ) if boe_required_level and $lvl are numeric


The way the query is constructed,'boe_required_level' is always going to be >= '1', and you'll select all records.

Basically, you're only testing a string against a string - not a column against a value.

At least that's how it looks to me...
Jan 26 '10 #2
boe_required_value is a database row. I only put on the single-quotes to check if it would do any difference, when it didnt work without them.
And yeah $lvl is numeric, it can be from 1 to anything higher, depending on what level the user is set to.

I tried echoing the values, and they are all set, but it seems as if the $lvl inside the query maybe isn't, since it selects everything. So could it be a syntax error?
Usually, using '".$lvl."' single-quotes and double-quotes and punctuation always worked..

Edit: I made it work, I had to turn the arrow operator the other way around, to check for 'equal and lower' instead of 'equal and higher'. lol

It will now only display the content which match the user's level, setting the max level at the user's level and will display anything below or equal to it.

Thanks dgreenhouse.
Jan 26 '10 #3

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

Similar topics

4
by: Dariusz | last post by:
I am a beginner in PHP and MySQL, and am working through a book and various online tutorials on PHP and MySQL and now stuck - installed everything on "localhost" and it all works fine. My question...
10
by: Chris Vinall | last post by:
I'm an SQL beginner and this is driving me nuts as it seems simple enough but I can't figure it out. I have a table that looks like: ID: int MajorVersion: int MinorVersion: int Content:...
11
by: JKop | last post by:
Take the following simple function: unsigned long Plus5Percent(unsigned long input) { return ( input + input / 20 ); } Do yous ever consider the possibly more efficent:
17
by: Paul | last post by:
HI! I get an error with this code. <SCRIPT language="JavaScript"> If (ifp==""){ ifp="default.htm"} //--></SCRIPT> Basicly I want my iframe to have a default page if the user enters in...
9
by: mkdunaway3 | last post by:
I'm just starting out here and I keep running into a basic problem. I build a set of tables: First Names, Last Names, Member Status. I bring these together in a table, Persons' Name & Status,...
6
by: jan | last post by:
My apologies for being a javascript beginner and asking such a basic question. This is probably so easy that nobody ever mentions it. Tutorials and places that tell of basic commands never seem to...
10
by: R.A.M. | last post by:
Hello, I am trying to learn SQL Server. I need to write a trigger which deletes positions of the document depending on the movement type. Here's my code: set ANSI_NULLS ON set...
3
by: Jeff | last post by:
....another beginnger question. I have a web application in .net v2 VB that requires multiple reads from sql tables where each read is slightly different - so the sql select statements also differ...
11
by: TokyoJ | last post by:
I run a small camp in Alaska for kids and my director is asking for a web form. Could someone please have a look and offer some advice on where I'm making mistake(s)? I'm using the RegExp function...
6
by: lgerhardx | last post by:
First of all, please forgive my newness to the language. I have had much experience programming...but not in C! :) I am modifying a program designed in LabWindows/CVI, which as far as I can...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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...

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.