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.

PHP Forum


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



Freelance Jobs

Reply
if else if and else question
Old 04-08-2010, 03:29 PM if else if and else question
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
Hi all,

I have a statment that goes

PHP Code:
if ($test){
//do this

}elseif(test2){
//insert into database blar blar
insert data into databse 

}else{
Echo
" error one of the test filed try again";

What I want to know is before test 2 is run, I need to search the database and see if the data is already entered into the database. And if it is dont insert the data but give error message what the best way of doing this ??
__________________

Please login or register to view this content. Registration is FREE

Last edited by chrishirst; 04-08-2010 at 05:49 PM..
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
 
Register now for full access!
Old 04-08-2010, 04:26 PM Re: if else if and else question
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
You could do something like this:
PHP Code:
function checkDB()
{
     
//check if the data is already in the database
     
if(/*data is in database */)
          return 
true;

     return 
false;
}

if (
$test){
//do this

}elseif($test2 && !checkDB()){
//insert into database blar blar
insert data into databse 

}else{
Echo
" error one of the test failed try again";

__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 04-08-2010, 04:31 PM Re: if else if and else question
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
what the best way to check the database with a select from table where this like that
__________________

Please login or register to view this content. Registration is FREE
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 04-08-2010, 05:36 PM Re: if else if and else question
nayes84's Avatar
Extreme Talker

Latest Blog Post:
Difference between ASP And JSP
Posts: 232
Name: John
Location: Tokyo
Trades: 0
Quote:
Originally Posted by millwalll View Post
what the best way to check the database with a select from table where this like that
I like
PHP Code:
if(mysql_result(mysql_query("select count(*) from table_name where something limit 1"),0)>0)
   
//data already exist
else
   
//data don't exist 
I think this is the fastest and less memory consuming way
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

if(I'm("Helpful")) Add_Talkupation("nayes84");

Last edited by nayes84; 04-08-2010 at 05:37 PM..
nayes84 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to if else if and else question
 

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.19381 seconds with 12 queries