Jump to content

Multi-Dimensional Array Help


savagenoob

Recommended Posts

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?

Link to comment
Share on other sites

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'));

Link to comment
Share on other sites

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']
    ); 
}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.