User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 392,047 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,290 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 803 | Replies: 18 | Solved
Closed Thread
Join Date: Dec 2007
Posts: 336
Reputation: OmniX is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
OmniX's Avatar
OmniX OmniX is offline Offline
Posting Whiz

How to check a variable's content?

  #1  
May 20th, 2008
I wish to check if a variable (I am pulling the variable as mysql_fetch_array) contains the number 2008 in it. If so it is displayed.

Now I have the display working fine but it displays everything and I want to optimize it to just show the variables containing 2008.

Any ideas?

Thanks, Regards X.
AddThis Social Bookmark Button
 
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 238
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: How to check a variable's content?

  #2  
May 20th, 2008
Umm..
  1. if($row['col1'] == "2008") {
  2. //print
  3. } //else do nothing
If the record in the table has more than 2008, for example, some text with it, you can try it this way.
  1. <?php
  2. $str = "test - 2008 is as boring as 2007";
  3. if(strstr($str,"2008")) {
  4. echo "2008 found!";
  5. } else {
  6. echo "2008 not found!";
  7. }
  8. ?>
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
 
Join Date: Dec 2007
Posts: 336
Reputation: OmniX is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
OmniX's Avatar
OmniX OmniX is offline Offline
Posting Whiz

Re: How to check a variable's content?

  #3  
May 21st, 2008
I just solved it using stristr and then found your solution (never got notified of your message)whats the difference between the functions?

Thanks once again nav.
 
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 238
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: How to check a variable's content?

  #4  
May 21st, 2008
stristr does the same as strstr. But stristr is case-insensitive. ie., stristr("This is a test","IS"); will return true since "IS" is found in "This". Whereas, strstr("This is a test","IS"); will return false (since "IS" doesn't match with "is").

Cheers,
Nav
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
 
Join Date: Dec 2007
Posts: 336
Reputation: OmniX is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
OmniX's Avatar
OmniX OmniX is offline Offline
Posting Whiz

Re: How to check a variable's content?

  #5  
May 21st, 2008
Ahh ok thanks nav, genious as usual

On to the next problem XD

If you get a chance to look at my double click problem (requires 2 clicks to be updated) I think that covers everything I require for this project XD
 
Join Date: Jun 2008
Posts: 5
Reputation: Merlin333 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Merlin333 Merlin333 is offline Offline
Newbie Poster

Re: How to check a variable's content?

  #6  
Jun 4th, 2008
I read your post above with great interest. I have a phpBB forum and am the most beginning of beginners. I have what seems to me an easy question for someone beyond my "knowledge". I am trying to construct a simple if then else statement that I can wrtie that will test for the "is the user logged in " variable (which I don't know) - test for true or false and allow me to display a guest message.

This is so simple Im a little embarassed (lol) but I would appreciate some help.

Thanks,

This is the "bones" of what I'm trying to.
--------------------------------------------------------------
$logged = variable_name_that contains_login_value


<?php
if $logged = variable_name_that contains_login_value
display welcome/signup banner;
} else {
Do nothing;
}
?>
--------------------------------------------------------------
 
Join Date: Dec 2007
Posts: 336
Reputation: OmniX is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
OmniX's Avatar
OmniX OmniX is offline Offline
Posting Whiz

Re: How to check a variable's content?

  #7  
Jun 4th, 2008
You should post your problem in a new thread but anyways.

Few minor things wrong with your code:

<?php
if ($logged == "variable_name_that contains_login_value") 
display welcome/signup banner;
} 
?>

Hope that helps

Regards, X
Last edited by OmniX : Jun 4th, 2008 at 11:54 pm.
 
Join Date: Jun 2008
Posts: 5
Reputation: Merlin333 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Merlin333 Merlin333 is offline Offline
Newbie Poster

Re: How to check a variable's content?

  #8  
Jun 5th, 2008
Originally Posted by OmniX View Post
You should post your problem in a new thread but anyways.

Few minor things wrong with your code:

<?php
if ($logged == "variable_name_that contains_login_value") 
display welcome/signup banner;
} 
?>

Hope that helps

Regards, X


Thanks for the reply it is much appreciated. My only remaining questions are:

1. Is the correct name of the variable $logged
2. What values do it contain or return

Thanks again
 
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 238
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: How to check a variable's content?

  #9  
Jun 5th, 2008
Umm.. There are some things you need to know before 'creating' a variable. A variable can't start with an integer. For example, $123variable is not a valid variable name. More about it here..
http://nl2.php.net/language.variables
And $logged will have the value that you assigned to it. For example,
  1. <?php
  2. $logged = "yes";
  3. if($logged == "no") {
  4. echo "Not logged in";
  5. } else {
  6. echo "Logged in..";
  7. }
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
 
Join Date: Dec 2007
Posts: 336
Reputation: OmniX is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
OmniX's Avatar
OmniX OmniX is offline Offline
Posting Whiz

Re: How to check a variable's content?

  #10  
Jun 5th, 2008
Nav has answered your question.

If you still dont understand, cut out a section of your code and we will try to help you.
 
Closed Thread

Only community members can participate in forum threads. You must register or log in to contribute.

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

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 11:23 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC