dongzhong7443 2013-07-08 17:19
浏览 21
已采纳

使用数组抓取所有MYSQL行

Hi I'm trying to output all of the rows and information from my table :

id,Symbol,entry,exit,openclosed,entrydate,longshort,target_one,target_two,target_three,notes

This is through this script I'm working on to get this functionality. Right now I'm only outputting one of the database entries. This entry of course being the last one. For reference the last entry symbol is GLD. I'd like it to continue with the next symbols, but can't seem to get it to output. The outputted data for quote_0,quote_1 ect. come from yahoo as an array.

<?php
error_reporting(E_ALL ^ E_NOTICE);
ini_set("display_errors", 1);
//begin
    include "storescripts/connect_to_mysql.php"; 
    $sql = mysql_query("SELECT * FROM stockpicks ORDER BY id LIMIT 100");
    $productCount = mysql_num_rows($sql); // count the output amount
    if ($productCount > 0) {
        // get all the product details
        while($row = mysql_fetch_array($sql)){ 
            $id = $row["id"];
            $symbol = $row["symbol"];
         }
    }
    mysql_close();
    //end
        if(empty($symbol)) {
            echo nothing;
        }
            else {
                $open = fopen("http://quote.yahoo.com/d/quotes.csv?s=$symbol&f=sl1d1t1c1ohgv&e=.csv", "r");
                $quote = fread($open, 1000);

                fclose($open);

                $quote = str_replace("\"", "", $quote);
                $quote = explode(",", $quote);

                $quote_0 = ($quote[0]);
                $quote_1 = ($quote[1]);
                $quote_2 = ($quote[2]);
                $quote_3 = ($quote[3]);
                $quote_4 = ($quote[4]);
                $quote_5 = ($quote[5]);
                $quote_6 = ($quote[6]);
                $quote_7 = ($quote[7]);
                $quote_8 = ($quote[8]);

                echo "<div class='symbol'><div class='quote'>Company: $quote_0</div></div>";
                echo "<div class='leftofStocks'><div class='row'><div class='quote'>Last trade: $$quote_1</div>";
                echo "<div class='quote'>Date: $quote_2</div>";
                echo "<div class='quote'>Time: $quote_3</div>";
                echo "<div class='quote'>From Previous: $$quote_4</div></div>";
                echo "<div class='row'><div class='quote'>Open: $$quote_5</div>";
                echo "<div class='quote'>High: $$quote_6</div>";
                echo "<div class='quote'>Low: $$quote_7</div>";
                echo "<div class='quote'>Volume: $quote_8</div></div>";
}
?>          
  • 写回答

2条回答 默认 最新

  • dte66654 2013-07-08 17:25
    关注

    You have to more your output into the while loop to get access to each of the values in your table.

    <?php
    error_reporting(E_ALL ^ E_NOTICE);
    ini_set("display_errors", 1);
    //begin
        include "storescripts/connect_to_mysql.php"; 
        $sql = mysql_query("SELECT * FROM stockpicks ORDER BY id LIMIT 100");
        $productCount = mysql_num_rows($sql); // count the output amount
        if ($productCount > 0) {
            // get all the product details
            while($row = mysql_fetch_array($sql)){ 
                $id = $row["id"];
                $symbol = $row["symbol"];
                if(empty($symbol)) {
                    echo nothing;
                }
                    else {
                        $open = fopen("http://quote.yahoo.com/d/quotes.csv?s=$symbol&f=sl1d1t1c1ohgv&e=.csv", "r");
                        $quote = fread($open, 1000);
    
                        fclose($open);
    
                        $quote = str_replace("\"", "", $quote);
                        $quote = explode(",", $quote);
    
                        $quote_0 = ($quote[0]);
                        $quote_1 = ($quote[1]);
                        $quote_2 = ($quote[2]);
                        $quote_3 = ($quote[3]);
                        $quote_4 = ($quote[4]);
                        $quote_5 = ($quote[5]);
                        $quote_6 = ($quote[6]);
                        $quote_7 = ($quote[7]);
                        $quote_8 = ($quote[8]);
    
                        echo "<div class='symbol'><div class='quote'>Company: $quote_0</div></div>";
                        echo "<div class='leftofStocks'><div class='row'><div class='quote'>Last trade: $$quote_1</div>";
                        echo "<div class='quote'>Date: $quote_2</div>";
                        echo "<div class='quote'>Time: $quote_3</div>";
                        echo "<div class='quote'>From Previous: $$quote_4</div></div>";
                        echo "<div class='row'><div class='quote'>Open: $$quote_5</div>";
                        echo "<div class='quote'>High: $$quote_6</div>";
                        echo "<div class='quote'>Low: $$quote_7</div>";
                        echo "<div class='quote'>Volume: $quote_8</div></div>";
                }
             }
        }
        mysql_close();
        //end
    
    ?> 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制