pdoで予約情報をmysqlに格納する

■mysql側
まず、テーブルを作ります。
1.管理画面側で予約情報をcake.phpで閲覧できるようにしたいので、テーブル名は複数にします。
2.いたずらの予約が複数回あった場合は、そのipアドレスをhtaccessでアクセス制御できるようにしたいので、ipアドレスと、user agentのカラムを作ります。
3.予約送信時間の型は、yyyy-mm-ddではなくyyyy-mm-dd h:i:sなので、dateではなくdatetimeにします。(間違えました)
4.管理者画面で後からメモをinsert出来るようにしたいので、memoのカラムを作ります。

create table reserve.masters(
        id int unsigned auto_increment primary key,
        day varchar(255),
	time1 varchar(41),
	time2 varchar(41),
	course varchar(41),
	charge varchar(41),
	name varchar(41),
	mail varchar(41),
	ip varchar(255),
	useragent varchar(255),
	created datetime,
	memo varchar(255)
);

■php側
普通のpdoです。REMOTE_ADDRとHTTP_USER_AGENTでユーザー情報を取得しています。

$start = $_POST['stime'];
	$end = $_POST['etime'];

	$ip = $_SERVER['REMOTE_ADDR'];
	$useragent = $_SERVER['HTTP_USER_AGENT'];
	$date = date('Y-m-d H:i:s');

	$dsn = "mysql:dbname=reserve;host=localhost";
	$user = "hoge";
	$password = "hogehoge";	 
	try {
	    $dbh = new PDO($dsn, $user, $password);
	} catch (PDOException $e){
	    print('connection failed:'.$e->getMessage());
	} 

	$stmt = $dbh -> prepare("INSERT INTO masters (day, time1, time2, course, charge, name, mail, ip, useragent, created) VALUES(:day, :time1, :time2, :course, :charge, :name, :mail, :ip, :useragent, :created)");
	$stmt->bindParam(':day', $_POST['day'], PDO::PARAM_STR);
	$stmt->bindParam(':time1', $_POST['time1'], PDO::PARAM_STR);
	$stmt->bindParam(':time2', $_POST['time2'], PDO::PARAM_STR);
	$stmt->bindParam(':course', $_POST['course'], PDO::PARAM_STR);
	$stmt->bindParam(':charge', $_POST['charge'], PDO::PARAM_STR);
	$stmt->bindParam(':name', $_POST['name'], PDO::PARAM_STR);
	$stmt->bindParam(':mail', $_POST['mail'], PDO::PARAM_STR);
	$stmt->bindParam(':ip', $ip, PDO::PARAM_STR);
	$stmt->bindParam(':useragent', $useragent, PDO::PARAM_STR);
	$stmt->bindParam(':created', $date, PDO::PARAM_STR);
    $stmt->execute();

■画面遷移
1.入力フォーム

2.確認画面

3.thankyou画面

4.メール受信

5.mysql

ここまでは特に問題なさそうです。
次はvalidation周りを作っていきたいと思います。

簡易的な確認画面

mb_send_mailでメールを送る。

if(!isset($_POST['name'])){
   header('Location: http://192.168.33.10:8000');
} else {
	$name = $_POST['name'];
	$mail = $_POST['mail'];
	$day = $_POST['day'];
	$time = $_POST['time'];
	$hour = floor($time / 60);
	$minutes = $time % 60;
	if(!$minutes == NUll ){
			$stime = $hour.":".$minutes;
		}  else {
			$stime = $hour.":00";
		}
	$time =$_POST['time'] + $_POST['course'];
	$hour = floor($time / 60);
	$minutes = $time % 60;
	if(!$minutes == NUll ){
			$etime = $hour.":".$minutes;
		}  else {
			$etime = $hour.":00";
		}
	$course = $_POST['course'];
	$lawyer = $_POST['lawyer'];
}

if(isset($_POST["submit"])){
	mb_language('ja');
	mb_internal_encoding("utf-8");

	$start = $_POST['stime'];
	$end = $_POST['etime'];

	$subject = "[自動送信]お問い合わせありがとうございます";

	$body = <<< EOM

 {$name} 様

この度はご予約ありがとうございます。
以下のご予約内容を承りました。
===================================================
【 お名前 】 
{$name} 様

【 メールアドレス 】 
{$mail}

【 ご予約日時 】 
{$day} {$start} ~ {$end}

【 コース 】
{$course} 分

【 担当弁護士 】 
{$lawyer}
===================================================

内容を確認のうえ、回答させて頂きます。

〇〇弁護士事務所
EOM;
     $fromEmail = "hoge@gmail.com";
     $fromName = "〇〇事務所";
     $header = "From:".mb_encode_mimeheader($fromName)."<$fromEmail>";
     mb_send_mail($mail,$subject,$body,$header);

     // header("Location: thanks.php");
     exit;
}
?>
<form action="" method="post">
<input type="hidden" name="name" value="<?php echo $name; ?>">
<input type="hidden" name="mail" value="<?php echo $mail; ?>">
<input type="hidden" name="day" value="<?php echo $day; ?>">
<input type="hidden" name="stime" value="<?php echo $stime; ?>">
<input type="hidden" name="etime" value="<?php echo $etime; ?>">
<input type="hidden" name="course" value="<?php echo $course; ?>">
<input type="hidden" name="lawyer" value="<?php echo $lawyer; ?>">
<h1>お問い合わせ内容の確認</h1>
<p>お問い合わせ内容はこちらで宜しいでしょうか?<br>
よろしければ「送信する」ボタンを押してください。<hr>
<b>お名前</b><br>
<?php echo $name; ?>様<br>
<b>メールアドレス</b><br>
<?php echo $mail; ?><br>
<b>日付</b><br>
<?php echo $day; ?><br>
<b>時間</b><br>
<?php echo $stime; ?>~<?php echo $etime; ?><br>
<b>コース</b><br>
<?php echo $course; ?>分<br>
<b>担当</b><br>
<?php echo $lawyer; ?><br><br>
<input type="button" value="内容を修正する" onclick="history.back(-1)">
<button type="submit" name="submit">送信する</button>
</form>

メール

str_replaceの回数指定

03-6803-5794から、”03-“をstr_replaceすると、重複して削除され、685794になってしまう。

preg_replaceなら、回数を指定できる。

$num1 =  strstr($number, '-', true);
$num = preg_replace("/".$num1."-/","", $number, 1);
$num2 =  strstr($num, '-', true);
$num3 = str_replace("".$num2."-","", $num);

電話番号から、市外局番、市内局番、加入者番号を抜き出す

strstr trueでハイフン(-)より前を抜き出し、str_replaceで抜き出した数+ハイフンを削除して、またstrstr trueでハイフン(-)より前を抜き出します。

$number = empty($_GET["p"])? NULL: $_GET["p"];
$number = str_replace('-','', $number);

require "function.php";

$number = format_phone_number($number);

$num1 =  strstr($number, '-', true);
$num = str_replace("".$num1."-","", $number);
$num2 =  strstr($num, '-', true);
$num3 = str_replace("".$num2."-","", $num);

echo $num1 . "<br>";
echo $num2 . "<br>";
echo $num3;

おおおおお

車輪の再発明:reinventing the wheel

電話番号の市外局番、市内局番を分岐させようと条件分岐式を書いていましたが

$number = str_replace('-','', $number);

$num_2 = substr($number, 0, 2);
$num_5 = substr($number, 0, 5);
if($num_2 == '03' or $num_2 == '04' or $num_2 == '06'){
  $num1 = substr($number, 0, 2);
  $num2 = substr($number, 2, 4);
  $num3 = substr($number, 6, 4);
}elseif($num_5 == '01372' or $num_5 == '01374' or $num_5 == '01377' or $num_5 == '' or $num_5 == '' or $num_5 == '' or $num_5 == '' or $num_5 == '' or $num_5 == '' or $num_5 == '' or $num_5 == '' or $num_5 == '' or $num_5 == '' or $num_5 == '' or $num_5 == '' or $num_5 == '' or $num_5 == '' or $num_5 == '' or $num_5 == '' or $num_5 == '')

書いている途中で車輪の再発明は辞めようと思いました。
function.php

function format_phone_number($input, $strict = false) {
    $groups = array(
        5 => 
        array (
            '01564' => 1,
            '01558' => 1,
            '01586' => 1,
            '01587' => 1,
            '01634' => 1,
            '01632' => 1,
            '01547' => 1,
            '05769' => 1,
            '04992' => 1,
            '04994' => 1,
            '01456' => 1,
            '01457' => 1,
            '01466' => 1,
            '01635' => 1,
            '09496' => 1,
            '08477' => 1,
            '08512' => 1,
            '08396' => 1,
            '08388' => 1,
            '08387' => 1,
            '08514' => 1,
            '07468' => 1,
            '01655' => 1,
            '01648' => 1,
            '01656' => 1,
            '01658' => 1,
            '05979' => 1,
            '04996' => 1,
            '01654' => 1,
            '01372' => 1,
            '01374' => 1,
            '09969' => 1,
            '09802' => 1,
            '09912' => 1,
            '09913' => 1,
            '01398' => 1,
            '01377' => 1,
            '01267' => 1,
            '04998' => 1,
            '01397' => 1,
            '01392' => 1,
        ),
        4 => 
        array (
            '0768' => 2,
            '0770' => 2,
            '0772' => 2,
            '0774' => 2,
            '0773' => 2,
            '0767' => 2,
            '0771' => 2,
            '0765' => 2,
            '0748' => 2,
            '0747' => 2,
            '0746' => 2,
            '0826' => 2,
            '0749' => 2,
            '0776' => 2,
            '0763' => 2,
            '0761' => 2,
            '0766' => 2,
            '0778' => 2,
            '0824' => 2,
            '0797' => 2,
            '0796' => 2,
            '0555' => 2,
            '0823' => 2,
            '0798' => 2,
            '0554' => 2,
            '0820' => 2,
            '0795' => 2,
            '0556' => 2,
            '0791' => 2,
            '0790' => 2,
            '0779' => 2,
            '0558' => 2,
            '0745' => 2,
            '0794' => 2,
            '0557' => 2,
            '0799' => 2,
            '0738' => 2,
            '0567' => 2,
            '0568' => 2,
            '0585' => 2,
            '0586' => 2,
            '0566' => 2,
            '0564' => 2,
            '0565' => 2,
            '0587' => 2,
            '0584' => 2,
            '0581' => 2,
            '0572' => 2,
            '0574' => 2,
            '0573' => 2,
            '0575' => 2,
            '0576' => 2,
            '0578' => 2,
            '0577' => 2,
            '0569' => 2,
            '0594' => 2,
            '0827' => 2,
            '0736' => 2,
            '0735' => 2,
            '0725' => 2,
            '0737' => 2,
            '0739' => 2,
            '0743' => 2,
            '0742' => 2,
            '0740' => 2,
            '0721' => 2,
            '0599' => 2,
            '0561' => 2,
            '0562' => 2,
            '0563' => 2,
            '0595' => 2,
            '0596' => 2,
            '0598' => 2,
            '0597' => 2,
            '0744' => 2,
            '0852' => 2,
            '0956' => 2,
            '0955' => 2,
            '0954' => 2,
            '0952' => 2,
            '0957' => 2,
            '0959' => 2,
            '0966' => 2,
            '0965' => 2,
            '0964' => 2,
            '0950' => 2,
            '0949' => 2,
            '0942' => 2,
            '0940' => 2,
            '0930' => 2,
            '0943' => 2,
            '0944' => 2,
            '0948' => 2,
            '0947' => 2,
            '0946' => 2,
            '0967' => 2,
            '0968' => 2,
            '0987' => 2,
            '0986' => 2,
            '0985' => 2,
            '0984' => 2,
            '0993' => 2,
            '0994' => 2,
            '0997' => 2,
            '0996' => 2,
            '0995' => 2,
            '0983' => 2,
            '0982' => 2,
            '0973' => 2,
            '0972' => 2,
            '0969' => 2,
            '0974' => 2,
            '0977' => 2,
            '0980' => 2,
            '0979' => 2,
            '0978' => 2,
            '0920' => 2,
            '0898' => 2,
            '0855' => 2,
            '0854' => 2,
            '0853' => 2,
            '0553' => 2,
            '0856' => 2,
            '0857' => 2,
            '0863' => 2,
            '0859' => 2,
            '0858' => 2,
            '0848' => 2,
            '0847' => 2,
            '0835' => 2,
            '0834' => 2,
            '0833' => 2,
            '0836' => 2,
            '0837' => 2,
            '0846' => 2,
            '0845' => 2,
            '0838' => 2,
            '0865' => 2,
            '0866' => 2,
            '0892' => 2,
            '0889' => 2,
            '0887' => 2,
            '0893' => 2,
            '0894' => 2,
            '0897' => 2,
            '0896' => 2,
            '0895' => 2,
            '0885' => 2,
            '0884' => 2,
            '0869' => 2,
            '0868' => 2,
            '0867' => 2,
            '0875' => 2,
            '0877' => 2,
            '0883' => 2,
            '0880' => 2,
            '0879' => 2,
            '0829' => 2,
            '0550' => 2,
            '0228' => 2,
            '0226' => 2,
            '0225' => 2,
            '0224' => 2,
            '0229' => 2,
            '0233' => 2,
            '0237' => 2,
            '0235' => 2,
            '0234' => 2,
            '0223' => 2,
            '0220' => 2,
            '0192' => 2,
            '0191' => 2,
            '0187' => 2,
            '0193' => 2,
            '0194' => 2,
            '0198' => 2,
            '0197' => 2,
            '0195' => 2,
            '0238' => 2,
            '0240' => 2,
            '0260' => 2,
            '0259' => 2,
            '0258' => 2,
            '0257' => 2,
            '0261' => 2,
            '0263' => 2,
            '0266' => 2,
            '0265' => 2,
            '0264' => 2,
            '0256' => 2,
            '0255' => 2,
            '0243' => 2,
            '0242' => 2,
            '0241' => 2,
            '0244' => 2,
            '0246' => 2,
            '0254' => 2,
            '0248' => 2,
            '0247' => 2,
            '0186' => 2,
            '0185' => 2,
            '0144' => 2,
            '0143' => 2,
            '0142' => 2,
            '0139' => 2,
            '0145' => 2,
            '0146' => 2,
            '0154' => 2,
            '0153' => 2,
            '0152' => 2,
            '0138' => 2,
            '0137' => 2,
            '0125' => 2,
            '0124' => 2,
            '0123' => 2,
            '0126' => 2,
            '0133' => 2,
            '0136' => 2,
            '0135' => 2,
            '0134' => 2,
            '0155' => 2,
            '0156' => 2,
            '0176' => 2,
            '0175' => 2,
            '0174' => 2,
            '0178' => 2,
            '0179' => 2,
            '0184' => 2,
            '0183' => 2,
            '0182' => 2,
            '0173' => 2,
            '0172' => 2,
            '0162' => 2,
            '0158' => 2,
            '0157' => 2,
            '0163' => 2,
            '0164' => 2,
            '0167' => 2,
            '0166' => 2,
            '0165' => 2,
            '0267' => 2,
            '0250' => 2,
            '0533' => 2,
            '0422' => 2,
            '0532' => 2,
            '0531' => 2,
            '0436' => 2,
            '0428' => 2,
            '0536' => 2,
            '0299' => 2,
            '0294' => 2,
            '0293' => 2,
            '0475' => 2,
            '0295' => 2,
            '0297' => 2,
            '0296' => 2,
            '0495' => 2,
            '0438' => 2,
            '0466' => 2,
            '0465' => 2,
            '0467' => 2,
            '0478' => 2,
            '0476' => 2,
            '0470' => 2,
            '0463' => 2,
            '0479' => 2,
            '0493' => 2,
            '0494' => 2,
            '0439' => 2,
            '0268' => 2,
            '0480' => 2,
            '0460' => 2,
            '0538' => 2,
            '0537' => 2,
            '0539' => 2,
            '0279' => 2,
            '0548' => 2,
            '0280' => 2,
            '0282' => 2,
            '0278' => 2,
            '0277' => 2,
            '0269' => 2,
            '0270' => 2,
            '0274' => 2,
            '0276' => 2,
            '0283' => 2,
            '0551' => 2,
            '0289' => 2,
            '0287' => 2,
            '0547' => 2,
            '0288' => 2,
            '0544' => 2,
            '0545' => 2,
            '0284' => 2,
            '0291' => 2,
            '0285' => 2,
            '0120' => 3,
            '0570' => 3,
            '0800' => 3,
            '0990' => 3,
        ),
        3 => 
        array (
            '099' => 3,
            '054' => 3,
            '058' => 3,
            '098' => 3,
            '095' => 3,
            '097' => 3,
            '052' => 3,
            '053' => 3,
            '011' => 3,
            '096' => 3,
            '049' => 3,
            '015' => 3,
            '048' => 3,
            '072' => 3,
            '084' => 3,
            '028' => 3,
            '024' => 3,
            '076' => 3,
            '023' => 3,
            '047' => 3,
            '029' => 3,
            '075' => 3,
            '025' => 3,
            '055' => 3,
            '026' => 3,
            '079' => 3,
            '082' => 3,
            '027' => 3,
            '078' => 3,
            '077' => 3,
            '083' => 3,
            '022' => 3,
            '086' => 3,
            '089' => 3,
            '045' => 3,
            '044' => 3,
            '092' => 3,
            '046' => 3,
            '017' => 3,
            '093' => 3,
            '059' => 3,
            '073' => 3,
            '019' => 3,
            '087' => 3,
            '042' => 3,
            '018' => 3,
            '043' => 3,
            '088' => 3,
            '050' => 4,
        ),
        2 => 
        array (
            '04' => 4,
            '03' => 4,
            '06' => 4,
        ),
    );
    $groups[3] += 
        $strict ?
        array(
            '020' => 3,
            '070' => 3,
            '080' => 3,
            '090' => 3,
        ) :
        array(
            '020' => 4,
            '070' => 4,
            '080' => 4,
            '090' => 4,
        )
    ;
    $number = preg_replace('/[^\d]++/', '', $input);
    foreach ($groups as $len => $group) {
        $area = substr($number, 0, $len);
        if (isset($group[$area])) {
            $formatted = implode('-', array(
                $area,
                substr($number, $len, $group[$area]),
                substr($number, $len + $group[$area])
            ));
            return strrchr($formatted, '-') !== '-' ? $formatted : $input;
        }
    }
    $pattern = '/\A(00(?:[013-8]|2\d|91[02-9])\d)(\d++)\z/';
    if (preg_match($pattern, $number, $matches)) {
        return $matches[1] . '-' . $matches[2];
    }
    return $input;
}

修正
function.phpをrequire

$number = empty($_GET["p"])? NULL: $_GET["p"];
$number = str_replace('-','', $number);

require "function.php";

$number = format_phone_number($number);

echo $number;

php ディレクトリ下のファイルを取得

globで取得します。

if($_POST["search"]){
	$number = htmlspecialchars($_POST["search"]);
	$number = str_replace('-','', $number);
}
echo $number."<br>";

foreach(glob("number/".$number."*") as $file){
	if(is_file($file)){
		$url = substr($file, 7);
		echo "<a href=\"".$file."\">" .rtrim($url, '.php')."</a><br>";
	}
}

検索フォーム

一致ファイルを表示

テキストを音声(mp3)にする

view

<?php  
include 'voicetext.php';
?>
<style>
.form{
	width:500px;
}
</style>
<body>
<span>テキストを入力してください</span><br>
<form id="form" name="form" action="" method="POST">
<input id="input_text" type="text" class="form" name="input_text" value="">
<button type="submit">変換する</button>
</form>

<span>変換した音声を再生する</span><br>
<audio id="audio" controls>
<source src="voice.mp3">
</audio><br>
<input type="button" value="play" onclick="audio_play()">
<input type="button" value="pause" onclick="audio_pause()">
<script type="text/javascript">
function audio_play() { audio.play();}
function audio_pause() { audio.pause();}
</script>

voicetext.php
hikariの声を使います。
https://cloud.voicetext.jp/webapi/docs/api
curl

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.voicetext.jp/v1/tts");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$authorized = "do not watch";
curl_setopt($ch,CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch,CURLOPT_USERPWD,$authorized);
$post_array = array("text" => $_POST["input_text"], "speaker" => "hikari", "emotion" => "happiness", "pitch" => "80", "emotion_level" => "4");
$postdata = "";
foreach ($post_array as $key => $val){
	$postdata.= urlencode($key) . '=' . urlencode($val). '&';
}
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
$output = curl_exec($ch);
curl_close($ch);
$fp = fopen("voice.mp3","w");
fwrite($fp, $output);
fclose($fp);

browser

mp3

HOYA株式会社:光学機器・ガラスメーカー
東京都新宿区西新宿6-10-1 日土地西新宿ビル 20F
代表:鈴木洋

天気予報RSSをmp3に変換してみます。
テキスト:[ 東京都の天気概況 ] 本州付近は高気圧に覆われています。 【関東甲信地方】 関東甲信地方は、甲信地方は晴れている所もありますが、関東地方はおお むね曇りとなっています。 3日は、高気圧に覆われて晴れますが、湿った空気の影響により、朝晩中 心に曇る所があるでしょう。

笑)これは、ちょっと違う 〇やってる人みたいですね。

emotionとemotion levelをなくします。

ほう

cloud speech api

phpで郵便番号から住所を取得

$zip = "1530042";
$base_url = "http://zipcloud.ibsnet.co.jp/api/search?zipcode=".$zip."";
$json = file_get_contents($base_url);
print_r('<pre>');
var_dump($json);
print_r('</pre>');
$arr = json_decode($json, true);
echo $arr['results'][0]['address1']. "<br>";
echo $arr['results'][0]['address2']. "<br>";
echo $arr['results'][0]['address3'];

string(293) “{
“message”: null,
“results”: [
{
“address1”: “東京都”,
“address2”: “目黒区”,
“address3”: “青葉台”,
“kana1”: “トウキョウト”,
“kana2”: “メグロク”,
“kana3”: “アオバダイ”,
“prefcode”: “13”,
“zipcode”: “1530042”
}
],
“status”: 200
}”
東京都
目黒区
青葉台

postされた条件によるsql文の分岐とconcatがnullの時

「これ、絶対もっと効率的に書ける筈」、と思いながら結局、POSTされた際のsqlのパターンを全部書いてしまった。
終わってる。死にたい。。

concatの値がnullがある場合は、ifnullを使います。
CONCAT(IFNULL(username, ”), IFNULL(message, ”))

<?php
	$dsn = "mysql:dbname=mail;host=localhost";
	$user = "hoge";
	$password = "hogehoge";
	try {
	    $dbh = new PDO($dsn, $user, $password);
	} catch (PDOException $e){
	    print('connection failed:'.$e->getMessage());
	}

	if(!empty($_POST["search"]) and !empty($_POST["gender"]) and !empty($_POST["age"]) and !empty($_POST["job"]) and !empty($_POST["area"])){
		$sql = "select * from users where CONCAT(IFNULL(username, ''), IFNULL(message, '')) like '%".$_POST["search"]."%' and gender = '".$_POST["gender"]."' and age = '".$_POST["age"]."' and job = '".$_POST["job"]."' and area = '".$_POST["area"]."' order by id desc";
	}elseif(!empty($_POST["search"]) and !empty($_POST["age"]) and !empty($_POST["job"]) and !empty($_POST["area"])){
		$sql = "select * from users where CONCAT(IFNULL(username, ''), IFNULL(message, '')) like '%".$_POST["search"]."%' and age = '".$_POST["age"]."' and job = '".$_POST["job"]."' and area = '".$_POST["area"]."' order by id desc";
	}elseif(!empty($_POST["search"]) and !empty($_POST["gender"]) and !empty($_POST["job"]) and !empty($_POST["area"])){
		$sql = "select * from users where CONCAT(IFNULL(username, ''), IFNULL(message, '')) like '%".$_POST["search"]."%' and gender = '".$_POST["gender"]."' and job = '".$_POST["job"]."' and area = '".$_POST["area"]."' order by id desc";
	}elseif(!empty($_POST["search"]) and !empty($_POST["gender"]) and !empty($_POST["age"]) and !empty($_POST["area"])){
			$sql = "select * from users where CONCAT(IFNULL(username, ''), IFNULL(message, '')) like '%".$_POST["search"]."%' and gender = '".$_POST["gender"]."' and area = '".$_POST["area"]."' order by id desc";
	}elseif(!empty($_POST["search"]) and !empty($_POST["gender"]) and !empty($_POST["age"]) and !empty($_POST["job"])){
		$sql = "select * from users where CONCAT(IFNULL(username, ''), IFNULL(message, '')) like '%".$_POST["search"]."%' and gender = '".$_POST["gender"]."' and age = '".$_POST["age"]."' and job = '".$_POST["job"]."'  order by id desc";
	}elseif(!empty($_POST["search"]) and !empty($_POST["job"]) and !empty($_POST["area"])){
			$sql = "select * from users where CONCAT(IFNULL(username, ''), IFNULL(message, '')) like '%".$_POST["search"]."%' and job = '".$_POST["job"]."' and area = '".$_POST["area"]."' order by id desc";
	}elseif(!empty($_POST["search"]) and !empty($_POST["age"]) and !empty($_POST["area"])){
		$sql = "select * from users where CONCAT(IFNULL(username, ''), IFNULL(message, '')) like '%".$_POST["search"]."%' and age = '".$_POST["age"]."' and area = '".$_POST["area"]."' order by id desc";
	}elseif(!empty($_POST["search"]) and !empty($_POST["age"]) and !empty($_POST["job"])){
		$sql = "select * from users where CONCAT(IFNULL(username, ''), IFNULL(message, '')) like '%".$_POST["search"]."%' and age = '".$_POST["age"]."' and job = '".$_POST["job"]."' order by id desc";
	}elseif(!empty($_POST["search"]) and !empty($_POST["gender"]) and !empty($_POST["area"])){
		$sql = "select * from users where CONCAT(IFNULL(username, ''), IFNULL(message, '')) like '%".$_POST["search"]."%' and gender = '".$_POST["gender"]."' and area = '".$_POST["area"]."' order by id desc";
	}elseif(!empty($_POST["search"]) and !empty($_POST["gender"]) and !empty($_POST["job"])){
		$sql = "select * from users where CONCAT(IFNULL(username, ''), IFNULL(message, '')) like '%".$_POST["search"]."%' and gender = '".$_POST["gender"]."' and job = '".$_POST["job"]."' and order by id desc";
	}elseif(!empty($_POST["search"]) and !empty($_POST["gender"]) and !empty($_POST["age"])){
		$sql = "select * from users where CONCAT(IFNULL(username, ''), IFNULL(message, '')) like '%".$_POST["search"]."%' and gender = '".$_POST["gender"]."' and age = '".$_POST["age"]."' order by id desc";
	}elseif(!empty($_POST["search"]) and !empty($_POST["gender"])){
		$sql = "select * from users where CONCAT(IFNULL(username, ''), IFNULL(message, '')) like '%".$_POST["search"]."%' and gender = '".$_POST["gender"]."' order by id desc";
	}elseif(!empty($_POST["search"]) and !empty($_POST["age"])){
		$sql = "select * from users where CONCAT(IFNULL(username, ''), IFNULL(message, '')) like '%".$_POST["search"]."%' and age = '".$_POST["age"]."' order by id desc";
	}elseif(!empty($_POST["search"]) and !empty($_POST["job"])){
		$sql = "select * from users where CONCAT(IFNULL(username, ''), IFNULL(message, '')) like '%".$_POST["search"]."%' and job = '".$_POST["job"]."' order by id desc";
	}elseif(!empty($_POST["search"]) and !empty($_POST["area"])){
		$sql = "select * from users where CONCAT(IFNULL(username, ''), IFNULL(message, '')) like '%".$_POST["search"]."%' and area = '".$_POST["area"]."' order by id desc";
	}elseif(!empty($_POST["search"])){
		$sql = "select * from users where CONCAT(IFNULL(username, ''), IFNULL(message, '')) like '%".$_POST["search"]."%' order by id desc";
	}elseif(!empty($_POST["gender"]) and !empty($_POST["age"]) and !empty($_POST["job"]) and !empty($_POST["area"])){
		$sql = "select * from users where gender = '".$_POST["gender"]."' and age = '".$_POST["age"]."' and job = '".$_POST["job"]."' and area = '".$_POST["area"]."' order by id desc";
	}elseif(!empty($_POST["gender"]) and !empty($_POST["job"]) and !empty($_POST["area"])){
		$sql = "select * from users where gender = '".$_POST["gender"]."' and job = '".$_POST["job"]."' and area = '".$_POST["area"]."' order by id desc";
	}elseif(!empty($_POST["gender"]) and !empty($_POST["age"]) and !empty($_POST["area"])){
		$sql = "select * from users where gender = '".$_POST["gender"]."' and age = '".$_POST["age"]."' and area = '".$_POST["area"]."' order by id desc";
	}elseif(!empty($_POST["gender"]) and !empty($_POST["age"]) and !empty($_POST["job"])){
		$sql = "select * from users where gender = '".$_POST["gender"]."' and age = '".$_POST["age"]."' and job = '".$_POST["job"]."' order by id desc";
	}elseif(!empty($_POST["gender"]) and !empty($_POST["area"])){
		$sql = "select * from users where gender = '".$_POST["gender"]."' and area = '".$_POST["area"]."' order by id desc";
	}elseif(!empty($_POST["gender"]) and !empty($_POST["job"])){
		$sql = "select * from users where gender = '".$_POST["gender"]."' and job = '".$_POST["job"]."' order by id desc";
	}elseif(!empty($_POST["gender"]) and !empty($_POST["age"])){
		$sql = "select * from users where gender = '".$_POST["gender"]."' and age = '".$_POST["age"]."' order by id desc";
	}elseif(!empty($_POST["gender"])){
		$sql = "select * from users where gender = '".$_POST["gender"]."' order by id desc";
	}elseif(!empty($_POST["age"]) and !empty($_POST["job"]) and !empty($_POST["area"])){
		$sql = "select * from users where age = '".$_POST["age"]."' and job = '".$_POST["job"]."' and area = '".$_POST["area"]."' order by id desc";
	}elseif(!empty($_POST["age"]) and !empty($_POST["area"])){
		$sql = "select * from users where age = '".$_POST["age"]."' and area = '".$_POST["area"]."' order by id desc";
	}elseif(!empty($_POST["age"]) and !empty($_POST["job"])){
		$sql = "select * from users where age = '".$_POST["age"]."' and job = '".$_POST["job"]."' order by id desc";
	}elseif(!empty($_POST["age"])){
		$sql = "select * from users where age = '".$_POST["age"]."' order by id desc";
	}elseif(!empty($_POST["job"]) and !empty($_POST["area"])){
		$sql = "select * from users where job = '".$_POST["job"]."' and are = '".$_POST["are"]."' order by id desc";
	}elseif(!empty($_POST["job"])){
		$sql = "select * from users where job = '".$_POST["job"]."' order by id desc";
	}elseif(!empty($_POST["area"])){
		$sql = "select * from users where area = '".$_POST["area"]."' order by id desc";
	}else{
		$sql = "select * from users order by id desc";
	}
	$stmt = $dbh->query($sql);
	$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
	// var_dump($result);
?>

<style>
#img{
	position: relative;
}
#img img{
	vertical-align:top;
}
#icon{
	vertical-align:top;
	float:left;
}
#profile{
	display: inline;
}
</style>
<form action="" method="post"><input type="search" name="search" placeholder="ユーザー名もしくは一言メッセージから探す"> <input type="submit" value="検索"><br>
性別:<input type="radio" name="gender" value="男性">男性
<input type="radio" name="gender" value="女性">女性 
年齢:
	<select name="age">
	<option value="">選択してください</option>
	<option value="20歳未満">20歳未満</option>
	<option value="20-24歳">20-24歳</option>
	<option value="25-29歳">25-29歳</option>
	<option value="30-34歳">30-34歳</option>
	<option value="35-39歳">35-39歳</option>
	<option value="40-44歳">40-44歳</option>
	<option value="45-49歳">45-49歳</option>
	<option value="50-54歳">50-54歳</option>
	<option value="55-59歳">55-59歳</option>
	<option value="60-64歳">60-64歳</option>
	<option value="65-69歳">65-69歳</option>
	<option value="70-74歳">70-74歳</option>
	<option value="75-79歳">75-79歳</option>
	<option value="80歳以上">80歳以上</option>
	</select>
	職業:
	<select name="job">
	<option value="">選択してください</option>
	<option value="公務員">公務員</option>
	<option value="経営者・役員">経営者・役員</option>
	<option value="会社員">会社員</option>
	<option value="自営業">自営業</option>
	<option value="自由業">自由業</option>
	<option value="専業主婦">専業主婦</option>
	<option value="パート・アルバイト">パート・アルバイト</option>
	<option value="学生">学生</option>
	<option value="その他">その他</option>
	</select>
	登録地域:
	<select name="area">
	<option value="">選択してください</option>
	<option value="北海道">北海道</option>
	<option value="青森県">青森県</option>
	<option value="岩手県">岩手県</option>
	<option value="宮城県">宮城県</option>
	<option value="秋田県">秋田県</option>
	<option value="山形県">山形県</option>
	<option value="福島県">福島県</option>
	<option value="茨城県">茨城県</option>
	<option value="栃木県">栃木県</option>
	<option value="群馬県">群馬県</option>
	<option value="埼玉県">埼玉県</option>
	<option value="千葉県">千葉県</option>
	<option value="東京都">東京都</option>
	<option value="神奈川県">神奈川県</option>
	<option value="新潟県">新潟県</option>
	<option value="富山県">富山県</option>
	<option value="石川県">石川県</option>
	<option value="福井県">福井県</option>
	<option value="山梨県">山梨県</option>
	<option value="長野県">長野県</option>
	<option value="岐阜県">岐阜県</option>
	<option value="静岡県">静岡県</option>
	<option value="愛知県">愛知県</option>
	<option value="三重県">三重県</option>
	<option value="滋賀県">滋賀県</option>
	<option value="京都府">京都府</option>
	<option value="大阪府">大阪府</option>
	<option value="兵庫県">兵庫県</option>
	<option value="奈良県">奈良県</option>
	<option value="和歌山県">和歌山県</option>
	<option value="鳥取県">鳥取県</option>
	<option value="島根県">島根県</option>
	<option value="岡山県">岡山県</option>
	<option value="広島県">広島県</option>
	<option value="山口県">山口県</option>
	<option value="徳島県">徳島県</option>
	<option value="香川県">香川県</option>
	<option value="愛媛県">愛媛県</option>
	<option value="高知県">高知県</option>
	<option value="福岡県">福岡県</option>
	<option value="佐賀県">佐賀県</option>
	<option value="長崎県">長崎県</option>
	<option value="熊本県">熊本県</option>
	<option value="大分県">大分県</option>
	<option value="宮崎県">宮崎県</option>
	<option value="鹿児島県">鹿児島県</option>
	<option value="沖縄県">沖縄県</option>
	<option value="海外">海外</option>
</select><br>
</form>
<?php

	$i = 0;
	foreach($result as $value){
		if($i < 20){
			if(!empty($value&#91;"icon"&#93;)){
				$picon = $value&#91;"icon"&#93;;
				echo "<img src=\"".$picon."\" id=\"icon\" width=\"48px\" height=\"48px\">";
			} elseif($value['gender'] == "男性") {
				echo "<img src=\"asset/img/male.png\" id=\"icon\">";
			} else{
				echo "<img src=\"asset/img/female.png\" id=\"icon\">";
			}
			echo "<div id=\"profile\"><a href=\"?compose=new&to=".$value&#91;'username'&#93;."\">".$value['username'] ."</a>:".$value['age']." <span id=\"fs-s\">".$value['gender'] ."</span><br>";
			if(!empty($value["message"])){
				echo $value['job']."(".$value['area'].") <span id=\"fs-s\">一言メッセージ:「".$value["message"]."」</span></div><br><br>";
			} else {
				echo $value['job']."(".$value['area'].")</div><br><br>";
			}
			
			$i++;
		}
	}

挙動としては、思い通りに動いてくれるんだが、自分にがっかりするな。。

つなげると、
おおおお、基本機能はほぼ出来たか!

次は、スタイリングかな