I am trying to figure out how to write a statement in my first ci app (and only the second PHP app) and I'm stuck.
I have a journaling table that keeps book_id and user_id from their respective tables. I want to know who has read a book and crimp it back, but I need formatting to understand the query here:
$ readQuery = $ this-> DB- & gt; Get_where ('books_users', array ('book_id' = & gt; $ isbn));
And here is my argument for a person
// Get my user information $ user = $ this-> ion_auth-> Get_user (); // Tell me who has read this $ $-> Db- & gt; ('User_id'); $ ReadQuery = $ this- & gt; Db- & gt; Get_where ('books_users', array ('book_id' => $ isbn)); // If only one person has read it ($ readQuery-> num_rows () == 1) {$ readResult = $ readQuery-> Line (); // And if that person was me ... if ($ readResult-> user_id == $ user- & gt; id) {$ message = 'You have read this.'; // if it was someone else ...} and ($ reader = $ this-> ion_auth-> get_user ($ readResult-> user_id); $ Message = "$ reader-> First_name $ Reader-> last_name has read it ";} // if two people have read it}
So I'm good if only one person has read it. When two people have read this, I want to say that "the same name and name have read it." If the log-in person has not read it, if they are one of two people, then it should say That " You and the name have read this. "
And for 3-5 if 3-5 people have read this, then the option" name one, name two, and the name will be three "or "You, give the name, and name three have read it." To 5 people
And if it is 6 or more, then the names of two of them should just say, "Give me the name , And 5 others have read it. "
I considered conditional for each example and then pushed all the users into an array. So I can see the use of In_Are () whether the logged-in user has read it and tried to report back, but I have some problems working in the argument.
Is there any easy way?
$ User = array); While ($ line) {if (currentuser) {array_unshift ($ user, 'you')} and {$ user [] = line [name]}} $ count = $ max = count ($ user); If ($ max> gt = 6) {$ max = 2; } $ Str = ''; ($ I = 0; $ i & lt; $ max; $ i ++) {$ str = ($ Str == '' '': ($ i == $ count-1 & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; # count; 6 & # 39; & # 39; & ';', ') $ Users [$ i]; } If ($ count> = 6) {$ str = 'And'. $ Count-2 It should be helpful to you. It is a very pseudo-code, but logic (I believe) to get what you want. You obviously do not want to get all the rows if you are just showing a lot of users but this can be easily accomplished.
Comments
Post a Comment