題名の通り、ラジオボタンのフォームのデータを受け取る方法が知りたいです。ラジオボタンの送信のhtmlの書き方はわかります。しかし、ラジオボタンの受信のphpの書き方がわかりません。つまりパラメータの渡し方がわかりません。
わからない部分は、if(issetの後に何を書けばいいかわかりません。
今、美味しいうどんが食べたいみたいに北海道のラジオボタンをクリックしたら北海道のうどんやが表示されるようにしたいのですが詳しいやり方がわかりません。下記にhtmlとphpコードを書きましたが、間違いはありますか?また、htmlとphpのコードの二つはradioForm.phpに書くのですか?
html
1 2<!doctype html> 3<html> 4<head> 5<meta charset="utf-8"> 6<title>ラジオボタンのデータの送信</title> 7</head> 8<body> 9<form name="form1" method="post" action="radioForm.php"> 10ラジオボタンの送信: 11<input type="radio" name="city" value="04100">仙台市 12<input type="radio" name="city" value="04201">石巻市 13・ 14・ 15・ 16<input type="submit" name="submit" value="送信">
PHP
1<?php 2if ( isset( $_GET[ 'my_filter' ] ) && preg_match( '![0-9]{5}!', $_GET[ 'my_filter' ] ) ) { 3 $area = $_GET[ 'my_filter' ]; 4} else { 5 $area = '04100'; 6} 7if ( isset( $_GET[ 'my_page' ] ) && is_numeric( $_GET[ 'my_page' ] ) ) { 8 9 $my_page = absint( $_GET[ 'my_page' ] ); 10} else { 11 $my_page = 1; 12} 13 14$id = 'id'; 15$item_per_page = 50; 16$start = ( $my_page - 1) * $item_per_page + 1; 17$url = 'http://search.olp.yahooapis.jp/OpenLocalPlatform/V1/localSearch?appid=' . $id . '&ac=' . $area . '&results=' . $item_per_page . '&start=' . $start . '&detail=full'; 18$xml = simplexml_load_file( $url ); 19$total_count = $xml->ResultInfo->Total; 20 21echo '<table class="left">'; 22echo '<caption>' . $start . '件目から' . $item_per_page . '件 表示中 / 総件数 ' . $total_count . '</caption>'; 23echo '<style scoped>.paging, table{width:80%;margin:auto;}td{border-bottom:1px solid #ccc;}td{color:#2980b9;}form{text-align:center;padding:2em;} 24 .page-link{padding:1em;margin:.3em;display:inline-block;width:3em;border:1px solid #ccc;word-wrap:normal;}h2{text-align:center;margin:2em 0;}</style>'; 25 26$html = '<tr><td>%1$s</td><td>%2$s</td><td>%3$s</td><td>%4$s</td><td>%5$s</td><td>%6$s</td><td>%7$s</td></tr>'; 27$i = 1; 28 29 function paging($limit, $page, $disp=5){ 30 global $area; 31 //$dispはページ番号の表示数 32 $next = $page+1; 33 $prev = $page-1; 34 35 //ページ番号リンク用 36 $start = ($page-floor($disp/2) > 0) ? ($page-floor($disp/2)) : 1;//始点 37 $end = ($start > 1) ? ($page+floor($disp/2)) : $disp;//終点 38 $start = ($limit < $end)? $start-($end-$limit):$start;//始点再計算 39 40 if($page != 1 ) { 41 print '<a href="?my_page='.$prev.'&my_filter='.$area.'">« 前へ</a>'; 42 } 43 44 //最初のページへのリンク 45 if($start >= floor($disp/2)){ 46 print '<a href="?my_page=1&my_filter='.$area.'">1</a>'; 47 if($start > floor($disp/2)) print "..."; //ドットの表示 48 } 49 50 51 for($i=$start; $i <= $end ; $i++){//ページリンク表示ループ 52 53 $class = ($page == $i) ? ' class="current"':"";//現在地を表すCSSクラス 54 55 if($i <= $limit && $i > 0 )//1以上最大ページ数以下の場合 56 print '<a href="?my_page='.$i.'&my_filter='.$area.'"'.$class.'>'.$i.'</a>';//ページ番号リンク表示 57 58 } 59 60 //最後のページへのリンク 61 if($limit > $end){ 62 if($limit-1 > $end ) print "..."; //ドットの表示 63 print '<a href="?my_page='.$limit.'&my_filter='.$area.'">'.$limit.'</a>'; 64 } 65 66 if($page < $limit){ 67 print '<a href="?my_page='.$next.'&my_filter='.$area.'">次へ »</a>'; 68 } 69 70 /*確認用 71 print "<p>current:".$page."<br>"; 72 print "next:".$next."<br>"; 73 print "prev:".$prev."<br>"; 74 print "limit:".$limit."<br>"; 75 print "start:".$start."<br>"; 76 print "end:".$end."</p>";*/ 77 78} 79 80$limit = 10;//最大ページ数 81$page = empty($_GET["my_page"])? 1:$_GET["my_page"];//ページ番号 82 83paging($limit, $page); 84 85foreach ( $xml->Feature as $key => $item ) { 86 87 printf( $html, $item->Name, $item->Property->Yomi, $item->Property->Tel1, $item->Property->Address, $item->Property->Station->Railway, $item->Property->Station->Name . '駅', $item->Property->Detail->OfficialPcUrl1 ); 88 89 $i++; 90} 91echo '</table>'; 92?> 93
PHP
1 <form action="hoge.php" form method="REQUEST"> 2 3<input type="radio" name="city" value="04100">仙台市 4<input type="radio" name="city" value="04201">石巻市 5・ 6・ 7・ 8<input type="submit" name="submit" value="送信"> 9 </form> 10 </body> 11 <?php 12 if ( isset($_REQUEST [ 'my_filter' ] ) ) {$area =$_REQUEST [ 'my_filter' ];$my_page=1; 13 } else { if( preg_match( '![0-9]{5}!',$_REQUEST[ 'my_filter' ] ){ 14$area =$_REQUEST['my_filter']; 15} else { 16$area = '04110'; 17} if ( isset( $_REQUEST[ 'my_page' ] ) && is_numeric($_REQUEST[ 'my_page' ] ) ) { 18 19 $my_page = absint($_REQUEST[ 'my_page' ] ); 20 } else { 21 $my_page = 1; 22 } 23 } 24 $id= '私のid'; 25 $item_per_page = 100; 26 $ct = '01'; 27 $start = ( $my_page - 1) * $item_per_page + 1; 28 $url = 'http://search.olp.yahooapis.jp/OpenLocalPlatform/V1/localSearch?appid=' . $id . '&ac=' . $area .'&gc='. $ct.'&results=' . $item_per_page . '&start=' . $start . '&detail=full'; 29 $xml = simplexml_load_file( $url ); 30 $total_count = $xml->ResultInfo->Total; 31 32 echo '<table class="left">'; 33 echo '<caption>' . $start . '件目から' . $item_per_page . '件 表示中 / 総件数 ' . $total_count . '</caption>'; 34 35 echo '<style scoped>.paging, table{width:80%;margin:auto;}td{border-bottom:1px solid #ccc;}td{color:#2980b9;}form{text-align:center;padding:2em;} 36 .page-link{padding:1em;margin:.3em;display:inline-block;width:3em;border:1px solid #ccc;word-wrap:normal;}h2{text-align:center;margin:2em 0;}</style>'; 37 38$html = '<tr><td>%1$s</td><td>%2$s</td><td>%3$s</td><td>%4$s</td><td>%5$s</td><td>%6$s</td><td>%7$s</td></tr>'; 39$i = 1; function paging($limit, $page, $disp=5){ 40 global $area; 41 //$dispはページ番号の表示数 42 $next = $page+1; 43 $prev = $page-1; 44 45 //ページ番号リンク用 46 $start = ($page-floor($disp/2) > 0) ? ($page-floor($disp/2)) : 1;//始点 47 $end = ($start > 1) ? ($page+floor($disp/2)) : $disp;//終点 48 $start = ($limit < $end)? $start-($end-$limit):$start;//始点再計算 49 50 if($page != 1 ) { 51 print '<a href="?my_page='.$prev.'&name='.$area.'">« 前へ</a>'; 52 } 53 54 //最初のページへのリンク 55 if($start >= floor($disp/2)){ 56 print '<a href="?my_page=1&name='.$area.'">1</a>'; 57 if($start > floor($disp/2)) print "..."; //ドットの表示 58 } 59 60 61 for($i=$start; $i <= $end ; $i++){//ページリンク表示ループ 62 63 $class = ($page == $i) ? ' class="current"':"";//現在地を表すCSSクラス 64 65 if($i <= $limit && $i > 0 )//1以上最大ページ数以下の場合 66 print '<a href="?my_page='.$i.'&name='.$area.'"'.$class.'>'.$i.'</a>';//ページ番号リンク表示 67 68 } 69 70 //最後のページへのリンク 71 if($limit > $end){ 72 if($limit-1 > $end ) print "..."; //ドットの表示 73 print '<a href="?my_page='.$limit.'&name='.$area.'">'.$limit.'</a>'; 74 } 75 76 if($page < $limit){ 77 print '<a href="?my_page='.$next.'&name='.$area.'">次へ »</a>'; 78 } 79 80 /*確認用 81 print "<p>current:".$page."<br>"; 82 print "next:".$next."<br>"; 83 print "prev:".$prev."<br>"; 84 print "limit:".$limit."<br>"; 85 print "start:".$start."<br>"; 86 print "end:".$end."</p>";*/ 87 88} 89 90$limit = 10;//最大ページ数 91$page = empty($_REQUEST ["my_page"])? 1:$_REQUEST["my_page"];//ページ番号 92 93paging($limit, $page); 94 95 96foreach ( $xml->Feature as $key => $item ) { 97 98 printf( $html, $item->Name, $item->Property->Yomi, $item->Property->Tel1, $item->Property->Address, $item->Property->Station->Railway, $item->Property->Station->Name . '駅', $item->Property->Detail->OfficialPcUrl1 ); 99 100 101 $i++; 102 } 103echo '</table>'; 104?>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。