duanli6618
2015-08-02 18:14
浏览 92

从mysql查询中读取PHP数组作为c#中的字符串

I have a PHP file and a C# app. In the php file it returns a Array of the rows that i selected from a mysql table. I want to read that Array and deserialize it so the result of a row can be parsed inside a textBlock. My PHP script:

    <?php
mysql_connect("-----", "------", "-----") or
    die("Could not connect: " . mysql_error());
mysql_select_db("------");

$list = array();
$query = "SELECT SongName,ArtistName,Thumbnail,MediaLink FROM Library";
$resource = mysql_query($query);
while($row = mysql_fetch_assoc($resource))
{
   $list['SongName' . (1 + count($list))] = $row['SongName'];
}
$list = array('row' => count($list)) + $list;
echo json_encode(array($list));
?> 

How do i get the ArtistName, Thumbnail and medialink inside the array? How do i read this in C# so my textblock will show: ArtistName. Technologies: Windows 10 Store apps(C#, XAML)

If somebody could help that'd be great,

Christos K

图片转代码服务由CSDN问答提供 功能建议

我有一个PHP文件和一个C#应用程序。 在php文件中它返回一个行数组 从mysql表中选择。 我想读取该数组并对其进行反序列化,以便可以在textBlock中解析行的结果。 我的PHP脚本:

 &lt;  ?php 
mysql_connect(“-----”,“------”,“-----”)或
 die(“无法连接:”。mysql_error()); 
mysql_select_db(  “------”); 
 
 $ list = array(); 
 $ query =“SELECT SongName,ArtistName,Thumbnail,MediaLink FROM Library”; 
 $ resource = mysql_query($ query);  
while($ row = mysql_fetch_assoc($ resource))
 {
 $ list ['SongName'。  (1 + count($ list))] = $ row ['SongName']; 
} 
 $ list = array('row'=&gt; count($ list))+ $ list; 
echo json_encode(array  ($列表));吗?
&GT;  
   
 
 

如何在数组中获取ArtistName,Thumbnail和medialink? 如何在C#中阅读此内容,以便我的文本块显示:ArtistName。 技术: Windows 10商店应用程序(C#,XAML)

如果有人可以提供帮助,那就很好了,

Christos K

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • dongzouya5792 2015-08-02 18:41
    最佳回答

    Simple, you pull all the required data from the database and return it as an array, just put the whole $row into the array you are about to return

    <?php
    mysql_connect("-----", "------", "-----") or
        die("Could not connect: " . mysql_error());
    
    mysql_select_db("------");
    
    $list = array();
    
    $query = "SELECT SongName,ArtistName,Thumbnail,MediaLink FROM Library";
    $resource = mysql_query($query);
    while($row = mysql_fetch_assoc($resource))
    {
       $list[] = $row;
    }
    
    echo json_encode($list);
    ?> 
    

    Now you should receive all the data you want in the javascript. Just use the javascript debugger to see what it looks like

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题