ernest1a Posted January 7, 2009 Share Posted January 7, 2009 I am new at PHP, please help me with the following question: $query = “SELECT * FROM Member WHERE loginName=’gsmith ... $result = mysqli_query($cxn,$query) while ($row = mysqli_fetch_assoc($result)) { extract($row) } In this case we get variables $password="sdfsd" $email="[email protected]" $loginName="gsmith" $name="Nick" But what happen if the data are as following: $query = “SELECT DISTINCT name FROM Member ORDER BY. Let's say we have 4 persons with the same name. I guess that multimension arrays will be created because we have 4 names and for each name all data (password, e-mail, log in and name). I don't understand how the multimension arrays will be created in this case. What will be as the key and what as the value and how variables will be created with function extract($row) in case of multimension arrays? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/139919-mysqli_fetch_assocresult/ Share on other sites More sharing options...
.josh Posted January 7, 2009 Share Posted January 7, 2009 Queries never return multi-dim arrays. At least, not in a form you can directly use. They will always return a result source, and your _fetch_assoc would pull out the info 1 row at a time (each time you call it). So when you call _fetch_assoc, you get a single-dim array of the current row. SELECT DISTINCT name FROM Member would return just 1 column 'name' and each row would only contain a single name. So for instance, if your table looks like this: name John Mary Joe Mary John John Joe You would get Joe John Mary So you would do something like this: $query = "SELECT DISTINCT name FROM Member"; $result = mysqli_query($cxn,$query); while ($row = mysqli_fetch_assoc($result)) { echo $row['name'] . "<br/>"; } And it would echo out Joe John Mary Quote Link to comment https://forums.phpfreaks.com/topic/139919-mysqli_fetch_assocresult/#findComment-732047 Share on other sites More sharing options...
ernest1a Posted January 7, 2009 Author Share Posted January 7, 2009 tnx. But what is the query is all. "SELECT * FROM Member". Is even possible to make thsi combination in mentioned case? Quote Link to comment https://forums.phpfreaks.com/topic/139919-mysqli_fetch_assocresult/#findComment-732059 Share on other sites More sharing options...
.josh Posted January 7, 2009 Share Posted January 7, 2009 Perhaps you should clarify your situation. I interpreted your original post to say that you thought that doing a select distinct would somehow return a multi-dimensional array. Well, it doesn't. Nor does any query. At least, not in this context. _fetch_whatever pulls one row at a time. That's why you put it into a loop. You mentioned something about having 4 of the same name. Well, what do you want to happen? Do you only want a list of names returned, no duplicates? Use the select distinct. Quote Link to comment https://forums.phpfreaks.com/topic/139919-mysqli_fetch_assocresult/#findComment-732078 Share on other sites More sharing options...
ernest1a Posted January 8, 2009 Author Share Posted January 8, 2009 sorry, I was just confused about something, it is clear to me now tnx Quote Link to comment https://forums.phpfreaks.com/topic/139919-mysqli_fetch_assocresult/#findComment-732097 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.