开发者

initialize an array with dummy values

 while ($row = mysql_fetch_object($result)) 开发者_如何学运维{
    $data[] = $row;
    echo "<div id='captionbox' style='width: 110px;float:left;color:#FFF;text-align:center;'>";
        echo "<a href='#' class='thumb'><img class='thumb-img' value = ".$row->aid." onclick='getVote(".$row->aid.", \"".$row->atitle."\")' src='images/roadies/th".$row->aid.".jpg' /> </a>";
    echo "<input  type = hidden name = aid id = rd".$row->aid." value = ".$row->aid.">".$row->atitle."</input>";
    echo "</div>";
    }

    $jsfriend = json_encode($data);

In the above PHP code, I am adding the mysql rows into an array $data. then i am making a JSON object from that array. before I come into the while loop I want to create the array $data and initialize the $data[0] pointer with dummy values as I do not want to use the [0] pointer values. can this be done?

I hope I am making sense.


Something like this?

$data=array("dummyfirst");
while(....


Seems to me all you need to do is simply assign a value before the while loop.

$data[0] = "Dummy Values"; // the 0 isn't really needed if this is a new array
while ($row = mysql_fetch_object($result)) {
  $data[] = $row; // first time through will be in $data[1]
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜