これは単独で動作するスクリプトですが、それらを一緒に使用すると、想定どおりに動作しません。ここでの問題は、while ループ内の if 条件が、データベースから値を取得し、$rajat でさらに使用される $watch の値の条件に応じてステートメントを実行することになっていることです。ただし、while ループは 1 回だけ実行されます。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>
| Posted: '.$p_posted.' | Ends: '.$p_expire.' | <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>
<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>| <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"> '.$p_own_con.'</div></div>
</div> ';
}
mysqli_free_result($query);
?>