MasterACE14 Posted October 1, 2007 Share Posted October 1, 2007 Afternoon Everyone, How can I grab a certain field of a Multi-Dimensional Array using the ID. I have set for that Array? I just want to be able to create a simple function to do pretty much what this function does, but for an array. <?php // Select fields from the user table function player_table($select){ $where = $_SESSION['playerid']; $rs = mysql_connect("localhost", "ace_ACE", "*****"); mysql_select_db("ace_cf", $rs); $sql = "SELECT `" . $select . "` FROM `cf_users` WHERE `id`='" . $where . "' LIMIT 1"; $rs = mysql_query($sql) or die('Query:<br />' . $sql . '<br /><br />Error:<br />' . mysql_error()); while($row = mysql_fetch_assoc($rs)){ if(isset($row[$select])){return $row[$select];} } } Sorry to anyone who doesnt understand what I mean, its hard to explain, my above example should give you a good idea of what I mean though. Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/71309-arrays-working-with-mysql/ Share on other sites More sharing options...
teng84 Posted October 1, 2007 Share Posted October 1, 2007 basically this is wrong way while($row = mysql_fetch_assoc($rs)){ if(isset($row[$select])){return $row[$select];} } simply $row = mysql_fetch_assoc($rs); return $row; then thats is function right so call a function like $sample =player_table($vaiable); echo $sample [field1]; echo $sample [field2]; Quote Link to comment https://forums.phpfreaks.com/topic/71309-arrays-working-with-mysql/#findComment-358783 Share on other sites More sharing options...
MasterACE14 Posted October 1, 2007 Author Share Posted October 1, 2007 sorry? im lost ??? basically this is wrong way while($row = mysql_fetch_assoc($rs)){ if(isset($row[$select])){return $row[$select];} } simply $row = mysql_fetch_assoc($rs); return $row; as for that, I never knew it could be done in such a simple way before Quote Link to comment https://forums.phpfreaks.com/topic/71309-arrays-working-with-mysql/#findComment-358793 Share on other sites More sharing options...
teng84 Posted October 1, 2007 Share Posted October 1, 2007 dude hold on ill will edit your function so that it will be more dynamic and useful Quote Link to comment https://forums.phpfreaks.com/topic/71309-arrays-working-with-mysql/#findComment-358796 Share on other sites More sharing options...
MasterACE14 Posted October 1, 2007 Author Share Posted October 1, 2007 ok, but this thread is about making similar function to do the same thing with a multi-dimensional array. Quote Link to comment https://forums.phpfreaks.com/topic/71309-arrays-working-with-mysql/#findComment-358797 Share on other sites More sharing options...
teng84 Posted October 1, 2007 Share Posted October 1, 2007 <?php function player_table($select,$connection,$db){ mysql_select_db($db,$connection);// idont know why you want this do you have lots of db? $rs = mysql_query($sql,$connection) or die('Query:<br />' . $sql . '<br /><br />Error:<br />' . mysql_error()); while($row = mysql_fetch_assoc($rs)){ $result[] = $row; } return $result; } $rs = mysql_connect("localhost", "ace_ACE", "*****"); $query ='your complete query'; $result = player_table($query,$rs,'dbname'); print_r($result); //result should be multi dimensional ?> note: not testted edited.... Quote Link to comment https://forums.phpfreaks.com/topic/71309-arrays-working-with-mysql/#findComment-358798 Share on other sites More sharing options...
MasterACE14 Posted October 1, 2007 Author Share Posted October 1, 2007 guess I didn't explain what I was after well enough. I didnt want to display information from the database in a multi dimensional array, I have a multi-dimensional array already setup, I want to select a certain array, and a certain value in the array in a similar way to how my player_table() function works. Quote Link to comment https://forums.phpfreaks.com/topic/71309-arrays-working-with-mysql/#findComment-358806 Share on other sites More sharing options...
teng84 Posted October 1, 2007 Share Posted October 1, 2007 ok give me sample output! Quote Link to comment https://forums.phpfreaks.com/topic/71309-arrays-working-with-mysql/#findComment-358810 Share on other sites More sharing options...
MasterACE14 Posted October 1, 2007 Author Share Posted October 1, 2007 I've posted again, and my new post asks my question better. I stuffed up my question here :-\ http://www.phpfreaks.com/forums/index.php/topic,161542.0.html Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/71309-arrays-working-with-mysql/#findComment-359689 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.