2014-05-17 32 views
-1

I have a SQL query statement that will return a particular set of result. Such as ID, Names, Price. I have no problem with that.将取数组放入<a href> value in PHP

However i am trying to add a link within the echo loop and set ID as the value so that i can post it to another page. Would that be possible ?

while ($row = mysql_fetch_array($result)) { 
    echo 
    "".$row{'Url'}."<br>"; 
    echo 
    "Name:".$row{'Name'}."<br>"; 
    echo 
    "Price: $ ".$row{'Price'}."<br>"; 
    echo 
    '<div class = "qwerty" data-countdown= '.$row{'Time'}.'></div>'; 
    echo 
    "Location:".$row{'Location'}."<br>"; 
    echo 
    "Description:".$row{'Description'}."<br>"; 
echo ''.$row{'ID'}.''; 


echo '<a href="" onclick="jsScript()">Show Comments</a> 
    <form id="displayComments" style="display:none" target="jsScript()" method="post"> 
    <input type="hidden" name="run" value=".$row{'ID'}." /> 
    </form>'; 
+1

您知道在php中可以通过$ arrayName [$ key]访问数组内容吗? – mleko

+0

不是。我没有意识到。感谢分享,我也会检查一下。 –

回答

1

You missed quotes. value="'.$row['ID'].'"

echo '<a href="" onclick="jsScript()">Show Comments</a> <form id="displayComments" style="display:none" target="jsScript()" method="post"> <input type="hidden" name="run" value="'.$row['ID'].'" /> </form>';

And php array use [ ]

http://ua2.php.net/manual/en/language.types.array.php

+0

干杯队友。当它变得非常混乱时,关闭所有引号会非常糟糕。 –