从动态创建的 html 表中检索数据


Retrieve data from a dynamically created html table

这是我的问题:

有一个动态创建的 html 表,我得到了mysql_fetch_array当用户单击同一行的最后一个单元格(代码中的circle_plus_grey.png)时,我实际上想检索一行的第一个单元格。

如果可能的话,我想使用PHP检索第一个单元格内容(song_name),我的最终目标是发送一封包含第一个单元格内容的电子邮件。

非常感谢您的帮助,这是我的代码:

<?php
    $query = $_GET['mood'];
    // gets value sent over search form
    $min_length = 1;
    // you can set minimum length of the query if you want
    if(strlen($query) >= $min_length){ // if query length is more or equal minimum length then
        $query = htmlspecialchars($query);
        // changes characters used in html to their equivalents, for example: < to &gt;
        $query = mysql_real_escape_string($query);
        // makes sure nobody uses SQL injection
        $raw_results = mysql_query("SELECT * FROM song_main
            WHERE (`song_name` LIKE '%".$query."%') OR (`song_artist` LIKE '%".$query."%') OR (`song_album` LIKE '%".$query."%')" ) or die(mysql_error());
            $num = mysql_num_rows($raw_results);

        if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do following

            while($results = mysql_fetch_array($raw_results)){

             echo '<table id="hor-minimalist-a" summary="songs table">
                        <thead>
                            <tr>
                            </tr>
                        </thead>
                    <tbody>';

            echo'<td width="270px">'. ucfirst($results['song_name']).'</td>';
            echo'<td width="200px">'. ucfirst($results['song_artist']).'</td>';
            echo'<td width="270px">'. ucfirst($results['song_album']).'</td>';
                echo '<td>';
                echo '<a href="linkto.php"/><img src="images/circle_plus_grey.png">';
                echo '<a href="#"/><img src="images/play_overlay.png">';
                echo '</td>'; 

                }
                // posts results gotten from database(title and text) you can also show id ($results['id'])

        }
        else{ // if there is no matching rows do following
            echo "No results";
        }
    }
    else{ // if query length is less than minimum
        echo "Minimum length is ".$min_length;
    }
    echo'</tr>
                </tbody>
                </table>';
?>    

您可以将第一列内容作为 GET 参数发送到其他脚本。

echo '<a href="linkto.php?data='.ucfirst($results['song_name']).'"><img src="images/circle_plus_grey.png">';