Php 检查是否设置了一个或多个$\u GET

Php 检查是否设置了一个或多个$\u GET,php,mysql,Php,Mysql,我再试一次:/ 我正在建立一个博客页面 我希望它能通过,海报或分类,月份或年份,或组合来显示帖子。 但只有在url中有$\u GET的情况下。如果没有,他们只需访问blogs.php,我希望它只显示最近的12篇文章。不,我有自己的分类工作和自己的海报工作 这里是我的代码,在编辑了一点之后 <?php $category = mysql_real_escape_string( $_GET['Category']); $Poster = mysql

我再试一次:/

我正在建立一个博客页面

我希望它能通过,海报或分类,月份或年份,或组合来显示帖子。 但只有在url中有$\u GET的情况下。如果没有,他们只需访问blogs.php,我希望它只显示最近的12篇文章。不,我有自己的分类工作和自己的海报工作

这里是我的代码,在编辑了一点之后

                    <?php 


$category = mysql_real_escape_string( $_GET['Category']);
$Poster = mysql_real_escape_string($_GET['Poster']);
$Month = mysql_real_escape_string($_GET['Month']);
$Year = mysql_real_escape_string($_GET['Year']);


$sql = "SELECT * FROM blog, blog_poster, blog_category WHERE blog.category = '$category' 
AND  blog_poster.pid = blog.posterid 
AND blog_category.ID = blog.category 

OR posterid = '$Poster' 
AND  blog_poster.pid = blog.posterid 
AND blog_category.ID = blog.category  
ORDER BY timestamp DESC LIMIT 5";

$result = mysql_query($sql) or print ("Can't select entries from table.<br />" . $sql . "<br />" . mysql_error());
while($row = mysql_fetch_array($result)) {
    $date = date("D M d Y", $row['timestamp']);

$title = stripslashes($row['title']);
$entry = stripslashes($row['entry']);
$id = $row['id'];
$entry =substr($entry, 0, 250);


?>

            <div class="ribbon">
                    <div class="wrapAround"></div>
                    <div class="tab">
                        <span class="blogDate"><?php echo $date; ?></span>
                        <span class="blogPostInfo">Posted by <a href="#"><?php echo $row['name']; ?></a> <!--|  <a href="#">0 Comments</a --></span>
                    </div>
                </div>
                <div class="blogPostSummary">
                    <h1><span><b><?php echo $title; ?></b></span></h1>
                    <div class="blogPostImage">
                        <a href='cs_blog/content.php?id=<?=$id?>'class="img">
                        <img src="../images/content/blogs/cs_blog/date/headers/blog-post-01.JPG" width="556" height="133" alt="blog post image" /></a>
                  </div>
                    <p>
                        <?php echo $entry."..&nbsp;<br><a href='content.php?id=$id'>Read more...</a>"; ?>
                    </p>
                    <p></p>
                </div>



                <!-- End of Content -->
                <?php }; ?>
试试这个

$category='DefaultCategory';
$poster='DefaultPoster';
$month='defaultMonth';
$month='defaultYear';

if(isset($_GET['Category']))
{
   $category = mysql_real_escape_string( $_GET['Category']);
}
if(isset($_GET['Poster']))
{
   $Poster = mysql_real_escape_string($_GET['Poster']);
}
if(isset($_GET['Month']))
{
   $Month = mysql_real_escape_string($_GET['Month']);
}
if(isset($_GET['Year']))
{
   $Year = mysql_real_escape_string($_GET['Year']);
}

$query="insert into sampleTable(category,poster,month,year)
 values ($Category,$Poster,$Month,$Year)"; 
或者,如果在表格设计中为所有字段设置了默认值
然后,您只能插入提供的字段

isset
有什么问题?isset似乎是正确的方法,很难理解您想要实现的目标。到目前为止你试过什么?向我们展示您的代码-我们可能能够指出错误。
函数get_post($key,$default){if(isset($u post[$key]){return$_post[$key];}return$default;}$category=mysql_real_escape_string(get_post('category','default category));
工作了谢谢mate,只需要在if(!empty)上有一个{在末尾有一个else谢谢mate
$conditions = array();
if( isset($_GET['Category']) ) $conditions[] = "category='". mysql_real_escape_string( $_GET['Category']) . "'";
if( isset($_GET['Poster']) )   $conditions[] = "poster='". mysql_real_escape_string( $_GET['Poster']) . "'";

if(!empty($conditions))
    $conditions = 'where ' . implode(' AND ', $conditions);
echo 'select * from table ' . $conditions;