【发布时间】:2015-11-03 20:19:25
【问题描述】:
这是我第一次在这里提问。 (对不起,如果我的英语不是那么好) 我不擅长 php 和 html。直到上个月,我从未编写过 html 或 php 代码。 我目前是一家公司的实习生,他们希望我建立一个内部网。现在一切正常,我已经使用 wordpress 建立了一个很好的网站,但现在他们问我一些对我来说太复杂的事情,没有人可以帮助我,所以我问你们。
在我的页面上,我有一个表单,可以在外部数据库中提交查找,然后将它们显示在同一页面上。一切正常。我想要的是当用户输入输入值时,我想要生成一个新页面。目前,当用户输入值时,url 保持不变(例如:http://localhost/vendors/),但我想要的是当用户输入 ABCD 时,我希望 url 现在是 http://localhost/vendors/abcd,这样我们就可以与正确的共享链接页面上显示的数据。
我试图在互联网上找到答案,但失败了。我读过我必须使用模板来使用模板生成具有输入值的新页面,但我不知道该怎么做。我也想让表单留在页面上,这样我们可以继续在数据库中搜索并显示其他数据
这是我现在所拥有的(我已经删除了所有无用的问题):
<!--Connection to mssql database-->
<?php
try {
$hostname = "hostname";
$port = 1433;
$dbname = "databasename";
$username = "username";
$pw = "password";
$dbh = new PDO ("dblib:host=$hostname:$port;dbname=$dbname","$username","$pw");
} catch (PDOException $e) {
echo "Failed to get DB handle: " . $e->getMessage() . "\n";
exit;
}
/**
* Template Name: Vendors
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages
* and that other 'pages' on your WordPress site will use a
* different template.
*
* @package vantage
* @since vantage 1.0
* @license GPL 2.0
*/
get_header(); ?>
<form action="" method="post">
<table id= "formvendor">
<tr><td><b>Vendor ID: </b></td><td><input type="text" name="vendorid"></td></tr>
<tr><td><b>Vendor name: </b></td><td><input type="text" name="vendname"></b></td></tr>
<input type="submit"
style="position: absolute; left: -9999px; width: 1px; height: 1px;"
tabindex="-1" />
</form>
<?
$vendorid = $_POST["vendorid"];
$vendname = $_POST['vendname'];
$vendorid=ltrim($vendorid);
$vendorid=rtrim($vendorid);
$vendname=ltrim($vendname);
$vendname=rtrim($vendname);
$query="SELECT ... FROM uni.dbo.pm00200 where ";
if(strlen($vendorid)>0){
$query .=" vendorid='$vendorid' or";
if(strlen($vendname)>0){ }
else{
$query=substr($query,0,(strLen($query)-3));
}
}
if(strlen($vendname)>0){
$kt2=split(" ",$vendname);//Breaking the string to array of words
// Now let us generate the sql
while(list($key,$val)=each($kt2)){
if($val<>" " and strlen($val) > 0){$query .= " vendname like '%$val%' or ";}
}// end of while
$query=substr($query,0,(strLen($query)-3));
// this will remove the last or from the string.
// end of if else based on type value
}
foreach ($dbh->query($query) as $t) {
echo "<table id='tablevendors' style='width:100%' cellpadding='-5px'>";
echo '<col width="40%"><col width="60%"';
echo "<tr>";
echo "<td><b>Vendor ID :</b></td><td> $t[vendorid]</td>";
echo "</tr><tr>";
echo "<td><b>Vendor name:</b></td><td> $t[vendname]</td>";
echo "</tr><tr>";
echo "<td><b>Vendor class:</b></td><td> $t[vndclsid]</td>";
echo "</tr><tr>";
echo "<td><b>Address 1:</b></td><td> $t[address1]</td>";
echo "</tr><tr>";
echo "<td><b>Address 2:</b></td><td> $t[address2]</td>";
echo "</tr><tr>";
echo "<td><b>Address 3:</b></td><td> $t[address3]</td>";
echo "</tr><tr>";
echo "<td><b>City:</b></td><td> $t[city]</td>";
echo "</tr><tr>";
echo "<td><b>State:</b></td><td> $t[state]</td>";
echo "</tr><tr>";
echo "<td><b>Zipcode:</b></td><td> $t[zipcode]</td>";
echo "</tr><tr>";
echo "<td><b>Payment:</b></td><td> $t[pymtrmid]</td>";
echo "</tr><tr>";
echo "<td><b>Buyer:</b></td><td> $t[buyer]</td>";
echo "</tr><tr>";
echo "<td><b>Minimum order:</b></td><td> $t[minorder]</td>";
echo "</tr><tr>";
echo "<td><b>Prepaid info:</b></td><td> $t[prepaid]</td>";
echo "</tr>";
echo "</table>";
}
unset($dbh); unset($stmt);
?>
//rest of template
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="entry-main">
<?php do_action('vantage_entry_main_top') ?>
<div class="entry-content">
<?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'vantage' ) ); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'vantage' ), 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
<?php do_action('vantage_entry_main_bottom') ?>
</div>
</article><!-- #post-<?php the_ID(); ?> -->
<?php if ( comments_open() || '0' != get_comments_number() ) : ?>
<?php comments_template( '', true ); ?>
<?php endif; ?>
<?php endwhile; // end of the loop. ?>
</div><!-- #primary .content-area -->
</div><!-- #content .site-content -->
<?php get_footer(); ?>
【问题讨论】:
-
查看此堆栈溢出帖子:stackoverflow.com/questions/15236733/…