dongtie0929 2012-11-05 19:52
浏览 28
已采纳

麻烦用PHP回发解决方案

This may be an easy fix, but I can't get my head around it .

Basically I've remade my blog using a database and php rather than wordpress. I want my site to show the most recent post first, then i'm using PhP postback to alter it

So far it works, but i can't figure out a way for it to automatically go to the most recent one but then change after the postback.

 <?php 
$inId = $data[0];

//if (!empty($inId))
//{ 

//}
//else 
//{
//$inId = $_POST['ID'];
//} 
    include 'Includes.php';
    $blogPosts = GetBlogPosts($inId);  
    foreach ($blogPosts as $post)  
{  
    echo "<div class='post'>";
    echo "<h3>" . $post->title . "</h3>";
    echo "<p2>" . $post->post . "</p2>";  
    echo "<span class='footer'>Posted By: " . $post->Author . " Posted On: " . $post-       >datePosted . "</span>";  
}  
echo '<form name="myForm" action="Index.php" onsubmit="return validateFormStrings()"    method="post">';
echo'<select name ="ID">'; 

$query4 = "SELECT * FROM Blogs ORDER BY ID ";
$result = mysql_query($query4);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {    
          echo '<option value="'.$row['ID'].'">'.$row['Title'].'</option>';
          echo '<br>';               
    } 
    echo'</select>'; 
echo '<input type="submit" value="Retrieve Posts">';
echo '<a href="Index.Php" ></a>';

echo '</form>';
?>

As you see i tried to fiddle with !empty and things but that's not really what im trying to do. If i'm unclear let me know.

I almost need something like " if ( button !pressed) then its data[0] else its the postback

Thanks in advance

  • 写回答

1条回答 默认 最新

  • dsdt66064367 2012-11-05 20:14
    关注

    I found out how to do it using the isset() function.

    if (isset($_POST['submit1'])) 
    {
    $inId = $_POST['ID'];
    }
     else
    { 
    $inId = $data[0];
    }
    

    This checks if the submit button has doe the postback or not. Works a treat.

    Gonna have a go at trying it with Ajax so I don't need the button at all ^^

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统