suttercain Posted March 28, 2007 Share Posted March 28, 2007 I got this to work many times before but I can't figure out why it's not working this time. I am pulling a column from MySQL named 'manuf' and I am assigning values to the keys and I want to echo the value. <?php $makes = array('ACUR'=>'ACURA', 'ALP'=>'ALPINA', 'ASMA'=>'ASTON MARTIN LAGONDA', 'AUDI'=>'AUDI', 'BAF'=>'FORD BAF CNG', 'BAYT'=>'GENERAL MOTORS BAYTECH CNG', 'BENT'=>'BENTLY', 'BMW'=>'BMW', 'BUIC'=>'BUICK', 'CAD'=>'CADILLAC', 'CHEV'=>'CHEVROLET', 'CHRS'=>'CHRYSLER', 'CUMM'=>'CUMMINS', 'DODG'=>'DODGE', 'FERI'=>'FERARAI', 'FORD'=>'FORD', 'GMC'=>'GMC', 'HOND'=>'HONDA', 'HUMM'=>'HUMMER', 'HYND'=>'HYUNDAI', 'INFI'=>'INFINITI', 'ISUZ'=>'ISUZU', 'JAG'=>'JAGUAR', 'JEEP'=>'JEEP', 'KI'=>'KIA', 'LAMB'=>'LABORGHINI', 'LAND'=>'LAND ROVER', 'LEXS'=>'LEXUS', 'LINC'=>'LINCOLN', 'LOTU'=>'LOTUS', 'MASE'=>'MASERATI', 'MAZD'=>'MAZDA', 'MBZ'=>'MERCEDES BENZ', 'MINI'=>'MINI', 'MITS'=>'MITSUBISHI', 'MORG'=>'MORGAN', 'MRCY'=>'MERCURY', 'NISS'=>'NISSAN', 'PONT'=>'PONTIAC', 'PORS'=>'PORSCHE', 'RPP'=>'ROUSCH', 'RR'=>'ROLLS ROYCE', 'SAAB'=>'SAAB', 'SALE'=>'SALEEN', 'SATU'=>'SATURN', 'SHLB'=>'SHELBY', 'SUBA'=>'SUBARU', 'SUZU'=>'SUZUKI', 'TOTA'=>'TOYOTA', 'VOLK'=>'VOLKSWAGEN', 'VOLV'=>'VOLVO', ); print $makes['manuf']; echo "<center>$makes[manuf]</center>"; ?> Where am I going wrong? Thanks in advance for your help. Shannon Quote Link to comment https://forums.phpfreaks.com/topic/44644-solved-echoing-an-array-argh/ Share on other sites More sharing options...
per1os Posted March 28, 2007 Share Posted March 28, 2007 $makes['manuf'] is not in the array if manuf is a $ it should be this. <?php //array code here. $manuf = "SATU"; print $makes[$manuf]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/44644-solved-echoing-an-array-argh/#findComment-216785 Share on other sites More sharing options...
suttercain Posted March 28, 2007 Author Share Posted March 28, 2007 Hi Frost, I gave this a try and the result is blank. <?php $manuf = array('ACUR'=>'ACURA', 'ALP'=>'ALPINA', 'ASMA'=>'ASTON MARTIN LAGONDA', 'AUDI'=>'AUDI', 'BAF'=>'FORD BAF CNG', 'BAYT'=>'GENERAL MOTORS BAYTECH CNG', 'BENT'=>'BENTLY', 'BMW'=>'BMW', 'BUIC'=>'BUICK', 'CAD'=>'CADILLAC', 'CHEV'=>'CHEVROLET', 'CHRS'=>'CHRYSLER', 'CUMM'=>'CUMMINS', 'DODG'=>'DODGE', 'FERI'=>'FERARAI', 'FORD'=>'FORD', 'GMC'=>'GMC', 'HOND'=>'HONDA', 'HUMM'=>'HUMMER', 'HYND'=>'HYUNDAI', 'INFI'=>'INFINITI', 'ISUZ'=>'ISUZU', 'JAG'=>'JAGUAR', 'JEEP'=>'JEEP', 'KI'=>'KIA', 'LAMB'=>'LABORGHINI', 'LAND'=>'LAND ROVER', 'LEXS'=>'LEXUS', 'LINC'=>'LINCOLN', 'LOTU'=>'LOTUS', 'MASE'=>'MASERATI', 'MAZD'=>'MAZDA', 'MBZ'=>'MERCEDES BENZ', 'MINI'=>'MINI', 'MITS'=>'MITSUBISHI', 'MORG'=>'MORGAN', 'MRCY'=>'MERCURY', 'NISS'=>'NISSAN', 'PONT'=>'PONTIAC', 'PORS'=>'PORSCHE', 'RPP'=>'ROUSCH', 'RR'=>'ROLLS ROYCE', 'SAAB'=>'SAAB', 'SALE'=>'SALEEN', 'SATU'=>'SATURN', 'SHLB'=>'SHELBY', 'SUBA'=>'SUBARU', 'SUZU'=>'SUZUKI', 'TOTA'=>'TOYOTA', 'VOLK'=>'VOLKSWAGEN', 'VOLV'=>'VOLVO', ); print $makes[$manuf]; echo "<center>$makes[$manuf]</center>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/44644-solved-echoing-an-array-argh/#findComment-216788 Share on other sites More sharing options...
per1os Posted March 28, 2007 Share Posted March 28, 2007 Wow what are you trying to do, now the array is named $manuf instead of makes??? Maybe reading up on arrays via http://www.php.net/array will do you some good? <?php // do not change this it is fine. $makes = array('ACUR'=>'ACURA', 'ALP'=>'ALPINA', 'ASMA'=>'ASTON MARTIN LAGONDA', 'AUDI'=>'AUDI', 'BAF'=>'FORD BAF CNG', 'BAYT'=>'GENERAL MOTORS BAYTECH CNG', 'BENT'=>'BENTLY', 'BMW'=>'BMW', 'BUIC'=>'BUICK', 'CAD'=>'CADILLAC', 'CHEV'=>'CHEVROLET', 'CHRS'=>'CHRYSLER', 'CUMM'=>'CUMMINS', 'DODG'=>'DODGE', 'FERI'=>'FERARAI', 'FORD'=>'FORD', 'GMC'=>'GMC', 'HOND'=>'HONDA', 'HUMM'=>'HUMMER', 'HYND'=>'HYUNDAI', 'INFI'=>'INFINITI', 'ISUZ'=>'ISUZU', 'JAG'=>'JAGUAR', 'JEEP'=>'JEEP', 'KI'=>'KIA', 'LAMB'=>'LABORGHINI', 'LAND'=>'LAND ROVER', 'LEXS'=>'LEXUS', 'LINC'=>'LINCOLN', 'LOTU'=>'LOTUS', 'MASE'=>'MASERATI', 'MAZD'=>'MAZDA', 'MBZ'=>'MERCEDES BENZ', 'MINI'=>'MINI', 'MITS'=>'MITSUBISHI', 'MORG'=>'MORGAN', 'MRCY'=>'MERCURY', 'NISS'=>'NISSAN', 'PONT'=>'PONTIAC', 'PORS'=>'PORSCHE', 'RPP'=>'ROUSCH', 'RR'=>'ROLLS ROYCE', 'SAAB'=>'SAAB', 'SALE'=>'SALEEN', 'SATU'=>'SATURN', 'SHLB'=>'SHELBY', 'SUBA'=>'SUBARU', 'SUZU'=>'SUZUKI', 'TOTA'=>'TOYOTA', 'VOLK'=>'VOLKSWAGEN', 'VOLV'=>'VOLVO'); // Somewhere $manuf needs to be set for testing purposes I will set it right now $manuf = 'SUBA'; print $makes[$manuf]; // should print "SUBARU"; // or it could be done like this: print $makes['TOTA']; // should print "TOTA"; // Just as long as the INDEX/KEY ('TOTA') of the ARRAY ($makes) is in the array it will print something. echo "<center>".$makes[$manuf]."</center>"; // personal preference I like to break it up ?> Just an fyi Arrays work like this: $array[$key] = $value; meaning the array at index key contains $value. Quote Link to comment https://forums.phpfreaks.com/topic/44644-solved-echoing-an-array-argh/#findComment-216794 Share on other sites More sharing options...
neoform Posted March 28, 2007 Share Posted March 28, 2007 I got this to work many times before but I can't figure out why it's not working this time. I am pulling a column from MySQL named 'manuf' and I am assigning values to the keys and I want to echo the value. <?php $makes = array('ACUR'=>'ACURA', 'ALP'=>'ALPINA', 'ASMA'=>'ASTON MARTIN LAGONDA', 'AUDI'=>'AUDI', 'BAF'=>'FORD BAF CNG', 'BAYT'=>'GENERAL MOTORS BAYTECH CNG', 'BENT'=>'BENTLY', 'BMW'=>'BMW', 'BUIC'=>'BUICK', 'CAD'=>'CADILLAC', 'CHEV'=>'CHEVROLET', 'CHRS'=>'CHRYSLER', 'CUMM'=>'CUMMINS', 'DODG'=>'DODGE', 'FERI'=>'FERARAI', 'FORD'=>'FORD', 'GMC'=>'GMC', 'HOND'=>'HONDA', 'HUMM'=>'HUMMER', 'HYND'=>'HYUNDAI', 'INFI'=>'INFINITI', 'ISUZ'=>'ISUZU', 'JAG'=>'JAGUAR', 'JEEP'=>'JEEP', 'KI'=>'KIA', 'LAMB'=>'LABORGHINI', 'LAND'=>'LAND ROVER', 'LEXS'=>'LEXUS', 'LINC'=>'LINCOLN', 'LOTU'=>'LOTUS', 'MASE'=>'MASERATI', 'MAZD'=>'MAZDA', 'MBZ'=>'MERCEDES BENZ', 'MINI'=>'MINI', 'MITS'=>'MITSUBISHI', 'MORG'=>'MORGAN', 'MRCY'=>'MERCURY', 'NISS'=>'NISSAN', 'PONT'=>'PONTIAC', 'PORS'=>'PORSCHE', 'RPP'=>'ROUSCH', 'RR'=>'ROLLS ROYCE', 'SAAB'=>'SAAB', 'SALE'=>'SALEEN', 'SATU'=>'SATURN', 'SHLB'=>'SHELBY', 'SUBA'=>'SUBARU', 'SUZU'=>'SUZUKI', 'TOTA'=>'TOYOTA', 'VOLK'=>'VOLKSWAGEN', 'VOLV'=>'VOLVO', ); print $makes['manuf']; echo "<center>$makes[manuf]</center>"; ?> Where am I going wrong? Thanks in advance for your help. Shannon nothing is wrong with it.. but you don't have an array element with the key "manuf".. so it's returning nothing. if you want to see what's in the array use print_r($makes); Quote Link to comment https://forums.phpfreaks.com/topic/44644-solved-echoing-an-array-argh/#findComment-216796 Share on other sites More sharing options...
suttercain Posted March 28, 2007 Author Share Posted March 28, 2007 Frost was right. I got it to work by changing the $makes = array('ACUR'=>'ACURA', back to the original. The only reason I changed it was that what it looked lik frost had done. My bad. Thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/44644-solved-echoing-an-array-argh/#findComment-216797 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.