This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
it says syntax error t_else, what could be the problem?
it really is making me crazy for finding what did i do wrong in this code
what could be myy mistake here?
<?php
include("../mysql_connect.php");
if (isset($_POST['search_form'])) {
$page1 = $_GET['page'];
if ($page1 == "" || $page1 == 1) {
$page1 = 0;
}
else {
$page1 = ($page1 * 5) - 5;
}
$query = "select * from tbl_news where news_title like '$_POST[search]' || news_author like '$_POST[search]' ";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
?>
<table class="table table-hover" border="2">
<col width="50%"></col>
<col width="40%"></col>
<col width="20%"></col>
<tr>
<td rowspan="3">
a href="news_view.php?id=<?php echo $row['news_id']; ?>">
<img src="<?php echo $row['news_image_location'] . $row['news_image']; ?>" height="300" width="500">
</a>
</td>
<td>Title: <?php echo $row['news_title']; ?></td>
</tr>
<tr>
<td>Author: <?php echo $row['news_author']; ?></td>
</tr>
<tr>
<td>Date: <?php echo $row['news_date_filed']; ?></td>
</tr>
</thead>
</table>
<?php
}
$query1 = "select * from tbl_news where news_title like '$_POST[search]' || news_author like '$_POST[search]'";
$result1 = mysql_query($query1);
$row1 = mysql_num_rows($result1);
$pagecount = $row1 / 5;
$pagecount = ceil($pagecount);
for ($count = 1; $count <= $pagecount; $count++) {
?>
<?php echo $count ?>
<?php
}
}
else{
$page1 = $_GET['page'];
if ($page1 == "" || $page1 == 1) {
$page1 = 0;
}
else {
$page1 = ($page1 * 5) - 5;
}
$query = "select * from tbl_news where news_status='Active' limit $page1,5";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
?>
<table class="table table-hover" border="2">
<col width="50%"></col>
<col width="40%"></col>
<col width="20%"></col>
<tr>
<td rowspan="3">
<a href="news_view.php?id=<?php echo $row['news_id']; ?>">
<img src="<?php echo $row['news_image_location'] . $row['news_image']; ?>" height="300"
width="500">
</a>
</td>
<td>Title: <?php echo $row['news_title']; ?></td>
</tr>
<tr>
<td>Author: <?php echo $row['news_author']; ?></td>
</tr>
<tr>
<td>Date: <?php echo $row['news_date_filed']; ?></td>
</tr>
</thead>
</table>
<?php
}
?>
<?php
$query1 = "select * from tbl_news where news_status='Active'";
$result1 = mysql_query($query1);
$row1 = mysql_num_rows($result1);
$pagecount = $row1 / 5;
$pagecount = ceil($pagecount);
for ($count = 1; $count <= $pagecount; $count++) {
?>
<?php echo $count ?>
<?php # code...
}
}
?>
here is the full code, of what errror gives me, please help me guys it takes me a a lot of time having this kind of problem i already tried everything i could but maybe you guys could me solve my problem hahahaha it really drained my mind here , im already mindblown on what is the my currently facing problem
You are missing < at the a tag inside the first while loop (exactly on line 21 when I copy/paste your code). That might be the reason it doesn't recognize the else statement, because it can't get to it properly.
try this code. may be it resolve your problem.
I have corrected some syntax mistake in your code.
<?php
include("../mysql_connect.php");
if (isset($_POST['search_form'])) {
$page1=$_GET['page'];
if ($page1=="" || $page1==1) {
$page1=0;
}
else{
$page1=($page1*5)-5;
}
$query="select * from tbl_news where news_title like '$_POST[search]' || news_author like '$_POST[search]' ";
$result=mysql_query($query);
while ($row=mysql_fetch_array($result)) {
?>
<table class="table table-hover" border="2">
<col width="50%"></col>
<col width="40%"></col>
<col width="20%"></col>
<tr>
<td rowspan="3">
<a href="news_view.php?id=<?php echo $row['news_id'];?>">
<img src="<?php echo $row['news_image_location'].$row['news_image'];?>" height="300" width="500">
</a>
</td>
<td>Title: <?php echo $row['news_title'];?></td>
</tr>
<tr>
<td>Author: <?php echo $row['news_author'];?></td>
</tr>
<tr>
<td>Date: <?php echo $row['news_date_filed'];?></td>
</tr>
</thead>
</table>
<?php
}
$query1="select * from tbl_news where news_title like '$_POST[search]' || news_author like '$_POST[search]'";
$result1=mysql_query($query1);
$row1=mysql_num_rows($result1);
$pagecount=$row1/5;
$pagecount=ceil($pagecount);
for ($count=1; $count <= $pagecount ; $count++) {
?>
<?php echo $count?>
<?php
}
}else{
$page1=$_GET['page'];
if ($page1=="" || $page1==1) {
$page1=0;
}
else{
$page1=($page1*5)-5;
}
$query="select * from tbl_news where news_status='Active' limit $page1,5";
$result=mysql_query($query);
while ($row=mysql_fetch_array($result)) {
?>
<table class="table table-hover" border="2">
<col width="50%"></col>
<col width="40%"></col>
<col width="20%"></col>
<tr>
<td rowspan="3">
<a href="news_view.php?id=<?php echo $row['news_id'];?>">
<img src="<?php echo $row['news_image_location'].$row['news_image'];?>" height="300" width="500">
</a>
</td>
<td>Title: <?php echo $row['news_title'];?></td>
</tr>
<tr>
<td>Author: <?php echo $row['news_author'];?></td>
</tr>
<tr>
<td>Date: <?php echo $row['news_date_filed'];?></td>
</tr>
</thead>
</table>
<?php
}
$query1="select * from tbl_news where news_status='Active'";
$result1=mysql_query($query1);
$row1=mysql_num_rows($result1);
$pagecount=$row1/5;
$pagecount=ceil($pagecount);
for ($count=1; $count <= $pagecount ; $count++) {
?>
<?php echo $count?>
<?php # code...
}
}
?>
Related
I have this report which filters data from 5 tables but it is very slow takes around 10 seconds. I tried using index on some columns but it did not help.
Basically the first query is the master and the others are for filtering it if the other queries condition met then it will skip it.
this is the script:
<div class="col-md-12">
<h3>List of Outstandings</h3>
<table class="table table-condensed table-bordered table-hover small">
<thead>
<tr>
<th >#</th>
<th>PR #</th>
<th>PR Type</th>
<th>Description</th>
<th>Dep.</th>
<th>Date</th>
<th>Requester</th>
<th>Assigned to</th>
</tr>
</thead>
<tbody>
<?php
$chkk = 0;
$sql = "SELECT * FROM msr WHERE Status ='Approved' ";
$result6 = $connn->query($sql);
if ($result6->num_rows > 0) {
$vo = 1;
while ($row0 = $result6->fetch_assoc()) {
$chkk = 0;
$MSRID = $row0["MSRID"];
$MSRType = $row0["MSRType"];
$result4 = "SELECT owner FROM tracking WHERE MSRID='$MSRID' ";
$MyRow4 = $connn->query($result4);
$row4 = $MyRow4->fetch_assoc();
$actionBy = $row4["owner"];
$resultusr = "SELECT RFQID FROM rfq WHERE MSRID='$MSRID' AND NOPO='No' ";
$MyRowusr = $connn->query($resultusr);
$rowusr = $MyRowusr->fetch_assoc();
$rfqcount = mysqli_num_rows($MyRowusr);
if ($rfqcount > 0) {
$chkk = 1;
}
$resultusr4 = "SELECT POID FROM po WHERE MSRID='$MSRID' ";
$MyRowusr4 = $connn->query($resultusr4);
$rowusr4 = $MyRowusr4->fetch_assoc();
$rfqcount4 = mysqli_num_rows($MyRowusr4);
if ($rfqcount4 > 0) {
$chkk = 1;
}
$resultusr1 = "SELECT MSRID FROM contract WHERE MSRID='$MSRID' ";
$MyRowusr1 = $connn->query($resultusr1);
$rowusr1 = $MyRowusr1->fetch_assoc();
$rfqcount1 = mysqli_num_rows($MyRowusr1);
if ($rfqcount1 > 0) {
$chkk = 1;
}
if ($chkk == 1) {
continue;
}
?>
<tr>
<td>
<?php echo $vo; ?>
</td>
<td>
<?php echo $row0["MSRID"]; ?>
</td>
<td>
<?php echo $row0["MSRType"]; ?>
</td>
<td>
<?php echo $row0["purposeofbuying"]; ?>
</td>
<td>
<?php echo depName($row0["DepRequester"]); ?>
</td>
<td>
<?php echo $row0["RequestDate"]; ?>
</td>
<td>
<?php echo reqName($row0["RequestPer"]); ?>
</td>
<td>
<?php echo reqName($actionBy); ?>
</td>
</tr>
<?php
$vo++;
}
}
?>
</tbody>
</table>
</div>
</div>
You can use subquery method instead of looping.
Example:
$sql = "SELECT *,
( SELECT owner
FROM tracking
WHERE tracking.MSRID= msr.MSRID
) AS _owner,
( SELECT RFQID
FROM rfq
WHERE rfq.MSRID= msr.MSRID
AND rfq.NOPO='No'
) AS _RFQID
FROM msr
WHERE rfq.Status ='Approved'";
Please help me how can i unlink a image when i delete a product.I dont know where is my error in my code .Thank everyone so much.I tried different way to resolve this problem.I teached myself learn to code on youtube, and then I tried to create another model.Please help me solve this problem.
Html Page
<h3>List Product</h3>
<table id="user">
<thead>
<tr>
<th>Serial</th>
<th>Product Name</th>
<th>Image</th>
<th>Price</th>
<th>Category</th>
<th>Type</th>
<th>Action</th>
</tr>
</thead>
<?php
if(!empty($_GET['msg'])){
$msg = unserialize(urldecode($_GET['msg']));
foreach ($msg as $key => $value){
echo '<span style="color:blue;font-weight:bold">'.$value.'</span>';
}
}
?>
<tbody>
<?php
$i = 0;
foreach($listproduct as $key => $listpro){
$i++;
?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo $listpro['productName']; ?></td>
<td><img src="<?php echo BASE_URL ?>/teamplate/image/<?php echo $listpro['image']; ?>" width="60" height="60"></td>
<td><?php echo $listpro['price']; ?></td>
<td><?php echo $listpro['catName'] ?></td>
<td>
<?php
if($listpro['type']==0){
echo 'Feathered';
}else{
echo 'Non-Feathered';
}
?>
</td>
<td>Delete
|| Edit
</td>
</tr>
<?php
}
?>
</tbody>
</table>
Function in Product page
public function delPro($id = NULL){
$tablePro = 'tbl_product';
$this->data = array();
$ProductModel = $this->load->model('ProductModel');
$result = $ProductModel->delProductById($tablePro, $id);
if($result == 1){
$this->data['productbyid'] = $ProductModel->updateProductById($tablePro, $id);
$path_unlink= BASE_URL."/teamplate/image/";
foreach($this->data['productbyid'] as $this->key => $this->value){
$image_pro = $this->value['image'];
unlink($path_unlink.$image_pro);
}
$mdata['msg'] = "Product Deleted Successfully...";
}else{
$mdata['msg'] = "Product Not Deleted...";
}
$url = BASE_URL."/Product/ListProduct?msg=".urlencode(serialize($mdata));
header("Location:$url");
}
ProductModel Page
public function updateProductById($tablePro, $id){
$query = "SELECT * from $tablePro where productId = '$id'";
return $this->db->select($query);
}
I am having an issue trying to figure how to replace mssql_result so that this code can work for mssql not MySQL. I have tried different ways still little lost on what to do. If anyone has any examples on how to do this would be big help. I will continue to try figuring it out and then post answer if I find it.
<html>
<head>
<title></title>
</head>
<body>
<?php
$serverName = "localhost";
$objConnect = new PDO( "sqlsrv:server=$serverName ; Database=maintenance", "test", "test123") or die("Error Connect to Database");
$strSQL = $objConnect->prepare("SELECT * FROM requests WHERE status='Received' ORDER BY id DESC");
$strSQL->execute();
$Num_Rows = $strSQL->fetchColumn();
$Per_Page = 2; // Per Page
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page)
{
$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
$Page_End = $Per_Page * $Page;
IF ($Page_End > $Num_Rows)
{
$Page_End = $Num_Rows;
}
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">Lan ID </div></th>
<th width="98"> <div align="center">Name </div></th>
</tr>
<?php
for($i=$Page_Start;$i<$Page_End;$i++)
{
?>
<tr>
<td><div align="center"><?php echo mssql_result($objQuery,$i,"lanId");?></div></td>
<td><?php echo mssql_result($objQuery,$i,"name");?></td>
<?php
}
?>
</table>
<br>
Total <?php echo $Num_Rows;?> Record : <?php echo $Num_Pages;?> Page :
<?php
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> ";
}
?>
</body>
</html>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">ID </div></th>
<th width="91"> <div align="center">Lan ID </div></th>
<th width="98"> <div align="center">Name </div></th>
</tr>
<?php
while($result = $strSQL->fetch( PDO::FETCH_ASSOC ))
{
?>
<tr>
<td><div align="center"><?php echo $result["lanId"];?></div></td>
<td><?php echo $result["name"];?></td>
<?php
}
?>
</table>
Im just New in Wordpress and in PHP .. Now Ive just uploaded a theme in Wordpress. The Problem is The Custom Pagination is not working in Wordpress but works well in USBWebserver. It Only Just show the Same Content
<table id="maincon2-Article">
<?php
$page2 = $_GET["page2"];
if($page2 == "" || $page2 == "1"){
$pages = 0;
}
else{
$pages = ($page2*3)-3;
}
$Mobartsql = "Select * from tbl_article ORDER BY `Article_ID` DESC limit 1,3";
$result4 = $con->query($Mobartsql);
while($row4 = $result4->fetch_assoc()){
echo '<tr>
<td style="width:50%">
<img src = "https://www.stlouisreviewcenter.com/wp-content/uploads/slrc/'.$row4["Art_pic"].'" id="artpiclink2"/>
</td>
<td style="padding-left:2%" >
<h1 id="art-head2" style="color:purple">'.$row4["Art_title"].' </h5>
</td>
</tr>';
$results1 = $con->query("Select * from tbl_article ORDER BY `Article_ID` DESC");
$rows2 = $result1->num_rows/3;
$rows2 = ceil($rows2);
}
echo '<tr>
<td><br></td>
</tr>
<tr>
<td colspan="2">';
for($i=1; $i<=$rows;$i++){
?> <button> <a href="/article/?page=<?php echo $i;?>" style="text-decoration:none;"/><?php echo $i; ?></a> </button>
<?php
}
?>
</td>
</tr>
<tr>
<td><br/></td>
</tr>
</table>
Here is the Sample .. Plz Need Help ..
Currently the below puts everything into rows, I am wondering if there is a way to put these as individual tables every time instead of rows?
I am used to echo everything to rows as everything I have dealt with so far, is perfectly fine. But now I am at a point where it would be better to show all as individual tables.
I might not be explaining myself very well, sorry if not.
<table width="75%" border="0" cellpadding="0" cellspacing="2" class="table">
<tr align="center">
<td class="header"><center>Patch Version</center></td>
<td class="header"><center>Patch Date</center></td>
<td class="header"><center>Update By</center></td>
<?php if ($userlvl >= 3) { ?><td class="header"><center>Admin Settings</center></td></tr> <?php } else { } ?>
</tr>
<?
$result = mysql_query("SELECT * FROM updates WHERE del ='0' ORDER BY id DESC") or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
?>
<tr>
</label></td>
<td class="header"><center><h4><? echo $row['patchversion'] ?></h3></center></td>
<td class="header"><center><h3><? echo $row['updatetime'] ?></h3></center></td>
<td class="header"><center><h4><? echo $row['addedby']?></h4></td>
<?php if ($userlvl >= 3) { ?><td class="header"><center><h4> <?php } else { } ?>
<?php if ($userlvl >= 3){ echo "( Edit )" ." - ". "( X )"; } else { } ?></center></td>
<tr><td class="cell" colspan="50"><? echo $row['news']?></td>
</tr>
<?php }
?>
</table>
Just move the table tags within your while loop, something like this for example:
<?php
while($row = mysql_fetch_array( $result )) {
?>
<table>
<tr>
<td class="header"><center><h4><? echo $row['patchversion'] ?></h3></center></td>
<td class="header"><center><h3><? echo $row['updatetime'] ?></h3></center></td>
<td class="header"><center><h4><? echo $row['addedby']?></h4></td>
<?php if ($userlvl >= 3) { ?><td class="header"><center><h4> <?php } else { } ?>
<?php if ($userlvl >= 3){ echo "( Edit )" ." - ". "( X )"; } else { } ?></center></td>
</tr>
</table>
<?php } ?>