savagenoob Posted November 21, 2010 Share Posted November 21, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/219344-multi-dimensional-array-help/ Share on other sites More sharing options...
savagenoob Posted November 21, 2010 Author Share Posted November 21, 2010 basically I need an array to echo this: return array( array('id'=>'0', 'name'=>'xmlqoyzgmykrphvyiz', 'date'=>'13-Sep-2002', 'price'=>'8370', 'number'=>'8056', 'address'=>'qdfbc', 'company'=>'taufrid', 'desc'=>'pppzhfhcdqcvbirw', 'age'=>'5512', 'title'=>'zticbcd', 'phone'=>'hvdkltabshgakjqmfrvxo', 'email'=>'eodnqepua', 'zip'=>'eodnqepua', 'country'=>'pdibxicpqipbsgnxyjumsza'), array('id'=>'1', 'name'=>'rbdmbabficcre', 'date'=>'10-Sep-2004', 'price'=>'3075', 'number'=>'3627', 'address'=>'oxcm', 'company'=>'xyzwzv', 'desc'=>'rwndyoedxh', 'age'=>'2134', 'title'=>'lxxyfgdtdffjce', 'phone'=>'zeejvbwy', 'email'=>'ldcikhxwfuulaxeedkogpxftb', 'zip'=>'ldcikhxwfuulaxeedkogpxftb', 'country'=>'pcmobxrdfclcyrx'), array('id'=>'2', 'name'=>'yr', 'date'=>'04-Mar-2007', 'price'=>'7129', 'number'=>'6614', 'address'=>'i', 'company'=>'gcpvrshftfxxlz', 'desc'=>'nyalrdjjl', 'age'=>'4728', 'title'=>'ddfl', 'phone'=>'mnhifzqltvirgiaug', 'email'=>'f', 'zip'=>'f', 'country'=>'epipbmtfsfxetenyedjxzsog'), array('id'=>'3', 'name'=>'bhqggvwolybfdtk', 'date'=>'26-Dec-2000', 'price'=>'1867', 'number'=>'4288', 'address'=>'jo', 'company'=>'goevufkvmbct', 'desc'=>'zhixinabyazbfleozrvovr', 'age'=>'3423', 'title'=>'b', 'phone'=>'odhh', 'email'=>'g', 'zip'=>'g', 'country'=>'idxvdztezvkkaz'), array('id'=>'4', 'name'=>'uynlhonmcqtjqzyzd', 'date'=>'23-Nov-2002', 'price'=>'8497', 'number'=>'5846', 'address'=>'vlwglvrcqqqc', 'company'=>'epkhgeqxdpwhlsohhadsxkd', 'desc'=>'bgjrxlpbbzihdzfhpcp', 'age'=>'417', 'title'=>'ejbfmucwyvyefpcqfdse', 'phone'=>'zimfqbhfccjl', 'email'=>'oyy', 'zip'=>'oyy', 'country'=>'vwntbsjdiohattacg'), array('id'=>'5', 'name'=>'inylpixtxvrorobkpt', 'date'=>'20-Oct-2000', 'price'=>'3551', 'number'=>'9863', 'address'=>'cte', 'company'=>'akyiy', 'desc'=>'tofqicmaqdosodljvosvrv', 'age'=>'5844', 'title'=>'apgyxfvrtahccuctxqlmtx', 'phone'=>'plnldiaaiphhnmcegcmif', 'email'=>'kyeakq', 'zip'=>'kyeakq', 'country'=>'hlktyvxhwyqmfxzrzexc')); Quote Link to comment https://forums.phpfreaks.com/topic/219344-multi-dimensional-array-help/#findComment-1137383 Share on other sites More sharing options...
sasa Posted November 21, 2010 Share Posted November 21, 2010 are you traying this <?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)){ $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'] ); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/219344-multi-dimensional-array-help/#findComment-1137385 Share on other sites More sharing options...
savagenoob Posted November 21, 2010 Author Share Posted November 21, 2010 I tried that (first thing) and it just overwrote the existing array, returning only one set, the last row in my database.. Quote Link to comment https://forums.phpfreaks.com/topic/219344-multi-dimensional-array-help/#findComment-1137386 Share on other sites More sharing options...
sasa Posted November 21, 2010 Share Posted November 21, 2010 are you add [] to the end of $echoarray variable? Quote Link to comment https://forums.phpfreaks.com/topic/219344-multi-dimensional-array-help/#findComment-1137387 Share on other sites More sharing options...
savagenoob Posted November 21, 2010 Author Share Posted November 21, 2010 eh. jesus. Thanks. I just caught this myself too. Now, how do i turn this function function initArray() { return array( array('id'=>'0', 'name'=>'xmlqoyzgmykrphvyiz', 'date'=>'13-Sep-2002', 'price'=>'8370', 'number'=>'8056', 'address'=>'qdfbc', 'company'=>'taufrid', 'desc'=>'pppzhfhcdqcvbirw', 'age'=>'5512', 'title'=>'zticbcd', 'phone'=>'hvdkltabshgakjqmfrvxo', 'email'=>'eodnqepua', 'zip'=>'eodnqepua', 'country'=>'pdibxicpqipbsgnxyjumsza'), array('id'=>'1', 'name'=>'rbdmbabficcre', 'date'=>'10-Sep-2004', 'price'=>'3075', 'number'=>'3627', 'address'=>'oxcm', 'company'=>'xyzwzv', 'desc'=>'rwndyoedxh', 'age'=>'2134', 'title'=>'lxxyfgdtdffjce', 'phone'=>'zeejvbwy', 'email'=>'ldcikhxwfuulaxeedkogpxftb', 'zip'=>'ldcikhxwfuulaxeedkogpxftb', 'country'=>'pcmobxrdfclcyrx')); Into one that returns my newly formed array. I tried function initArray() { return print_r($echoarray); } and... function initArray() { return array($echoarray); } and... function initArray() { return $echoarray; } This data is being pushed back via ajax to use with a datatable (YUI) and its still saying No Results. Quote Link to comment https://forums.phpfreaks.com/topic/219344-multi-dimensional-array-help/#findComment-1137404 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.