Log in

View Full Version : PHP Select From Multiple Table with Separated Comma



oyotsuket
04-16-2020, 04:25 PM
I have two tables in MySql.. First table's name is ANIMAL and second table's name is DESCRIPTION


-----|------ ------|-------------|--------
ida | name idb | desc | barcode
-----|------ ------|-------------|--------
1 | eagle 1 | bla bla bla | 1,3,4
2 | lion 2 | cla cla cla | 3,4
3 | bird 3 | dla dla dla | 1,2,3
4 | bee 4 | ela ela ela | 2,4
-----|------ ------|-------------|--------


then I want to get all desc value from DESCRIPTION that related with bird in ANIMAL table. I tried with the following line code:

$check = mysqli_query($dbconnection, "SELECT desc FROM description LEFT OUTER JOIN animal ON description.barcode=animal.ida WHERE animal.name='bird'");
while($data=mysqli_fetch_array($check)) {
$result = $data['desc'];
}

but no result from my above line code. I have search in many tutorial but still no result too. Any solution how to get the data as I need? thanks before.

james438
04-16-2020, 08:52 PM
Your post accidentally got flagged as spam. Our spam filter can be overly strict with new visitors.

One thing that I note, and it may cause troubles later if not already, is you have one column labeled as desc, which in MySQL is a command to sort values from highest to lowest and I'll admit is confusing me a bit.

It looks like you are trying to work with a normalized table. Is that correct? Please see this useful introductory article on Normalized tables here (http://mikehillyer.com/articles/an-introduction-to-database-normalization/).

It seems obvious, but just to be sure, I take it that ida corresponds with idb?

EDIT: I tried to recreate your table for DESCRIPTION and I was flagged for trying to use a reserved word (desc) as a column name.

To help me out a bit more, could you list a couple example results and change the content you have in the desc column to more relevant data?