Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-08-2010, 09:46 PM   PM User | #1
tkaeer
New Coder

 
Join Date: Dec 2009
Location: Sweden
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
tkaeer is an unknown quantity at this point
Variable in array help..

Hey!
I'm trying to put a variable in my array I have but it doesn't work ..

Here is my script with a variable:
PHP Code:
while($idet mysql_fetch_array($q_rostning)){
$namnen = array($idet['Namn']);
if (!
in_array("tkaeer"$namnen)){ 
And this will not work for me ..

Here is my script with some random data:
PHP Code:
while($idet mysql_fetch_array($q_rostning)){
$namnen = array("tkaeer""randomname""anotherrandomname");
if (!
in_array("tkaeer"$namnen)){ 
Is there possible to to this kind of thing?

/Tkaeer

Last edited by tkaeer; 01-08-2010 at 09:50 PM..
tkaeer is offline   Reply With Quote
Old 01-08-2010, 10:33 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
$namnen will only ever be a 1 element array since you always overwrite it.
To me, it looks like check for in array should also be outside of the while loop:
PHP Code:
$namnen = array();
while (
$idet mysql_fetch_array($q_rostning))
{
    
$namnen[] = $idet['Namn'];
}

if (!
in_array("tkaeer"$namnen)) // Or it could be a variable or whatever.
{
    print 
"That name is not in the list.";

__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 01-08-2010, 11:29 PM   PM User | #3
tkaeer
New Coder

 
Join Date: Dec 2009
Location: Sweden
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
tkaeer is an unknown quantity at this point
Quote:
Originally Posted by Fou-Lu View Post
$namnen will only ever be a 1 element array since you always overwrite it.
To me, it looks like check for in array should also be outside of the while loop:
PHP Code:
$namnen = array();
while (
$idet mysql_fetch_array($q_rostning))
{
    
$namnen[] = $idet['Namn'];
}

if (!
in_array("tkaeer"$namnen)) // Or it could be a variable or whatever.
{
    print 
"That name is not in the list.";


Thanx!, Really helped me!
tkaeer is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 11:21 AM.


Advertisement
Log in to turn off these ads.