Hello I have a question that could seem complicated. But I will try to explain it as better as I can. This is a problem of logic.
I have a database table. This database table (lets call it Table A) contains some strings.
Strings are composed by these rows:
ID (auto increment)
Text
Date
Time
Type
IDAccount.
Now some of these strings are equal. I need to SELECT all the strings that are equal and have them in one result.
So the logic of the code will be:
SELECT * from Table A WHERE mySQL find stringS with same Text, Date and Time.
Then “echo” for only ONE TIME(so not for any string, since they are perfectly equal): Text Date Time. (this will be an HTML DIV)
Then in these strings we have some other rows that have DIFFERENT values.
Type
IDAccount.
The PHP will have to show for these rows(Type, IDAccount) all the different values found for the EQUAL strings above.
So the final DIV would be:
Text (one time)
Date (one time)
Time (one time)
Type (every different value that is found will be shown)
IDAccount (every different value that is found will be shown).
I know this is something difficult to understand. I hope someone got my point.
The most important thing is “how to say to mySQL to SELECT all the strings that are equale for rows Text , Date and Time and show 1 result in the final DIV, and then how to show the not equal values for all those strings (Type, IDAccount) and show all of them in the same final DIV”.
Any help would be very appreciated!!
Lets play with it =D
I think the best way to do this would be in the PHP code, rather than in SQL.
You can achieve this by simply creating an associative array in PHP, using the “text” field as a key, that contains the data you want – and populating it as you pull information from the database.
An example:
SQL:
SELECT * FROM myTablePHP Code:
This will give you an array as follows:
and so on.
I hope that’s helpful.
EDIT: Poster asked for help with display.
/* Alternatively, you can loop each array contained in $info if you need more control */