Needhelp with arrays and MySQL - VERY VERY BADLY!!! Please!!
Posted: Sun Nov 06, 2005 8:49 pm
I have spent 4 days on this at 12 hrs_+ a day and I cannot figure it out. i need some major help with this! i am begging at this point~
here is what i got
Now my output looks like this: each section of code is seperated with "and"
...but when i loop through the unseperated array $content they only print once.
What i need is to be able to make my sql statement read properly
I need carrierdescription and carrierlogo values per ()
I cannot figure out how to chop up the array to do this or peice together multiple arrays and then loop through them so i get a statement that reads like this:
...VALUES ('verizon', '/image/logo.gif'), ('tmobile', '/images/logos.gif'), and so on and so on.
Please GOD.. Some one have the answer to this!!!!! I think i have officially read every single line on PHP.net about arrays.
Thanks,
vin
here is what i got
Code: Select all
$array = $p->output;
$row = array();
$contentCD = array();
$contentCL = array();
$content = array();
$hold = array();
foreach($array as $key=>$val){
if(is_array($val)){
foreach($val as $k=>$v){
//echo "$k: $v<BR>";
if(is_array($v)){
foreach($v as $k2=>$child){
//echo "$k2: $child<BR>";
if(is_array($child)){
foreach($child as $k3=>$name){
//echo "$k3: $name<BR>";
if(is_array($name)){
foreach($name as $k4=>$attributes){
$hold[] = strtolower($k4);
$row = array_unique($hold);
$content[] = $attributes;
$contentCD[] = trim($name['CARRIERDESCRIPTION']);
$contentCL[] = trim($name['CARRIERLOGO']);
}
}
}
}
}
}
}
}
} //end first foreach
if(is_array($row)){
$column = "(" . implode(", ", $row) . ")";
echo $column;
}else{
echo " Row not an array";
}
echo "<BR><BR>and<BR><BR>";
if(is_array($contentCD)){
$insertCD = "'" . implode("', '", $contentCD) . "'";
echo $insertCD;
}else{
echo "content not an array";
}
echo "<BR><BR>and<BR><BR>";
if(is_array($contentCL)){
$insertCL = "'" . implode("', '", $contentCL) . "'";
echo $insertCL;
}else{
echo "content not an array";
}
echo "<BR><BR>and<BR><BR>";
//even did a walk through the arrray
if(is_array($content)){
for($i=0; $i < count($content); $i++){
$value[] = $content[$i];
print "the value is ".$value[$i]."<bR>";
}
$insert = "'" . implode("', '", $value) . "'";
echo "<BR>";
echo $insert;
}else{
echo "content not an array";
}Now you will notice in sections 2 and 3 they duplicate, Why?(carrierdescription, carrierlogo)
and
'ALLTEL Wireless', 'ALLTEL Wireless', 'Cellular One', 'Cellular One', 'Cingular Wireless', 'Cingular Wireless', 'Liberty Wireless', 'Liberty Wireless', 'Nextel', 'Nextel', 'Sprint PCS', 'Sprint PCS', 'StarBox', 'StarBox', 'T-Mobile', 'T-Mobile', 'U.S. Cellular', 'U.S. Cellular', 'Verizon Wireless', 'Verizon Wireless'
and
'images/carriers/AllTel_logo.gif', 'images/carriers/AllTel_logo.gif', 'images/carriers/Cellularone-Lsf.gif', 'images/carriers/Cellularone-Lsf.gif', 'images/carriers/cingularlogo.gif', 'images/carriers/cingularlogo.gif', 'images/carriers/liberty_logo.gif', 'images/carriers/liberty_logo.gif', 'images/carriers/nextel_logo.gif', 'images/carriers/nextel_logo.gif', 'images/carriers/sprint_logo.gif', 'images/carriers/sprint_logo.gif', 'images/carriers/Motient_logo.gif', 'images/carriers/Motient_logo.gif', 'images/carriers/tmobile_logo.gif', 'images/carriers/tmobile_logo.gif', 'images/carriers/uscellular_l.gif', 'images/carriers/uscellular_l.gif', 'images/carriers/verizonLogo.gif', 'images/carriers/verizonLogo.gif'
and
the value is ALLTEL Wireless
the value is images/carriers/AllTel_logo.gif
the value is Cellular One
the value is images/carriers/Cellularone-Lsf.gif
the value is Cingular Wireless
the value is images/carriers/cingularlogo.gif
the value is Liberty Wireless
the value is images/carriers/liberty_logo.gif
the value is Nextel
the value is images/carriers/nextel_logo.gif
the value is Sprint PCS
the value is images/carriers/sprint_logo.gif
the value is StarBox
the value is images/carriers/Motient_logo.gif
the value is T-Mobile
the value is images/carriers/tmobile_logo.gif
the value is U.S. Cellular
the value is images/carriers/uscellular_l.gif
the value is Verizon Wireless
the value is images/carriers/verizonLogo.gif
...but when i loop through the unseperated array $content they only print once.
What i need is to be able to make my sql statement read properly
Code: Select all
$query = "INSERT INTO carrier $column VALUE ($value1, $value2), ($value1, $value2);";I cannot figure out how to chop up the array to do this or peice together multiple arrays and then loop through them so i get a statement that reads like this:
...VALUES ('verizon', '/image/logo.gif'), ('tmobile', '/images/logos.gif'), and so on and so on.
Please GOD.. Some one have the answer to this!!!!! I think i have officially read every single line on PHP.net about arrays.
Thanks,
vin