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

show literal when column contains certain value

I have an index.php page that does a query from a database of users, in this database there is a field called isadmin.. I am wondering if it would be possible to do some type of IF statement based on that field having a certain value? Some how fetching the status of that field, like if field=1 then echo "this" and if it equals 0 then display nothing..?

Thanks
Mar 30 '08 #1
5 2128
hsriat
1,654 Expert 1GB
I have an index.php page that does a query from a database of users, in this database there is a field called isadmin.. I am wondering if it would be possible to do some type of IF statement based on that field having a certain value? Some how fetching the status of that field, like if field=1 then echo "this" and if it equals 0 then display nothing..?

Thanks
That can be done by sql..
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM `your_table` WHERE `field_1`='value_1' AND `isadmin`='required_value'
If you want to try that with an if in PHP, do it like
[PHP]
while ($row = myqsl_fetch_array($sql))
{
if ($row['isadmin']=="required_value")
{
echo "string to be printed";
}
}[/PHP]

But the SQL solution is recommended.
Mar 30 '08 #2
ronverdonk
4,258 Expert 4TB
Sorry for bursting in, but I think what OP means is that he/she wants to replace a selected column value using an IF function. As the following example: when field_1 equals 1 it will be shown as 'this'
Expand|Select|Wrap|Line Numbers
  1. SELECT *, IF(field_1=1, 'this', field_1) AS field1_new FROM your_table;
Ronald
Mar 30 '08 #3
ronverdonk
4,258 Expert 4TB
This is a MySQL question so I will move it to the MySQL forum.

moderator
Mar 30 '08 #4
hsriat
1,654 Expert 1GB
Sorry for bursting in, but I think what OP means is that he/she wants to replace a selected column value using an IF function. As the following example: when field_1 equals 1 it will be shown as 'this'
Expand|Select|Wrap|Line Numbers
  1. SELECT *, IF(field_1=1, 'this', field_1) AS field1_new FROM your_table;
Ronald
ohh... if that's the case, then I guess I misinterpreted the question.

Harpreet
Mar 30 '08 #5
ronverdonk
4,258 Expert 4TB
ohh... if that's the case, then I guess I misinterpreted the question.

Harpreet
Happens to me frequently. Sometimes it is hard to understand what the OP means, because the real question is more or less hidden in the stated question.

Ronald
Mar 30 '08 #6

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

Similar topics

2
by: Tim Williams | last post by:
I'm trying to write a simple python program to access a MySQL database. I'm having a problem with using MySQLdb to get the results of a SQL command in a cursor. Sometimes the cursor.execute works,...
1
by: Alastair Cameron | last post by:
VB6, MSXML 3.2 installed: Q1. I am having a problem selecting nodes with XPATH expressions when an attribute values contain backslashes (\\) in as part of its value: For example the...
1
by: Joshua Ammann | last post by:
Hello, I'm trying to export a query containing contact information, including a field. Some zip codes have one or two leading zeros, for example, San Juan, PR (00927) and Springfield, MA...
1
by: Adil Bohoudi | last post by:
Hi all, i'm using a datagrid to show somedata retrieved from an sql-server 2000. this datagrid contains two columns a startdate and an enddate column. i used a storedprocedure to get both...
130
by: Daniel Manes | last post by:
I'm baffled. I have a column in a SQL Server Express database called "Longitude," which is a float. When I view the table in a DataGridView, some of the numbers, which only have two decimal places...
10
by: william | last post by:
#include <stdio.h> int main() { char *str=NULL; char x="today is good!"; printf("%s", str); str=strtok(x," "); if (str=="today") //<==here is line that confuses me printf("they equals!\n");
0
VbaNewbee
by: VbaNewbee | last post by:
I have a form with a few filters. Once the user clicks "search button", the code first evaluates my filters, then shows the query results in a List Box" titled backschedule. I have a few text...
2
by: Lucas | last post by:
Hi, I want to display an exception in a javascript alert and I'm rendering that client code using ClientScript.RegisterStartupScript(GetType(), key,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.