简体   繁体   中英

PHP $_POST from select box returns only the first character

i want to post values from a select box, run them through PHP and assign them to a Smarty object.

My html markup is the following:

<form action="http://www.domain.com/index.php?page=presse" method="post">
<p><label for="startDate" class="search-label">Jahr:</label>
<select name="datepicker">
   <option value="2014">2014</option>
   <option value="2013">2013</option>
   <option value="2012">2012</option>
</select></p>
<select name="issue">
   <option value="Abisolierzange">Abisolierzange</option>
   <option value="International">International</option>
   <option value="Kabelmesser">Kabelmesser</option>
</select></p>
<input type="submit" name="submit_presse_filter" class="blockHeadline" value="Suchen">
</form>

I receive the form data like this:

if(isset($_POST['submit_presse_filter'])) {
    $date  = $_REQUEST['datepicker'];   
    $issue = $_REQUEST['issue'];    
    $search_results["issue"]["datum"] = $date;
    $search_results["issue"]["ueberschrift"] = $issue;
}

And finaly in my template i put out the data like this:

{search_result.date}
{search_result.ueberschrift}

But i will only get the first letters of the values, like

2

for the date and

 A

for the first value of the issue.

Why is that?

EDIT:

The mistake was within the smarty foreach clause.

In php i build in a counter like this:

    $query = "SELECT * FROM table";

$result = mysql_query($query) OR die(mysql_error());
$number = mysql_num_rows($result);

$search_results = array();

if($number > 0) {
$i=0;
    while($row = mysql_fetch_array($result)) { 
        $search_results["issue"][$i]["datum"] = $row['datum'];
        $search_results["issue"][$i]["ueberschrift"] = $row['ueberschrift'];
        $search_results["issue"][$i]["inhalt"] = $row['inhalt1'];
        $search_results["issue"][$i++]["ort"] = $row['ort'];

    }
}
$smarty->assign('search_results', $search_results);

Now i can do this in my template:

{if $search_results.issue}
   <p><strong>Presse</strong></p>
   <ul>
    {foreach item=search_result from=$search_results.issue}
    <li>
        <h2>{$search_result.datum}</h2>
    </li>
    {/foreach}  
    </ul>
 {/if}

You are defining a two-dimensional array here: $search_results["issue"]["datum"] = $date; Maybe you want that to be $search_results["datum"] = $date; instead. Then {search_result.date} should work. Otherwise maybe {search_result.issue.date} helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM