dqnk57224 2012-03-22 20:09
浏览 67
已采纳

PHP Array into mysql select Statement

I have an issue where i have a textarea in a form where users can enter names on seperate lines. On submit I explode the " ".

I then want to pass the values from the array into an Select statement, but when i run the script it only returns one result (the last one) from the array..

here is the code below.

echo "<h1> You searched for the following names </h1>";

include 'conn.php';
mysql_select_db("email_finder", $con);
$Email = $_POST['EmailBox'];
$str = $Email;  
$lines = explode("
", $str);
//$in = implode(',', $lines); 
//$userStr = implode(',', $lines);


 echo "<table border='0'>
<tr>
<th style='color:White' width='180px'; bgcolor=#999999>Name</th>
<th style='color:White' width='250px'; bgcolor=#999999>Email</th>
</tr>";

echo "<pre>";
print_r($lines);
echo "</pre>";

foreach($lines as $array_element) { 

$result = mysql_query("SELECT * FROM `emails` WHERE `Name` IN('$array_element') ORDER BY `LastName`");

echo "<pre>";
print_r($array_element);
echo "</pre>";

while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { 

echo "<tr>";
echo "<td style='padding-left:5px'><b> ".$row['Name']."</b>&nbsp:&nbsp</td>";
printf("<td style='padding-left:5px'><a href=mailto:" .$row['Email'].  ">"  .$row['Email']. "</a></td>");
echo "</tr>";   

echo "<pre>";
print_r($row);
echo "</pre>";


}
}
echo "</table><br />";

echo "Email <b>ALL</b> these Students: <a href=mailto:".$row['Email']." >Click Here</a> <br />";

mysql_close($con);


echo '<br />';

If you can help i would be greatful

Thanks

  • 写回答

2条回答 默认 最新

  • dongtan7639 2012-03-22 20:19
    关注

    Guessing you've got OS specific line endings tripping you up. Try preg_split

    $lines = preg_split("/\
    |\|\\
    /", $str);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗