Current location: Hot Scripts Forums » Programming Languages » PHP » simple query code with if statement

simple query code with if statement

Reply
  #1  
Old 11-06-09, 11:35 AM
hscorp hscorp is offline
Newbie Coder
 
Join Date: Nov 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
simple query code with if statement

what i need
i got field in the database with 0 or 1 content

what i want is simple code

if 0 do nothing if 1 make a redirect

in php page
Reply With Quote
  #2  
Old 11-06-09, 11:49 AM
protocode protocode is offline
Newbie Coder
 
Join Date: May 2009
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
I assume you want only one result from your table. Secondly, you should save the url you want to redirect to in your result row.

PHP Code:
$query "SELECT field, url FROM table LIMIT 1";

$result mysql_query($query);

$row mysql_fetch_assoc($result);

if(
$row['field'] == 0){
}else{
header("location:$row['url']");

"field" is your 1 or 0 query-array element
Reply With Quote
  #3  
Old 11-06-09, 12:15 PM
hscorp hscorp is offline
Newbie Coder
 
Join Date: Nov 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
used this but didn't work

PHP Code:
if($file_info['deleted'] == 0){
}else{
header('location:http://www.mirrorzian.com/deleted.php');
}; 
Reply With Quote
  #4  
Old 11-06-09, 01:14 PM
protocode protocode is offline
Newbie Coder
 
Join Date: May 2009
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
First thing, please provide a sample code.

What comes to mind; does the element $file_info['deleted'] equal 0?

If it does in fact equal 1, however, it should work.

I just ran a sample bit to test your if statement. As written, it worked for me.
Reply With Quote
  #5  
Old 11-06-09, 01:25 PM
hscorp hscorp is offline
Newbie Coder
 
Join Date: Nov 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
done it i had an error

Code:
Warning: Cannot modify header information - headers already sent
and i didn't see this error so i thought it wasn't working but i've edit the redirect and now it works thanks man
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
If Statement With Query !!! phpfreek PHP 3 10-03-06 04:28 AM
Echo Inside If Statement sixflagsga PHP 1 07-19-06 05:43 PM
Very Simple Small Project - I got $$$ Fabolous Job Offers & Assistance 5 07-23-05 03:09 PM
Simple visitors ip code? netshark PHP 2 07-18-05 05:38 PM
Need a simple user code! dave111 Script Requests 1 09-07-03 10:48 AM


All times are GMT -5. The time now is 08:30 PM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2 (Unregistered)