Help Me

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
Megobrebi
Forum Newbie
Posts: 2
Joined: Sat Apr 23, 2011 1:56 pm

Help Me

Post by Megobrebi »

Hello! I Have Web-Site and the Web-Site has products page. First time This Page working very well I need to change something in this code but when i change this product page does not show anything it show just index.php codes. I can't correct this :banghead: .

Code: Select all

 <?PHP include_once('sitemap.php'); ?>

<DIV class="page_container">

<?PHP include_once('productcategory.php'); ?>

<div style="float:left;">
<table border="0">
<?PHP

$page = $_GET['pagenum'];


if($_GET['category'])
{
$add_Q=" WHERE cat_id="'" . $_GET['category'] . "' ";
}
else
{
$add_Q=" ";
}


$records_per_page = 7;
if(!filter_var($page, FILTER_VALIDATE_INT, 1))
$page=1;

$offset = ($page-1) * $records_per_page;

$result = mysql_query("SELECT * FROM products $add_Q ORDER BY prod_id DESC LIMIT $offset, $records_per_page");

if($row = mysql_fetch_array($result)){
  do{

$id=$row['prod_id'];
$name=$row['prod_name'];
$pn=$row['prod_pn'];
$price=$row['prod_price'];
$description=$row['prod_qdescription'];
$image1="product_images/" . $id . "/" . $row['image1'];

echo "<tr>
    <td rowspan='2'><center><a href='index.php?lan=$lan&page=detail&id=$id'><img src='$image1' width='120' height='120'/></a><br><b>$pn</b></center></td>
    <td><a href='index.php?lan=$lan&page=detail&id=$id' class='product_name'>$name</a><br><br><b style='font-size:12px;'>" . $lang['PRODUCT_PRICE'] . ": $price GEL</b></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>";


} while($row = mysql_fetch_array($result));
}


echo "</table>";


function build_url($filename, $key, $value){
  $values = array();
  $query_str = array();

parse_str($_SERVER['QUERY_STRING'], $values);

foreach($values as $k=>$v){
    if($k!=$key){
      $query_str[] = "{$k}={$v}";
    }
  }
  $query_str[] = "{$key}={$value}";

  return "$filename&".implode("&", $query_str);
}

$count_result = mysql_query("SELECT COUNT(*) FROM products $add_Q");
$count_row = mysql_fetch_array($count_result);
$count = $count_row["COUNT(*)"];


echo "<div style='float:left; width:100%; text-align:center; margin-top:25px; margin-bottom:30px;'>";

echo (($page>1)?"<a href='".build_url("index.php?lan=$lan&page=products", "pagenum", $page-1)."'>A« " . $lang['PRODUCT_BACK'] . "</a>":"A« " . $lang['PRODUCT_BACK'] . "")." | ";

for($i=1; $i<=($count/$records_per_page)+1; $i++){
  if($i!=$page)
    echo "<a style='text-decoration:underline;' href='".build_url("index.php?lan=$lan&page=products", "pagenum", $i)."'>$i</a> ";
  else
    echo $i;
  if($i<$count/$records_per_page)
    echo " | ";
}

echo ' | ' . (($page<$count/$records_per_page)?"<a href='".build_url("index.php?lan=$lan&page=products", "pagenum", $page+1)."'>" . $lang['PRODUCT_NEXT'] . " A»</a>":"" . $lang['PRODUCT_NEXT'] . " A»");


echo "</div></div>";
?>


</DIV>

<?PHP //include_once('leftbanners.php'); ?>

<?PHP include_once('sitemap.php'); ?>

<DIV class="page_container">

<?PHP include_once('productcategory.php'); ?>

<div style="float:left;">
<table border="0">
<?PHP

$page = $_GET['pagenum'];


if($_GET['category'])
{
$add_Q=" WHERE cat_id='" . $_GET['category'] . "' ";
}
else
{
$add_Q=" ";
}


$records_per_page = 7;
if(!filter_var($page, FILTER_VALIDATE_INT, 1))
$page=1;

$offset = ($page-1) * $records_per_page;

$result = mysql_query("SELECT * FROM products $add_Q ORDER BY prod_id DESC LIMIT $offset, $records_per_page");

if($row = mysql_fetch_array($result)){
  do{

$id=$row['prod_id'];
$name=$row['prod_name'];
$pn=$row['prod_pn'];
$price=$row['prod_price'];
$description=$row['prod_qdescription'];
$image1="product_images/" . $id . "/" . $row['image1'];

echo "<tr>
    <td rowspan='2'><center><a href='index.php?lan=$lan&page=detail&id=$id'><img src='$image1' width='120' height='120'/></a><br><b>$pn</b></center></td>
    <td><a href='index.php?lan=$lan&page=detail&id=$id' class='product_name'>$name</a><br><br><b style='font-size:12px;'>" . $lang['PRODUCT_PRICE'] . ": $price GEL</b></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>";


} while($row = mysql_fetch_array($result));
}


echo "</table>";


function build_url($filename, $key, $value){
  $values = array();
  $query_str = array();

parse_str($_SERVER['QUERY_STRING'], $values);

foreach($values as $k=>$v){
    if($k!=$key){
      $query_str[] = "{$k}={$v}";
    }
  }
  $query_str[] = "{$key}={$value}";

  return "$filename&".implode("&", $query_str);
}

$count_result = mysql_query("SELECT COUNT(*) FROM products $add_Q");
$count_row = mysql_fetch_array($count_result);
$count = $count_row["COUNT(*)"];


echo "<div style='float:left; width:100%; text-align:center; margin-top:25px; margin-bottom:30px;'>";

echo (($page>1)?"<a href='".build_url("index.php?lan=$lan&page=products", "pagenum", $page-1)."'>A« " . $lang['PRODUCT_BACK'] . "</a>":"A« " . $lang['PRODUCT_BACK'] . "")." | ";

for($i=1; $i<=($count/$records_per_page)+1; $i++){
  if($i!=$page)
    echo "<a style='text-decoration:underline;' href='".build_url("index.php?lan=$lan&page=products", "pagenum", $i)."'>$i</a> ";
  else
    echo $i;
  if($i<$count/$records_per_page)
    echo " | ";
}

echo ' | ' . (($page<$count/$records_per_page)?"<a href='".build_url("index.php?lan=$lan&page=products", "pagenum", $page+1)."'>" . $lang['PRODUCT_NEXT'] . " A»</a>":"" . $lang['PRODUCT_NEXT'] . " A»");


echo "</div></div>";
?>


</DIV>

<?PHP //include_once('leftbanners.php'); ?>
User avatar
getmizanur
Forum Commoner
Posts: 71
Joined: Sun Sep 06, 2009 12:28 pm

Re: Help Me

Post by getmizanur »

does your code enter if() statement?
Megobrebi
Forum Newbie
Posts: 2
Joined: Sat Apr 23, 2011 1:56 pm

Re: Help Me

Post by Megobrebi »

Yes there is many if() you can see in code. :roll:
User avatar
getmizanur
Forum Commoner
Posts: 71
Joined: Sun Sep 06, 2009 12:28 pm

Re: Help Me

Post by getmizanur »

Megobrebi wrote:Yes there is many if() you can see in code. :roll:
mmm...

what i mean is, does your code meet this condition

Code: Select all

if($row = mysql_fetch_array($result)){
is there any data in $result variable?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Help Me

Post by superdezign »

Just a tip:

If you want more responses, you need to pinpoint where your error resides instead of stating that a script doesn't work and giving us the entire thing. Tell us what it should be doing versus what it is doing. "Not showing anything" is far too vague. The only advice I can give you is to enable display_errors and set error_reporting to E_ALL.
Post Reply