Marcel1993 Posted December 27, 2010 Share Posted December 27, 2010 Hey, my code doesnt work and I dont know why: $update_weed_world_data_sql = "SELECT weed_factor, weed_basis FROM worlds"; $update_weed_world_data_res = mysql_query($update_weed_world_data_sql) OR DIE (mysql_error()); while($update_weed_world_data_while = mysql_fetch_assoc($update_weed_world_data_res)){ $update_weed_world_basis[''.$update_weed_world_data_while['id'].''] = $update_weed_world_data_while['weed_basis']; $update_weed_world_factor[''.$update_weed_world_data_while['id'].''] = $update_weed_world_data_while['weed_factor']; } I want to save some rows in variables identifiable by the value in the array. As example. When I want to echo $update_weed_world_factor['1'] - I want to get the row with ID 1 and the column "world_factor". I've used this code long time ago - but know something was going wrong. Thanks for helping :-) Link to comment https://forums.phpfreaks.com/topic/222702-save-rows-in-array/ Share on other sites More sharing options...
dragon_sa Posted December 27, 2010 Share Posted December 27, 2010 try this $Uid=$update_weed_world_data_while['id']; $update_weed_world_basis[$Uid] = $update_weed_world_data_while['weed_basis']; $update_weed_world_factor[$Uid] = $update_weed_world_data_while['weed_factor']; Link to comment https://forums.phpfreaks.com/topic/222702-save-rows-in-array/#findComment-1151672 Share on other sites More sharing options...
Marcel1993 Posted December 27, 2010 Author Share Posted December 27, 2010 Thank you but that didn't lead to any difference: $update_weed_world_data_sql = "SELECT weed_factor, weed_basis FROM worlds"; $update_weed_world_data_res = mysql_query($update_weed_world_data_sql) OR DIE (mysql_error()); while($update_weed_world_data_while = mysql_fetch_assoc($update_weed_world_data_res)){ $update_weed_world_id = $update_weed_world_data_while['id']; $update_weed_world_basis[$update_weed_world_id] = $update_weed_world_data_while['weed_basis']; $update_weed_world_factor[$update_weed_world_id] = $update_weed_world_data_while['weed_factor']; } echo $update_weed_world_factor[1]; Link to comment https://forums.phpfreaks.com/topic/222702-save-rows-in-array/#findComment-1151673 Share on other sites More sharing options...
dragon_sa Posted December 27, 2010 Share Posted December 27, 2010 echo out the ids to make sure you are getting them also the first item in the array starts at 0 $update_weed_world_id = $update_weed_world_data_while['id']; echo $update_weed_world_data_while['id']; $update_weed_world_basis[$update_weed_world_id] = $update_weed_world_data_while['weed_basis']; $update_weed_world_factor[$update_weed_world_id] = $update_weed_world_data_while['weed_factor']; Link to comment https://forums.phpfreaks.com/topic/222702-save-rows-in-array/#findComment-1151680 Share on other sites More sharing options...
Marcel1993 Posted December 27, 2010 Author Share Posted December 27, 2010 Hey, thanks for helping :-). I've just made an embarrassing mistake I didn't select "id" in the SQL-Query... Don't be cross with me Link to comment https://forums.phpfreaks.com/topic/222702-save-rows-in-array/#findComment-1151754 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.