2

A value in a column named 'Marks' is stored as [45,56] in my DB. I wants to extract its value as 45 and 56 . I have tried like below. But not getting values separately .

$result =mysql_query("SELECT * FROM school where StudentID='$ss'") or die(mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
    $Fromtable_CurrMARK= $row['marks']; //getting as [45,56]
    $CurrMark = json_decode( $Fromtable_CurrMARK);
    $mark1 = $CurrMark[0];
    $mark2 = $CurrMark[1];
}
dstudeba
  • 8,878
  • 3
  • 32
  • 41
Dhanya
  • 91
  • 1
  • 8
  • 2
    The above seems to be right (as long as the field **really** contains `[45,46]`), have you tried dumping your data using `print_r($Fromtable_CurrMARK)` to see what it really contains? My guess would be that you don't get a valid result from the above query. – Cyclonecode Nov 12 '15 at 05:09
  • 1
    As a side note you should try to switch to something else like `PDO` or `mysqli` since the `mysql` extension is deprecated. – Cyclonecode Nov 12 '15 at 05:15
  • [Here is the answer to your question](http://stackoverflow.com/questions/14950466/how-to-split-the-name-string-in-mysql) – Dennis Y. Parygin Nov 12 '15 at 05:35

0 Answers0