Created
February 5, 2012 00:20
-
-
Save yandod/1741333 to your computer and use it in GitHub Desktop.
普通のPHPスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$keyword = ''; | |
if (isset($_POST['keyword'])) { | |
$keyword = $_POST['keyword']; | |
} | |
mysql_connect('localhost','user','password'); | |
mysql_select_db('cakephp_sample'); | |
mysql_query('set names utf8'); | |
$sql = sprintf( | |
"SELECT id,name,description FROM friends WHERE name LIKE '%s'", | |
mysql_real_escape_string('%'.$keyword.'%') | |
); | |
$result = mysql_query($sql); | |
$data = array(); | |
while ($row = mysql_fetch_assoc($result)) { | |
$data[] = $row; | |
} | |
?> | |
<html> | |
<head><title>テストページ</title></head> | |
<body> | |
<form action="list1.php" method="POST"> | |
<input name="keyword"><input type="submit"> | |
</form> | |
<ul> | |
<?php | |
foreach ($data as $row) { | |
echo '<li>'; | |
echo $row['name']; | |
echo $row['description']; | |
echo '</li>'; | |
} | |
?></ul> | |
</body></html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment