如果条件内部而环路不工作,而它是单独工作

时间:2013-05-01 22:07:39

标签: php html mysql css

这是一个独立工作的脚本,但是当我一起使用它时,它不能正常工作。这里的问题是if条件内部while循环应该从数据库获取值并执行语句取决于$ watch的值的条件,这将在$ rajat中进一步使用。但是while循环只运行了一次。如果我运行while循环和if语句分开,那么它们正在工作。这可能是什么问题。提前感谢您的帮助......

 <?php
include_once("php_includes/connect_to_mysqli.php");
// Query the body section for the proper page
$sql = "SELECT * FROM projects  WHERE status='1' ORDER BY id DESC";
$query = mysqli_query($db_conx, $sql) or die (mysqli_error());
$rajat='';
$watch='';
$y=200; 
while($row = mysqli_fetch_array($query)){ 
    $p_title = $row["project_title"];
    $p_details = $row["description"];
    $p_attachment = $row["attachment"];
    $p_skills = $row["skills_req"];
    $p_min = $row["budget_min"];
    $p_max = $row["budget_max"];
    $p_abid = $row["average_bid"];
    $p_bcount = $row["bids"];
    $p_type = $row["type"];
    $p_owner = $row["posted_by"];
    $p_cat = $row["category"];
    $pid = $row["id"];
    $p_posted = $row["posted_date"];
    $p_expire = $row["expire"];


//Find project owner with id=$p_owner
$sql = "SELECT * FROM user WHERE id='$p_owner'"; 
$quebry = mysqli_query($db_conx, $sql) or die (mysqli_error());

while($row = mysqli_fetch_array($quebry)){ 
    $p_own = $row["username"];
    $p_own_con = $row["country"];
    $p_own_avt = $row["avatar"];
}
//Check for watchlist
$sql = "SELECT id FROM watchlist WHERE user_id='$y' AND project_id='$pid'";
    $query = mysqli_query($db_conx, $sql); 
    $watch_check = mysqli_num_rows($query);
    if ($watch_check < 1) {
        $watch= '<div class="watchhold" id="watchhold'.$pid.'"><div class="watchoff" id="watchoff'.$pid.'"  onclick="addwatch('.$pid .','.$y.',\''.$p_title.'\',\'watchhold'.$pid.'\')"></div><span>Add to Watchlist</span></div>';

    }else{

          $watch='<div class="watchhold" id="watchhold'.$pid.'"><div class="watchon" id="watchon'.$pid.'"></div><span>On Watchlist</span></div>';

        }
//End watchlist

    $rajat .= '<div class="jobBoard">
    <div class="tags"><img src="img/add_banners/feat.png"><img src="img/add_banners/seal.png"><img src="img/add_banners/urgent.png"><img src="img/add_banners/fulltime.png"><img src="img/add_banners/private.png"><img src="img/add_banners/nda.png"></div>
    <div class="proj_info"><div><a href="project_detailss.php?pid='.$pid.'" class="title">'.$p_title.'</a>'.$watch.'</div><div class="project_stats"><span class="bold">Fixed Price:  $'.$p_min.'-$'.$p_max.'</span>
        &nbsp;&nbsp;|&nbsp;&nbsp;Posted: '.$p_posted.'&nbsp;&nbsp;|&nbsp;&nbsp;Ends: '.$p_expire.'&nbsp;&nbsp;|&nbsp;&nbsp;<a class="numproposals-link" id="bubble_40683796" href="project_detailss.php?pid='.$pid.'" onmouseover="projectJs.showAvgBubble(\'40683796\',\'Low\',\'n/a\',\'High\',\'n/a\',\'Avg\',\'n/a\');" onmouseout="projectJs.hideAvgBubble();"><span class="bold">'.$p_bcount.'</span> Proposals</a></div>
    <div class="desc collapsed descFull" id="40683796Desc">
        '.$p_details.'</div><div class="prof">
        <span class="midgrey">Category:</span> <span title="Web Programming">Web Programming</span>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="midgrey">Skills:</span>'.$p_skills.'</span></div>
    <div class="prof"><span onmouseover="projectJs.showRatingTooltip(40683796);" onmouseout="projectJs.hideRatingTooltip(40683796);">
        <div class="eol-buyer-rating-small eol-buyer-rating-small-0" id="buyerRating40683796">
</div>| <a style="display:inline-block;" id="buyerRating40683796profurl" class="clientname" href="testing.php?u='.$p_own.'">'.$p_own.'</a>
</span>|&nbsp;&nbsp;<img data-src="/media/images/4.0/flags/in.gif" style="visibility: visible; zoom: 1; opacity: 1;" src="/media/images/4.0/flags/in.gif">&nbsp;&nbsp;'.$p_own_con.'</div></div>
</div> ';


}

 mysqli_free_result($query);
?>

1 个答案:

答案 0 :(得分:0)

你有一个额外的大括号......

//Find project owner with id=$p_owner
$sql = "SELECT * FROM user WHERE id='$p_owner'"; 
$quebry = mysqli_query($db_conx, $sql) or die (mysqli_error());

while($row = mysqli_fetch_array($quebry)){ 
    $p_own = $row["username"];
    $p_own_con = $row["country"];
    $p_own_avt = $row["avatar"];

//} <-- this shouldn't be here

//Check for watchlist
$sql = "SELECT id FROM watchlist WHERE user_id='$y' AND project_id='$pid'";
    $query = mysqli_query($db_conx, $sql); 
    $watch_check = mysqli_num_rows($query);
    if ($watch_check < 1) {
        $watch= '<div class="watchhold" id="watchhold'.$pid.'"><div class="watchoff" id="watchoff'.$pid.'"  onclick="addwatch('.$pid .','.$y.',\''.$p_title.'\',\'watchhold'.$pid.'\')"></div><span>Add to Watchlist</span></div>';

    }else{

          $watch='<div class="watchhold" id="watchhold'.$pid.'"><div class="watchon" id="watchon'.$pid.'"></div><span>On Watchlist</span></div>';

        }
//End watchlist

    $rajat .= '<div class="jobBoard">
    <div class="tags"><img src="img/add_banners/feat.png"><img src="img/add_banners/seal.png"><img src="img/add_banners/urgent.png"><img src="img/add_banners/fulltime.png"><img src="img/add_banners/private.png"><img src="img/add_banners/nda.png"></div>
    <div class="proj_info"><div><a href="project_detailss.php?pid='.$pid.'" class="title">'.$p_title.'</a>'.$watch.'</div><div class="project_stats"><span class="bold">Fixed Price:  $'.$p_min.'-$'.$p_max.'</span>
        &nbsp;&nbsp;|&nbsp;&nbsp;Posted: '.$p_posted.'&nbsp;&nbsp;|&nbsp;&nbsp;Ends: '.$p_expire.'&nbsp;&nbsp;|&nbsp;&nbsp;<a class="numproposals-link" id="bubble_40683796" href="project_detailss.php?pid='.$pid.'" onmouseover="projectJs.showAvgBubble(\'40683796\',\'Low\',\'n/a\',\'High\',\'n/a\',\'Avg\',\'n/a\');" onmouseout="projectJs.hideAvgBubble();"><span class="bold">'.$p_bcount.'</span> Proposals</a></div>
    <div class="desc collapsed descFull" id="40683796Desc">
        '.$p_details.'</div><div class="prof">
        <span class="midgrey">Category:</span> <span title="Web Programming">Web Programming</span>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="midgrey">Skills:</span>'.$p_skills.'</span></div>
    <div class="prof"><span onmouseover="projectJs.showRatingTooltip(40683796);" onmouseout="projectJs.hideRatingTooltip(40683796);">
        <div class="eol-buyer-rating-small eol-buyer-rating-small-0" id="buyerRating40683796">
</div>| <a style="display:inline-block;" id="buyerRating40683796profurl" class="clientname" href="testing.php?u='.$p_own.'">'.$p_own.'</a>
</span>|&nbsp;&nbsp;<img data-src="/media/images/4.0/flags/in.gif" style="visibility: visible; zoom: 1; opacity: 1;" src="/media/images/4.0/flags/in.gif">&nbsp;&nbsp;'.$p_own_con.'</div></div>
</div> ';


}

 mysqli_free_result($query);
?>