Skip to content

Instantly share code, notes, and snippets.

@yandod
Created February 5, 2012 00:20
Show Gist options
  • Save yandod/1741333 to your computer and use it in GitHub Desktop.
Save yandod/1741333 to your computer and use it in GitHub Desktop.
普通のPHPスクリプト
<?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