violinrocker Posted May 11, 2011 Share Posted May 11, 2011 i was wonderin if there is a function where you can get a column in an array format... if there is none, how could I put a row of names inside an array. @include ("../session.php"); include ("../addons/functions/general.php"); mysql_connect("localhost", "", "") or die(mysql_error()); mysql_select_db("") or die(mysql_error()); $result = mysql_query("SELECT friendname FROM friends where username='$session->username'"); while ($row = mysql_fetch_assoc($result)) { } $response = array(); $names = array('ROW of NAMES in HERE); i need $names = array('ROW of Names in Here); to be like this $names = array('Abraham Lincoln', 'Adolf Hitler', 'Agent Smith', 'Agnus', 'AIAI', 'Akira Shoji', 'Akuma', 'Alex', 'Antoinetta Marie', 'Baal', 'Baby Luigi', 'Backpack', 'Baralai', 'Bardock', 'Baron Mordo', 'Barthello', 'Blanka', 'Bloody Brad', 'Cagnazo', 'Calonord', 'Calypso', 'Cao Cao', 'Captain America', 'Chang', 'Cheato', 'Cheshire Cat', 'Daegon', 'Dampe', 'Daniel Carrington', 'Daniel Lang', 'Dan Severn', 'Darkman', 'Darth Vader', 'Dingodile', 'Dmitri Petrovic', 'Ebonroc', 'Ecco the Dolphin', 'Echidna', 'Edea Kramer', 'Edward van Helgen', 'Elena', 'Eulogy Jones', 'Excella Gionne', 'Ezekial Freeman', 'Fakeman', 'Fasha', 'Fawful', 'Fergie', 'Firebrand', 'Fresh Prince', 'Frylock', 'Fyrus', 'Lamarr', 'Lazarus', 'Lebron James', 'Lee Hong', 'Lemmy Koopa', 'Leon Belmont', 'Lewton', 'Lex Luthor', 'Lighter', 'Lulu'); Quote Link to comment https://forums.phpfreaks.com/topic/236120-rows-inside-array/ Share on other sites More sharing options...
TOA Posted May 11, 2011 Share Posted May 11, 2011 Inside the while loop try this: $names[] = $row['friendname']; If I understand you correctly Quote Link to comment https://forums.phpfreaks.com/topic/236120-rows-inside-array/#findComment-1213918 Share on other sites More sharing options...
violinrocker Posted May 11, 2011 Author Share Posted May 11, 2011 in my table i have the names "smiley,jc,dub,cookie,pete" what i wanted to do was fetch them from the database and put them inside $names = array(smiley,jc,dub,cookie,pete); sorta like $names = array( while ($row = mysql_fetch_assoc($result)) { return $row[name] } ); Quote Link to comment https://forums.phpfreaks.com/topic/236120-rows-inside-array/#findComment-1213927 Share on other sites More sharing options...
TOA Posted May 11, 2011 Share Posted May 11, 2011 in my table i have the names "smiley,jc,dub,cookie,pete" what i wanted to do was fetch them from the database and put them inside $names = array(smiley,jc,dub,cookie,pete); sorta like $names = array( while ($row = mysql_fetch_assoc($result)) { return $row[name] } ); That's exactly what I gave you Put what I posted inside your while loop, and it will put each db name into the names array Quote Link to comment https://forums.phpfreaks.com/topic/236120-rows-inside-array/#findComment-1213931 Share on other sites More sharing options...
violinrocker Posted May 11, 2011 Author Share Posted May 11, 2011 that would make it something like $names = array('smiley','hanane','dub'); or will it be something like $names = array[smileyhananedub]; sorry if im so stupid with this, im not well versed with arrays coz if i manually put the names like $names = array('Abraham Lincoln', 'Adolf Hitler', 'Agent Smith', 'Agnus', 'AIAI', 'Akira Shoji', 'Akuma', 'Alex', 'Antoinetta Marie', 'Baal', 'Baby Luigi', 'Backpack', 'Baralai', 'Bardock', 'Baron Mordo', 'Barthello', 'Blanka', 'Bloody Brad', 'Cagnazo', 'Calonord', 'Calypso', 'Cao Cao', 'Captain America', 'Chang', 'Cheato', 'Cheshire Cat', 'Daegon', 'Dampe', 'Daniel Carrington', 'Daniel Lang', 'Dan Severn', 'Darkman', 'Darth Vader', 'Dingodile', 'Dmitri Petrovic', 'Ebonroc', 'Ecco the Dolphin', 'Echidna', 'Edea Kramer', 'Edward van Helgen', 'Elena', 'Eulogy Jones', 'Excella Gionne', 'Ezekial Freeman', 'Fakeman', 'Fasha', 'Fawful', 'Fergie', 'Firebrand', 'Fresh Prince', 'Frylock', 'Fyrus', 'Lamarr', 'Lazarus', 'Lebron James', 'Lee Hong', 'Lemmy Koopa', 'Leon Belmont', 'Lewton', 'Lex Luthor', 'Lighter', 'Lulu'); a javascript that fetches the name works... but if i tried fetching from the database, it doesnt work Quote Link to comment https://forums.phpfreaks.com/topic/236120-rows-inside-array/#findComment-1213934 Share on other sites More sharing options...
violinrocker Posted May 11, 2011 Author Share Posted May 11, 2011 Oh lol nvm... i found out it was my include files that was messing it.... anyway, it worked great thank you so much for the help Quote Link to comment https://forums.phpfreaks.com/topic/236120-rows-inside-array/#findComment-1213941 Share on other sites More sharing options...
TOA Posted May 11, 2011 Share Posted May 11, 2011 Sweet Quote Link to comment https://forums.phpfreaks.com/topic/236120-rows-inside-array/#findComment-1213942 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.