1

Basically I have coded a PHP script to pull information from a JSON file and store it all in one column inside of my MySQL database, here is the format upon which I am storing the data.

(37.50!03:37:42pm PST)

So i basically have multiple entries of similar results stored inside brackets inside of one column.

Now i want limit the results displayed when i pull that information back from the database and display it on my webpage and i cant figure out how? Is there a simple way?

I have tried using LIMIT in my SQL statement but to my understanding(maybe i am wrong) that is used for limiting the number of rows returned and not used for one unique column.

Thank you for your time.

  • 3
    http://stackoverflow.com/questions/1258743/normalization-in-mysql – Sammitch Jan 14 '16 at 00:02
  • When you write a `SELECT` query, you list the columns you want to return after the `SELECT` keyword. So just put the column name that you want. – Barmar Jan 14 '16 at 00:16

1 Answers1

0

Honestly, it might be easier to accomplish this using PHP. You haven't posted the details of what the multiple data looks like but guessing it is something like this '(37.50!03:37:42pm PST),(37.50!03:37:42pm PST),(37.50!03:37:42pm PST)'.

When fetching the data you split the data and turn it into an array and with preg_split you can have it only return you a limited number of the split array (in the example it uses 50). Post a comment if this doesn't work or if you are able to clarify the format of what multiple entries looks like in the field.

Example:

$rs = mysqli_query($conn, "SELECT yourColumn FROM your_table order by write_here_your_dec_name desc, your_desc_name");

while ($row=mysqli_fetch_assoc($rs)) {
    $parts = preg_split('~,~', $row['yourColumn'], 50, PREG_SPLIT_NO_EMPTY);
    foreach ($parts as $part ) {
        echo "$part<br>";
    }
}
Clay
  • 4,700
  • 3
  • 33
  • 49