这是我的问题:
我有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 >
$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>';
?>
答案 0 :(得分:0)
您可以将第一列内容作为GET参数发送到另一个脚本。
echo '<a href="linkto.php?data='.ucfirst($results['song_name']).'"><img src="images/circle_plus_grey.png">';