这是我的问题:

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

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

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

<?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">';

关于php - 从动态创建的html表中检索数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18932171/

10-16 05:56