fetching database info from table ---, info in databse is divided with "," |
fetching database info from table ---, info in databse is divided with "," |
sanoj96 |
Mar 23 2019, 09:53 AM
Post
#1
|
Advanced Member Group: Members Posts: 118 Joined: 18-September 12 Member No.: 17,803 |
Hello,
So i have seen this been done (while back) but as of now i cant remember how i can get the info from the database. So basicly i have an database that have the following info: CODE bid userPosted location Members Status date 1 NameOfUser lat/lng 1, 2, 3 ,4 new DatePosted The Members table is holding the ids from the users. How can i get that info divided up. So i can get the ID and then echo out the name of the user ? Sorry for my bad english and proberly bad explaination... Feel free to ask questions if you guys didnt understand. This post has been edited by sanoj96: Mar 23 2019, 10:00 AM |
CharlesEF |
Mar 23 2019, 10:27 AM
Post
#2
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
I'm confused. Sounds like you just want to SELECT users and display their Id and Name? Since you've shown no code exactly what do you need help with?
|
sanoj96 |
Mar 23 2019, 10:46 AM
Post
#3
|
Advanced Member Group: Members Posts: 118 Joined: 18-September 12 Member No.: 17,803 |
it is just a quesstion, didnt feel i needed to give the code for this.
Basicly, i have a user table and a group table, UserID's is is sotred under the row "members" in the Group table. And since i am storing the info like this: (1 , 2 , 3, 4 ) in the members table. So basicly the code i have looks like this: CODE <?php if($rows["members"] == $users1["id"]){ echo $users1["name"]; }else{ echo "[ERROR: No Match Found in our Database]"; } as of now it displays "No Match Found in Out Database" or 1,2,3,4 i want it to display 1: John Doe (ID: Name) 2: Jon Doe (ID: Name) 3: Petter Doe (ID: Name) 4: Monica Doe (ID: Name) Hope this helped! This post has been edited by sanoj96: Mar 23 2019, 10:49 AM |
CharlesEF |
Mar 23 2019, 04:45 PM
Post
#4
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
$rows["members"] will never equal $users1["id"]. To be honest I would redesign the database. But, assuming you don't want to redesign your database then you need to convert $rows["members"] into an array (see explode command) then use PHP command in_array to check each value in the array against $users1["id"].
Example: $members = explode(", " , $rows["members"]); if(in_array($users1["id"], $members)) { echo $users1["name"]; } else { echo "[ERROR: No Match Found in our Database]"; } This code is untested but should get you started. Also, if members doesn't contain comma space ", " then the above code will fail. This post has been edited by CharlesEF: Mar 23 2019, 04:47 PM |
CharlesEF |
Mar 23 2019, 05:42 PM
Post
#5
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
Or, you can forget about the array plan and try this instead. Just use 'strpos' to test for $users1["id"]. Example:
CODE if(strpos($rows["members"], $users1["id"]) !== false) { echo $users1["name"]; } else { echo "[ERROR: No Match Found in our Database]"; } This post has been edited by CharlesEF: Mar 23 2019, 05:44 PM |
Lo-Fi Version | Time is now: 18th April 2024 - 09:32 PM |