473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

HELP! Selecting Array Rows based on an array of field=>value s

Here's the code i have:

$db = array(); //main array
$db['main'] = array(); //table `main`
$db['main'][] = array('id'=>0,
'username'=>'joshfrench','userpass'=>'password','u serlevel'=>'admin');
//row
$db['main'][] = array('id'=>1,
'username'=>'bob_smith','userpass'=>'psswrd','user level'=>'user');
//row

function trim_value(&$value){
$value = strtolower(trim($value));
}
function fdb_select($fields = "*", $table, $where = false, $limit =
false){
global $db;
$retv = $db[$table];

//LIMIT RESULTS TO FIELDS
if(strrpos($fields, ",") === false){$field=array($fields);}else{$field
= explode(",", $fields);};
array_walk($field, "trim_value");
$all_fields = array_keys($retv[0]);
if($fields == '*'|| is_null($fields)){$field = $all_fields;};
$field = array_uintersect($all_fields, $field, "strcasecmp");
$retvi = array();
foreach($retv as $num =$row){
foreach($row as $fname =$fvalue){
$fname1 = strtolower($fname);
if(in_array($fname1, $field)){
$retvi[$num][$fname]=$fvalue;
};
};
};
//DONE LIMITING TO FIELDS
if($where != false){

//UP TO HERE IT WORKS FINE
//LIMIT TO WHERE CLAUSE
$retvj = array();
foreach($retvi as $num =$row){
//IN THE ROW
foreach($where as $k =$v){
//IF ROW MEETS ALL REQUIREMENTS
if($row[$k] == $v){
$retvj[] = $retvi[$num]; //Keep that row
};
};
};
//DONE LIMITING TO WHERE CLAUSE
};
$retvi = (isset($retvj)) ? $retvj:$retvi;
//SEND A FINAL ASSOCIATIVE ARRAY
return $retvi;
};
print_r(fdb_select("*", "main", array('id'=>"1",
"username"=>"joshfrench")));

the previous code outputs this:

Array
(
[0] =Array
(
[id] =0
[username] =joshfrench
[userpass] =password
[userlevel] =admin
)

[1] =Array
(
[id] =1
[username] =bob_smith
[userpass] =psswrd
[userlevel] =user
)

)

if i make the last option array('id'=>'1'), it does what i want.

HELP!!

Oct 22 '06 #1
0 1303

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: brendan | last post by:
Sorry this isnt a cross post .. i just didnt get any help from alt.php. I have a website which utilises post forms for navigation in some areas. Problem is, when *some* users hit the BACK button...
1
by: Bob Stearns | last post by:
Unshift only takes values, as I read it. I have a real need to Unshift key=>value pairs. Help.
31
by: da Vinci | last post by:
OK, this has got to be a simple one and yet I cannot find the answer in my textbook. How can I get a simple pause after an output line, that simply waits for any key to be pressed to move on? ...
3
by: He Shiming | last post by:
Hi Folks, Happy holidays! I have a question regarding STL multimap. Basically, the current multimap<int,int> look like this: key=>value 1=>10, 1=>20, 1=>30,
3
by: leeaids | last post by:
Hi, I am hoping somebody can help me. Normally to use the file upload feature in an html page, users must either select or type in a file to upload then click on button or link to initiate...
1
by: Chuck | last post by:
I have a query that uses the query with the critera set to . We I run the query the msgbox pops up asking for the name information to be entered, but on the top (blue background) of the message box...
4
by: Andrzej Wegrzyn | last post by:
Hi, I had a portal that worked before, and over 5 months period JavaScript errors started to show up on all forms where I have datagrids. Using: IE 6.0, WIN XP, IIS 5.1, Framework 1.1 ...
4
by: Mr. SweatyFinger | last post by:
My gridview is ties to a table of states. These are United States states, from the greatest land in the world. The numeric column is an autonumber, hopefully you've heard of that. If not please...
8
by: gelligokul | last post by:
Hello frens i want to retrieve <asp:label> value from the code behind in c# can any one help me...
1
by: otiose3 | last post by:
I've been ploughing through the archives here, but I can't seem to find a solution for my situation... Essentially, I want to run the JQuery script that is in the "value" attribute of my <option>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.