doubu5154 2019-01-14 15:43
浏览 150
已采纳

MYSQL只选择一部分列

I running a simple mysql query and trying to grab from the src column but I only want to grab the "video#.mp4" part - not the whole value (see picture attached below)

If anyone knows how to achieve this... I really appreciated it! Thank you for any help!

enter image description here

Code:

$con=mysqli_connect("localhost","test","123","test");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql="SELECT id, title, src, type, poster_img FROM TABLE_NAME";

if ($result=mysqli_query($con,$sql))
{

$id = 0;
// Fetch one and one row
while ($row=mysqli_fetch_row($result))
{

// Show video#.mp4 here ///
echo '';

$id++;   

}

// Free result set
mysqli_free_result($result);
}
mysqli_close($con);
  • 写回答

1条回答

  • doupi7619 2019-01-14 15:54
    关注

    I suggest you to store quality and video name in 2 different columns, because this will help you in searching etc.

    In your example, you can achieve your desired result by using json_decode but again, it will work if you have valid json in src column.

    Example:

    $string = '[{"quality":"default","mp4":"video2.mp4"}]';
    $array = json_decode($string,true);
    print_r($array);
    

    Result:

    Array ( [0] => Array ( [quality] => default [mp4] => video2.mp4 ) )
    

    Now you can get the index mp4 easily, if you have multiple file format, than you can group than inside your loop.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?