PHP - Can Not Retrieve Values From 3 Dimensional Array With Foreach
I am trying to iterate through a 3 dimensional array and echo out all the details. I am having a trouble with the following:
Array ( [DT_Intrinsic_mob7] => Array ( [0] => Array ( [cli] => 11111111111 [min] => 533 ) [1] => Array ( [cli] => 2222222222 [min] => 536 ) [2] => Array ( [cli] => 33333333333 [min] => 541 ) ------- SNIP ----- [46] => Array ( [cli] => 5555555555 [min] => 5471 ) ) [DT_belltel_mob7] => Array ( [0] => Array ( [cli] => 999999999 [min] => 508 ) [1] => Array ( [cli] => 8888888888 [min] => 519 ) [2] => Array ( [cli] => 7777777777 [min] => 602 ) [3] => Array ( [cli] => 7975757375 [min] => 701 ) ) ) My code looks like this: foreach ($cli_data as $key => $value){ foreach ($cli_data[$key] as $key2 => $value2){ foreach($cli_data[$key][$key2] as $key3 => $value3){ echo "key3 is $key3 \n"; echo "value is $value3['cli']"; } } echo "\n\n"; } I keep getting the following error PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/html/index.php on line Thanks Similar TutorialsHI ! I have a table which captures how customers came to be customer ie 'advertisement', 'friend' etc etc. So I want to be able to show / count that N number came from referral or advertisement. My query is simple, I select all from the Media column. This gives me a multi-dimensional array, where each table row, becomes a new sub array. I have 3000 customers ... that's a quite a few sub arrays ! So, a sample print_r of the array looks like this: Code: [Select] Array ( [0] => Array ( [media] => friend ) [1] => Array ( [media] => friend ) [2] => Array ( [media] => friend ) [3] => Array ( [media] => Coming Over From Old Site I have tried using a couple of array functions such as count(array,1) and (array_count_values($media)) but they both don't count the individual values out of the sub arrays. I'm a bit stuck - Can anyone help me ? Many Many Thanks !! Hi, I'm having problems retrieving the values from a form posting without getting a warning My form records playername, hours played and minutes played Code: [Select] <li id="input1" style="margin-bottom:4px;" class="clonedInput"> Name: <select name="player[1][userid]" id="player[1][userid]" class="playerInput" style="width: 7em;" > <option value=""></option> <?php while($row = mysql_fetch_array($sql)) { echo '<option value="'.stripslashes($row['userid']).'">'.stripslashes($row['name']).'</option>'; } mysql_data_seek($sql,0); ?> </select> <select name="player[1][hours]" id="player[1][hours]"> <option value="">Hours</option> <option value=""></option> <?php for($x = 0; $x <= 23; $x++ ) { echo '<option value="'.$x.'">'.$x.'</option>'; } ?> </select> <select name="player[1][minutes]" id="player[1][minutes]"> <option value="">Minutes</option> <option value=""></option> <?php for($y = 15; $y <= 59; $y+=15) { echo '<option value="'.$y.'">'.$y.'</option>'; } ?> </select> </li> I use some javascript to create new players as necessary so every player has a userid, hours, minutes played... After posting the query string looks like this /cLeagueHandler.php?player[1][userid]=1&player[1][hours]=3&player[1][minutes]=15&player[2][userid]=3&player[2][hours]=6&player[2][minutes]=45&submit=Save+Points player1 userid = 1 hours = 3 minutes = 15 player2....... The code i'm using to access the values is Code: [Select] print_r ($_GET); // test display form values foreach ($_GET as $key => $value) { echo '<br/>'.$key.'<br/> '; foreach ($value as $iKey => $iValue) { // Line 72 foreach ($iValue as $xKey => $xValue) { echo " The $xKey for Player $iValue is $xValue <br/>"; } } } The above code displays Array ( [player] => Array ( [1] => Array ( [userid] => 1 [hours] => 3 [minutes] => 15 ) [2] => Array ( [userid] => 3 [hours] => 6 [minutes] => 45 ) ) [submit] => Save Points ) player The userid for Player Array is 1 The hours for Player Array is 3 The minutes for Player Array is 15 The userid for Player Array is 3 The hours for Player Array is 6 The minutes for Player Array is 45 submit Warning: Invalid argument supplied for foreach() in .................cLeagueHandler.php on line 72 Line 72 is foreach ($value as $iKey => $iValue) { If anyone could help me with this it would be great appreciated.......I want to be able to build and sql string to Insert a players id, hours, minutes into a database......(obviously not incl the submit value!) Maybe this is not even the best way of approaching this.....I'm quiet new to PHP so apologies if this is long winded...I'm trying to give as much info as possible.... thanks in advance tmfl I have mysql select query shown below retrieving data from a database:
$sql = " SELECT student, sum( test_score ) as score FROM test INNER JOIN level ON test.level_id = level.level_id GROUP BY student" $result = $mysqli->query($sql, MYSQLI_STORE_RESULT); if($result) { while ($row = $result->fetch_array(MYSQLI_ASSOC)) { var_dump($row); } }On inspection of the retrieved array with var_dump(), i have these result below: array (size=2) 'John' => string 'English' (length=2) 'Score' => string '20' (length=3) array (size=2) 'Mary' => string 'Math' (length=3) 'Score' => string '35' (length=3) array (size=2) 'Samuel' => string 'Physics' (length=3) 'Score' => string '5' (length=3)How do I get at and print out the highest score from this set of array values within this context. I tried this echo max($row['count']) but i understandably got this feedback: Warning: max(): When only one parameter is given, it must be an array Thanks. To generate the stockroom drop down list function einv_generateStockrmSelectDropdown($Stockrm,$field,$dropdown) { //connect to database base_connectDatabase(); echo "<select id=\"stockrm\" name=\"".$field."[]\" multiple=\"multiple\" style=\"align:left\" class=\"form-control\">"; if (isset($Stockrm) && ($Stockrm != "")) { $stockrmname = einv_getStockrmDetail($Stockrm); echo "<option value=\"". $Stockrm ."\">". $stockrmname['einv_stockrm_name'] ."</option>"; } else { $Stockrm = 0; } $getStockrmSQL = base_executeSQL("SELECT * FROM einv_stockroom WHERE einv_stockrm_id<>" . $Stockrm . " ORDER BY einv_stockrm_name"); while ($Stockrmdata_row = base_fetch_array($getStockrmSQL)) { if (base_num_rows($getStockrmSQL)!= 0) { echo "<option value=\"".$Stockrmdata_row['einv_stockrm_id']."\">".$Stockrmdata_row['einv_stockrm_name']."</option>"; } } echo "</select>"; echo "<script src=\"../terms_base/js/jquery.multiple.select.js\"></script>"; //Input some codes to split the dropdown and make it into the setSelects. By default, the first time = AutoSelectAll if(isset($dropdown) && ($dropdown != "")) { //dropdown = 1;2;3 $SDDArrays = explode(";", $dropdown); $countTrap0 = count($SDDArrays); $drop = "$('#stockrm').multipleSelect(\"setSelects\", ["; $counting = 1; foreach ($SDDArrays as &$value) { if ($countTrap0 != $counting) { $drop .= "'". $value . "',"; } else { $drop .= "'". $value . "'"; } $counting++; } $drop .= "]);\n"; } elseif (isset($dropdown)) { //dropdown= $drop = "$('#stockrm').multipleSelect(\"uncheckAll\")"; } else { // $drop = "$('#stockrm').multipleSelect(\"checkAll\")"; } echo "<script>\n"; echo "$(function() {\n"; echo "".$drop.""; echo "});\n"; echo "$(\"#stockrm\").multipleSelect({ onClose: function() { document.getElementById('search').click(); }});\n"; echo "$(\"#stockrm\").multipleSelect();\n"; echo "</script>"; //close the database base_closeDatabase(); }add stockroom function //This function is use to add new stock room //code = stock room code //name = stock room name //desc = stock room description //remark = stock room remark //cat = stock room category function einv_addStockrm($code,$name,$desc,$remark,$cat) { //connect to database base_connectDatabase(); $User = base_getUserDetail($_SESSION['uID']); base_executeSQL("INSERT INTO einv_stockroom (einv_stockrm_code, einv_stockrm_name, einv_stockrm_desc, einv_stockrm_remark, einv_stockrm_cat) VALUES ('" . $code . "', '" . $name . "', '" . $desc . "', '" . $remark . "', '" . $cat . "')"); base_addTransactionLog('Manage Stock Room', 'Add', " Stock Room Code = " . $code . " || Stock Room Name = " . $name . " || Stock Room Description = " . $desc . " || Stock Room Remark = " . $remark . " || Stock Room Category = " . $cat . " "); //go to stock room page echo '<script type="text/javascript">' . "\n"; echo 'window.location="../einventory/stockrm_list.php";'; echo '</script>'; //close the database base_closeDatabase(); } Edit stockroom function einv_editStockrm($srid,$code,$name,$desc,$remark,$cat) { //connect to database base_connectDatabase(); $User = base_getUserDetail($_SESSION['uID']); $Stockroom = einv_getStockrmDetail($srid); base_executeSQL("UPDATE einv_stockroom SET einv_stockrm_code='" . $code . "', einv_stockrm_name='" . $name . "', einv_stockrm_desc='" . $desc . "', einv_stockrm_remark='" . $remark . "', einv_stockrm_cat = '" . $cat . "' WHERE einv_stockrm_id=" . $srid . ""); base_addTransactionLog('Manage Stock Room', 'Edit', " Stock Room Code = " . $code . " || Stock Room Name = " . $name . " || Stock Room Description = " . $desc . " || Stock Room Remark = " . $remark . " || Stock Room Category = " . $cat . " "); //go to stock room page echo '<script type="text/javascript">' . "\n"; echo 'window.location="../einventory/view_stockrm.php?id='. $srid .'";'; echo '</script>'; //close the database base_closeDatabase(); } I have a dropdown list named **Stockroom** where it displays an array of values. Example: **Stockroom** 1. [A] 2. [b] 3. [C] When user clicks on [A], it will display relevant data fields that [A] possess (appears below stockroom ddl). And as user clicks on [b], there is an onchange function that will then show [b] data fields (fields in A is deleted and replaced with B). I am able to add the initial values however, as i want to edit and change the stockroom from [A] to [b] which will result in a whole new data to be stored, i am unable to do so. Any ideas? I believe i have to amend my edit stockroom function where i require a set of coding such as If the array is selected, i have to delete existing data and add new data in accordance to the selected ID. Edited by mac_gyver, 14 January 2015 - 07:05 AM. code tags around posted code please Hi I am new this forum and looking for some much appreciated help with something that has me stumped. I have extracted regions from image names in a directory. example: 'edinburgh_castle_(Edinburgh).jpg' (Extracted Edinburgh from in-between the brackets) So I have a list of Regions, extracted from all the various image names in the directory which I want to populate into a dynamic drop down menu for filtering purposes. Here's my issue... I want there to be only one 'Edinburgh' option appearing in my drop down menu. I don't want duplicates. Here is my code so far. php: [Select]
hi, i’m currently facing a new problem (i managed to use array_unique function successfully but i face this problem)with my php loop. i couldn’t seem to increment in my foreach loop to get the value of an array. $update_id1=Array ( [0] => 398 [1] => 397 [2] => 393 [3] => 391 [8] => ); //$i=0; foreach ($update_id1 as $i => $v) { $ex= explode(",", $v); $unique=array_unique($ex); //f$ketch username from update table in db and inject it to the feed query. $imp_id= implode(',', $ids); //$id1=$ids[$i]; // $x=0; // for($x=0;$x<count(unique);$x++){ echo 'ids:- '.$i; print_r($unique[$i]); echo '<br>'; //} $totalUpdates=$project->totalUpdates($ids[$i],$_SESSION['uname'] ,$unique[$i],$load); //$i++; } i tried every method nothing seems to work can anyone help me in this regard please. Edited December 25, 2019 by narutofanI have a database query set up that returns an array. I then cycle through the rows in a foreach statement that wraps each value in a <td> tag to output it to a table. It works really great, but now I need to access two of the values and add some info to them. The first field returned is an image filename and I want to wrap it in an image tag that also concatenates the image path location to the value. All the images are stored in the same location, so basically I want to take the first value form the array and add the path to where the images are and wrap the whole thing in an <img> tag. The other field I need to modify is the last value in the array which is actually an email address. For that field I want to make them an active email link so I need to wrap an <a>href=mailto: </a> tag around the value. How could I modify this code so I could add the necessary tags to these elements of the array? Here is the code I am running: Code: [Select] $query = "Select member_image as 'Image', member_name as 'Name', city as 'City', phone as 'Phone', email as 'Email' FROM directory"; //connect to database $conn=db_connect(); //call function do_query to run the query and output the table do_query($conn, $querey); The functions called are as follows: Code: [Select] function db_connect() { $conn = new mysqli("localhost", "username", "password", "databasename"); } function do_query($conn, $query); { $result = mysqli_query($conn, $query); WHILE ($row = mysqli_fetch_assoc($result)) { If (!$heading) //only do if header row hasn't been output yet { $heading = TRUE; //so we only do it once echo "<table>\n<tr<>\n"; foreach ($row as $key => $val) { echo "<th>$key</th>"; } echo "</tr>\n"; } echo "<tr>"; foreach ($row as $val) { echo "<td> $val </td>"; } echo "</tr>\n"; } //close the while echo "</table>\n"; } Hello, I've been stuck on this code for nearly 3 days and i still am not able to understand this too well. The PHP manual says "Unless the array is referenced, foreach operates on a copy of the specified array and not the array itself. foreach has some side effects on the array pointer. Don't rely on the array pointer during or after the foreach without resetting it." Right , so from what i understand from that,if i want to modify an array inside a foreach , i need to reference the array. This example was given in the PHP manual to demonstrate this reference requirement <?php $arr = array(1, 2, 3, 4); foreach ($arr as &$value) { $value = $value * 2; } // $arr is now array(2, 4, 6, 8) unset($value); // break the reference with the last element ?> But, when i try this code : <?php $array = array('Ibanez'); foreach ($array as $guitar) { $array['guitar'] = $array[0]; unset($array[0]); $array['guitar'] = 'Gibson'; } print_r($array); ?> The output of the array outside the foreach shows the changed array and not the original anymore. So doesn't this mean that the foreach CAN indeed operate on the array itself without the array being referenced? The reason i'm stuck with this code is that i'm trying to use another slightly bigger array which needs to have its keys modified within the foreach statement, but the changes refuse to leave the foreach loop. But when i tested this small piece of code above, changes are indeed getting reflected without any reference. I'm really confused now about how this works. Help is greatly appreciated I have a for loop which extracts info from a MySQL table, chooses something then needs to push each bit into an array: for($i = 0 ; $i < $query_report_rows ; ++$i) { $row= mysql_fetch_row($query_names); if($row[6] == 0) { $sName = $row[1]; } elseif($row[6] == 1) { $sName = $row[2]; } $name = "$row[0], $sName"; $print = nl2br($row[7]); } What i need is a multidimensional array to hold $name and $print: $name_print = array( array('name'=>$name 'print'=>$print ) ) How do i array push into such an array from the above for loop? (multi-dimensional array are a very weak point at the moment, so any pointers here would be very much appreciated) Hiya peeps! Here are my scripts; test.php <?php include 'formValidation.php'; $new = new formValidation( array( array( 'formname' => 'firstname', 'value' => 'james', 'options' => 'required, alllowercase, onlyletters', 'name' => 'First Name' ), array( 'formname' => 'password', 'value' => 'blahblah', 'options' => 'required, oneuppercase, alphanumerical', 'name' => 'Password' ), array( 'formname' => 'username', 'value' => 'blahblah', 'options' => 'required, oneuppercase, alphanumerical', 'name' => 'Username' ) ) ); ?> formValidation.php <?php class formValidation { private $inputs; function __construct($inputs = array()) { foreach($inputs as $input_key => $input_value) { foreach($input_value as $key => $value) { echo $value . '<br />'; } } } public function __prep($formname, $options, $value, $name) { echo $formname . ' ' . $options . ' ' . $value . ' ' . $name . '<br />'; } } ?> This outputs; firstname james required, alllowercase, onlyletters First Name password blahblah required, oneuppercase, alphanumerical Password username blahblah required, oneuppercase, alphanumerical Username But what i need to do is for every four values I need them to be sent to the __prep function. EG; $this->__prep('firstname', 'required, alllowercase, onlyletters', 'james', 'First Name'); I have no idea how to do this tho, I have tried a for() loop, another foreach loop, array the first four values then foreaching them again. I'm stuck, someone please help! Many thanks, James. I AM WORKING ON A PROJECT , I NEED YOUR HELP. I WANT TO USE EXISTING SRC OF IFRAME + RETRIVED VALUE FROM DATABASE INTO IFRAME This is my data.php to retrive values from database into iframe without refresh web page.
<?php $conn = new mysqli('localhost', 'root', '', 'x'); if ($conn->connect_error) { die("Connection error: " . $conn->connect_error); } $result = $conn->query("SELECT number1 FROM users"); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { echo $row['number1'] . '<br>'; } } ?>
<?php include('data.php') ?> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> </head> <body> <div id="show"></div> <script type="text/javascript" src="jquery-3.1.1.min.js"></script> <script type="text/javascript"> $(document).ready(function() { setInterval(function () { $('#show').load('data.php') }, 1000); }); </script> <iframe id="w3" src="DATABASE RETRIVED VALUE" height="80px" width="300px" frameborder="0" style="border: 0; width:300px; height:80px; background-color: #FFF;"></iframe> </body> </html>
INDEX FILE CODES CAN SUCCESSFULLY RETRIVE VALUES FROM DATABASE BUT, I WANT TO STORE IT IN IFRAME SRC . VAR= URLS = 'HTTP://WWW.GOOGLE.COM' IFRAME SRC WILL BE VAR URLS + RETRIEVED VALUE FROM DATABASE
I have been trying to solve this problem for a few days now and can't seem to work it out. I'm sure i'm missing some simple point.. I am using a mysql PDO fetch to return 2 fields in each row and then put them into an array of their own: foreach ($st->fetchAll() as $row){ $subs[] = array($row['subscriber'],$row['plant']); Some of the rows share the same $row[0], which is the 'subscriber' field. What I want to do is make up another array with each smaller array having a single, unique $row[0] and any number of added 'plant' fields following (e.g $row[1],$row[2] etc). I've tried all sorts of ways to achieve this but am at a loss. Would someone be able to point me in the right direction ? Thanks. Hi, I have a question: I have a CSV file where the first row are the names of the columns. The format of the CSV file is: Name | Surname | Adress | Date of birth Robert | Miller | Athome 1| 29. Februar 1976 . . . How should I import the CSV. Thanks in advance. hello freaks,
I have a four-element array, which is the result of a mysql query. The array is like below. (This is of course just a snippet to show the structure; the hours of course go up to 24, then repeat; there are about ten days' worth of data.)
Array ( [dayname] => day1 [hour] => 1 [widtype] => type1 [Output] => 20 ) Array ( [dayname] => day1 [hour] => 2 [widtype] => type1 [Output] => 9 ) Array ( [dayname] => day1 [hour] => 1 [widtype] => type2 [Output] => 450 ) Array ( [dayname] => day1 [hour] => 2 [widtype] => type2 [Output] => 650 ) I want to loop through this data and output each hour's data in a separate line, like below (I included the headings just for clarity): Day Hour Type1_total Type2_total day1 1 20 450 day1 2 9 650 ... and can't seem to make this happen. Here's the code I've written: $prevday = ''; while ( $row = mysql_fetch_assoc($result)) { extract($row); $currentday = $row['dayname']; $currenthour = $row['hour']; $currentwid = $row['widtype']; while($currentday !== $prevday){ for($currenthour = 1; $currenthour <=24; $currenthour++){ if($row['widtype'] == 'type1'){ $type1_total = $row['Output'];} if($row['fuel'] == 'type2'){$type2_total = $row['Output'];} print "<pre>"; echo "$currentday, $currenthour, $type1_total, $type2_total"; print "</pre>"; } $prevday = $currentday; } }... and here's what it outputs: day1, 1, 20, , day1, 2, 20, , Clearly I have written this loop wrong but have banged my head against it for a while and wonder if it's just not possible to do what I want. Any suggestions would be hugely appreciated! I am having a hell of a time getting this to work. I need the keys in an array to be specific, not a sequential number or a row in my database. I need to add to the array through each loop of my while() statement. This code does it, but does not use the keys I specify, after the first entry, it starts assigning numbers to keys. Any guidance would be great. <?php require_once ('includes/config.php'); require_once ('includes/connect.php'); $echoarray = array(); $resultsql = mysql_query("SELECT * FROM clients")or die(mysql_error()); while($row = mysql_fetch_array($resultsql)){ if(empty($echoarray)){ $echoarray = array( 'id' => $row['ID'], 'name' => $row['First_Name'] . " " . $row['Last_Name'], 'price' => $row['Status'], 'number' => $row['Sex'], 'address' => $row['Phys_Street'], 'company' => $row['Agency'], 'desc' => $row['Notes'], 'age' => $row['Date_Birth'], 'title' => $row['Occupation'], 'phone' => $row['Phone'], 'email' => $row['Email'], 'zip' => $row['Phys_Zip'], 'country' => $row['Phys_City'] ); } else { array_push($echoarray, $echoarray['id'] = $row['ID'], $echoarray['name'] = $row['First_Name'] . " " . $row['Last_Name'], $echoarray['price'] = $row['Status'], $echoarray['number'] = $row['Sex'], $echoarray['address'] = $row['Phys_Street'], $echoarray['company'] = $row['Agency'], $echoarray['desc'] = $row['Notes'], $echoarray['age'] = $row['Date_Birth'], $echoarray['title'] = $row['Occupation'], $echoarray['phone'] = $row['Phone'], $echoarray['email'] = $row['Email'], $echoarray['zip'] = $row['Phys_Zip'], $echoarray['country'] = $row['Phys_City'] ); } Any Ideas? I am trying to store all the elements of my tree in an array.My code produces multi dimensional array, but i want it to be one dimensional. How can i get it ? Code:- Code: [Select] function tree_gather($node) //Function to calculate count { $sql = "SELECT lchild,rchild FROM tree WHERE parent = '$node'"; $execsql = mysql_query($sql); $array = mysql_fetch_array($execsql); if(!empty($array['lchild']) || !empty($array['rchild'])) { $child[] = $array['lchild']; $child[] = $array['rchild']; $child[] = tree_gather($array['lchild']); $child[] = tree_gather($array['rchild']); } return $child; } Result:- Code: [Select] Array ( [0] => 2 [1] => 3 [2] => Array ( [0] => 4 [1] => 5 [2] => Array ( [0] => 10 [1] => 11 [2] => [3] => ) [3] => Array ( [0] => 8 [1] => 9 [2] => [3] => ) ) [3] => Array ( [0] => 7 [1] => 6 [2] => Array ( [0] => 15 [1] => 14 [2] => Array ( [0] => 16 [1] => 17 [2] => [3] => ) [3] => ) [3] => Array ( [0] => 13 [1] => 12 [2] => [3] => ) ) ) Table: - Hi everyone, I am having trouble passing/displaying the values inside of a selected list. I created a add/remove list using Jquery and I tried to display the values passed using foreach and for loops but it is still not working. The values I am trying to get are $existing_mID[$j], which is inside of the option value attribute. Please kindly let me know what should I do in order to get the values and I really appreciate your help. <?php $selected = $_POST['selectto']; if(isset($selected)) { echo "something in selected<br />"; for ($i=0;$i<count($selected);$i++) echo "selected #1 : $selected[$i]"; foreach ($selected as $item) echo "selected: item: $item"; } ?>This is the form Hi, Im battling here to get "only" certain values from a "akey" and "value" query.. I have a list of items around 200 id's strong, i only want to pull cirtain values from the list, the table structure is like so: id, akey, value // i don't know the values of the specific akey's or their id's but i do know the akey value. what i am trying to do is only pull the values that are in the "getConfigTitle's" list below (this list is only a sample the actual list is around 100 strong) here is my code sample: $query="SELECT akey,value FROM settings WHERE LOWER(akey) LIKE getConfigTitles();"; $settingsList=doSelectSql($query); foreach ($settingsList as $set) { $r=array(); $r['CONFIGTITLE']=getConfigTitles(); $r['KEY'] = $set->akey; $r['SETTING'] = $set->value; $rows[]=$r; } function getConfigTitles() { $titles=array(); $titles['search']= "search" ; $titles['viewprofile']= "viewprofile" ; $titles['editprofile']= "editprofile" ; $titles['dashboard']= "dashboard" ; $titles['preview']= "preview" ; return $titles; } I'm not sure if the title explains it very well, but here is an image of it. I am trying to figure out how to access the option selected (equal, not equal, etc.), along with its input box, for each column (the checkboxes on the right) selected. The purpose of this is to allow a non-programming administrator user to create a custom query to access information. I can find out which checkboxes are selected no problem, but finding the accompanying drop-down option and input box is difficult for me. How do I do this? If you have a suggestion on how to change it, I'm very open. Thank you in advance! Code: [Select] if(!isset($_POST['submit'])) { echo " <form method='post'> <table> <tr> <td valign='top'>SELECT</td> <td valign='top'> <table>"; // LIST ALL COLUMNS IN A TABLE $result = mysql_query("SELECT * FROM table_name") or die(mysql_error()); $rowcount=mysql_num_rows($result); $y=mysql_num_fields($result); for ($x=0; $x<$y; $x++) { echo " <tr> <td> <input type='checkbox' name='fields[]' value='".mysql_field_name($result, $x)."'>".mysql_field_name($result, $x)." </td> </tr>"; } echo " </table> </td> <td valign='top'>FROM allocations</td> <td valign='top'>WHERE</td> <td> <table>"; // LIST ALL COLUMNS IN A TABLE $result = mysql_query("SELECT * FROM table_name") or die(mysql_error()); $rowcount=mysql_num_rows($result); $y=mysql_num_fields($result); for ($x=0; $x<$y; $x++) { echo " <tr> <td> <input type='checkbox' name='column[]' value='".mysql_field_name($result, $x)."'>".mysql_field_name($result, $x)." </td> <td> <select name='operator[]'> <option value='='>equals</option> <option value='<>'>does not equal</option> <option value='>'>greater than</option> <option value='<'>less than</option> <option value='>='>greater than or equal to</option> <option value='<='>less than or equal to</option> <option value='LIKE'>is like</option> </select> </td> <td><input type='text' name='criteria[]'></td> </tr>"; } echo " </table> </td> <td valign='top'><input type='submit' value='Process Query' name='submit' class='submit'></td> </tr> </table> </form>"; } else { echo "<b>Fields to edit:</b> "; foreach ($_POST['fields'] as $fields) { echo $fields,", "; } echo "<br><br>"; echo "<b>Columns to query:</b> "; foreach ($_POST['column'] as $columns) { echo $columns," HERE IS THE SPOT, "; } } Hello , i am trying to sort a 2d dimensional array by the first column(id) and i havent find anything till now This is my code for the 2d array: $username = $_SESSION['username']; $c = 0; $row=1; $col=1; $users_array = array(); $get_from = mysql_query("SELECT id FROM my_activity WHERE from_user='$username'"); while($fetch1 = mysql_fetch_array($get_from)){ $id[$c] = $fetch1[0]; $get_from_user = mysql_query("SELECT * FROM my_activity WHERE id='$id[$c]'"); $get_user_rows = mysql_num_rows($get_from_user); while($guser = mysql_fetch_array($get_from_user)){ $user[$c] = $guser['to_user']; $users_array[$id[$c]][$user[$c]]= $id[$c].".".$user[$c]; $c++; } } $get_to = mysql_query("SELECT * FROM my_activity WHERE to_user='$username'"); while($fetch2 = mysql_fetch_array($get_to)){ $id[$c] = $fetch2[0]; $get_to_user = mysql_query("SELECT from_user FROM my_activity WHERE id='$id[$c]'"); while($tuser = mysql_fetch_array($get_to_user)){ $user[$c] = $tuser[0]; $users_array[$id[$c]][$user[$c]]= $id[$c].".".$user[$c]; $c++; } } This is what i get if i simply loop the array to get the result: Code: [Select] Array ( [6] => Array ( [checkdate] => 6.checkdate ) [25] => Array ( [asdsadsad] => 25.asdsadsad ) [7] => Array ( [webuser] => 7.webuser ) [9] => Array ( [newuser] => 9.newuser ) [10] => Array ( [bot77un] => 10.bot77un ) ) I am trying to sort it by the ids 6,25,7,9,10 in DESC |