Page 1 of 1
How To get Index from Array and Select Spicific array
Posted: Mon May 18, 2009 10:51 pm
by shafiq2626
Hello!
i stored values in array like id,name,password and email. like
Code: Select all
<?php $databse=array(
"ID"=>"1", array("name"=>"shafique", "password"=>"123", "email"=>"email@email.com"),
"ID"=>"2", array("name"=>"sha", "password"=>"12", "email"=>"sha@email.com"),
"ID"=>"3", array("name"=>"aaa", "password"=>"13", "aaa"=>"aaa@email.com")
); ?>
And after i want to log in from a form input to against a specific array value like name and password And also these arrays values should be Add ,edit,delete, these values from take the values by input .
please help me.
thanks
Re: How To get Index from Array and Select Spicific array
Posted: Tue May 19, 2009 12:47 am
by Christopher
What you are actually doing is this:
Code: Select all
<?php $databse=array(
"ID"=>"1",
array("name"=>"shafique", "password"=>"123", "email"=>"email@email.com"),
"ID"=>"2",
array("name"=>"sha", "password"=>"12", "email"=>"sha@email.com"),
"ID"=>"3",
array("name"=>"aaa", "password"=>"13", "aaa"=>"aaa@email.com")
); ?>
The three arrays with be assigned indexes 0, 1, 2. And I assume that 'ID' will be 3, but that should give an error. You should use var_dump() or print_r to show $databse so you can see what you are creating.
Re: How change Array and with Spicific array value
Posted: Tue May 19, 2009 3:19 am
by shafiq2626
Helo! I got Index now i want to change an array attributes to get the value from input.
like
Code: Select all
array("name"=>"shafique")
replace with
array("name"=>"ssssss")
how this can possible .
please help me.
thanks
array output problem
Posted: Tue May 19, 2009 10:39 pm
by shafiq2626
hello!
i Make This Array
Code: Select all
$databse=array(
"ID"=>"1",
array("name"=>"shafique", "password"=>"123", "email"=>"email@email.com"),
"ID"=>"2",
array("name"=>"sha", "password"=>"12", "email"=>"sha@email.com"),
"ID"=>"3",
array("name"=>"aaa", "password"=>"13", "email"=>"aaa@email.com"));
for output
<?php
Code: Select all
foreach($databse as $key=>$value)
{
?>
<tr><td><?php echo $value['name'];?></td><td><?php echo $value['password'];?></td><td><?php echo $value['email'];?></td></tr>
<?php }?>
the result show
3 3 3
shafique 123 email@email.com
sha 12 sha@email.com
aaa 13 aaa@email.com
why the top row the values 3 3 3
the three rows are true but top row why display.
display please help
thanks
Re: How To get Index from Array and Select Spicific array
Posted: Tue May 19, 2009 11:26 pm
by Christopher
Please do not double post.
Did you use var_dump() or print_r() like I suggested so you can see what your array actually looks like?
Re: How To get Index from Array and Select Spicific array
Posted: Wed May 20, 2009 12:09 am
by shafiq2626
arborint wrote:Please do not double post.
Did you use var_dump() or print_r() like I suggested so you can see what your array actually looks like?
when i use var_dump($database);
then result show
array(4) { ["ID"]=> string(1) "3" [0]=> array(3) { ["name"]=> string(8) "shafique" ["password"]=> string(3) "123" ["email"]=> string(15) "
email@email.com" } [1]=> array(3) { ["name"]=> string(3) "sha" ["password"]=> string(2) "12" ["email"]=> string(13) "
sha@email.com" } [2]=> array(3) { ["name"]=> string(3) "aaa" ["password"]=> string(2) "13" ["email"]=> string(13) "
aaa@email.com" } }
Re: How To get Index from Array and Select Spicific array
Posted: Wed May 20, 2009 12:44 am
by Christopher
A good PHP development trick is to do this:
Code: Select all
echo '<pre>' . print_r($var, 1) . '</pre>';
If you look at the array that way it will look something like this (but more expanded):
Code: Select all
array(4) {
["ID"]=> string(1) "3"
[0]=> array(3) { ["name"]=> string(8) "shafique" ["password"]=> string(3) "123" ["email"]=> string(15) "email@email.com" }
[1]=> array(3) { ["name"]=> string(3) "sha" ["password"]=> string(2) "12" ["email"]=> string(13) "sha@email.com" }
[2]=> array(3) { ["name"]=> string(3) "aaa" ["password"]=> string(2) "13" ["email"]=> string(13) "aaa@email.com" }
}
So it looks like your ['ID'] key is not doing what you thought is was doing. But the other elements look like what you want.