acook Posted January 29, 2008 Share Posted January 29, 2008 I have a simple page that queries a database and stores the results in an array called $results_array (see below). <?php $db_user = ""; $db_pass = ""; $dsn = "OPASRPT"; $conn = odbc_connect($dsn, '', ''); $query = "SELECT Incident_Id, Affected_Item__, Severity, Facility, Customer_Name__, Assignee_Group__, Assignee_Individual, Status_History_Closed_TIME, Status_History_Closed_USER, Submitter, Create_date, VIP, Control_Panel_Create, FCR_Candidate, Source, Assignee_Group_Counter FROM Incident_Management"; $result = odbc_exec($conn, $query); $results_array = array(); while(odbc_fetch_row($result)) { $results_array[] = array( 'Incident_Id' => odbc_result($result, 1), 'Affected_Item' => odbc_result($result, 2), 'Severity' => odbc_result($result, 3), 'Facility' => odbc_result($result, 4), 'Customer_Name' => odbc_result($result, 5), 'Assignee_Group' => odbc_result($result, 6), 'Assignee_Individual' => odbc_result($result, 7), 'Closed_Time' => odbc_result($result, , 'Closed_User' => odbc_result($result, 9), 'Submitter' => odbc_result($result, 10), 'Create_Date' => odbc_result($result, 11), 'VIP' => odbc_result($result, 12), 'Control_Panel_Create' => odbc_result($result, 13), 'FCR_Canidate' => odbc_result($result, 14), 'Source' => odbc_result($result, 15), 'Assignee_Group_Counter' => odbc_result($result, 16), ); } foreach($results_array AS $this_row) { echo"{$this_row['Incident_Id']}<br>"; } odbc_close($conn); ?> My question is, is it possible to perform operations on the stored values? For example, let's say I wanted to count the number of "Incident_Id"s. Could this be done? Also, is it possible to run a function that only counts Severity 4's from "Severity"? Or can I do any compare functions? I know this can all be achieved by using more queries, but I'd like to avoid that. It seems easier to only query the DB once and let PHP do the work. Please help. Quote Link to comment https://forums.phpfreaks.com/topic/88453-running-queries-from-an-array/ Share on other sites More sharing options...
trq Posted January 29, 2008 Share Posted January 29, 2008 I know this can all be achieved by using more queries, but I'd like to avoid that. It seems easier to only query the DB once and let PHP do the work. Please help. This is in fact the wrong way around. It is usually best to query the database for the exact information you want. Of course, there are all the array functions at your displosal if you still wish to do it your way though. Quote Link to comment https://forums.phpfreaks.com/topic/88453-running-queries-from-an-array/#findComment-452783 Share on other sites More sharing options...
acook Posted January 29, 2008 Author Share Posted January 29, 2008 This is in fact the wrong way around. It is usually best to query the database for the exact information you want. Of course, there are all the array functions at your displosal if you still wish to do it your way though. Ok, so are you suggesting I run several queries within 1 php page? What I am looking to do is very complicated and might need some 20+ queries. Would this be ok? Quote Link to comment https://forums.phpfreaks.com/topic/88453-running-queries-from-an-array/#findComment-452792 Share on other sites More sharing options...
cooldude832 Posted January 29, 2008 Share Posted January 29, 2008 ODBC isn't supported in this forum exclusively, but look for a ODBC forum for support on making "better" queries 20 queries sounds extensive for somethign this basic. Quote Link to comment https://forums.phpfreaks.com/topic/88453-running-queries-from-an-array/#findComment-452800 Share on other sites More sharing options...
acook Posted January 29, 2008 Author Share Posted January 29, 2008 Yeah, what I posted was just a basic sample of what I need. Eventually I need to total certain numbers, show averages of other numbers, show how many of a certain item one has (ie, How many Severity 4's someone had), etc. That's why I was thinking PHP could do it. It would take less time to execute and save the DB the trouble of all of the queries. PS. Your profile pic seems to be some sort of molecule? Or part of a molecule... Quote Link to comment https://forums.phpfreaks.com/topic/88453-running-queries-from-an-array/#findComment-452810 Share on other sites More sharing options...
cooldude832 Posted January 29, 2008 Share Posted January 29, 2008 well ODBC is different from SQL but I'm sure you can do similar functions like structural based queries with if statements, COUNT() MAX() MIN() UNIQUE() AVG() etc in proper ODBC syntax Quote Link to comment https://forums.phpfreaks.com/topic/88453-running-queries-from-an-array/#findComment-452814 Share on other sites More sharing options...
acook Posted January 30, 2008 Author Share Posted January 30, 2008 After playing with this further, it seems that I'll be impossible to run seperate queries on the database as it is too slow and times out. I don't understand why if I have the results stored in the array, I can't manupliate them and get the data I need. The server that the PHP webserver is on is 1000x faster. I'm sure PHP can handle it. Quote Link to comment https://forums.phpfreaks.com/topic/88453-running-queries-from-an-array/#findComment-453516 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.