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

Help Me

Postby Megobrebi » Sat Apr 23, 2011 2:04 pm

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: .
Syntax: [ Download ] [ Hide ]
 <?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)."'>" . $lang['PRODUCT_BACK'] . "</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>":"" . $lang['PRODUCT_NEXT'] . "");


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'); ?>
Megobrebi
Forum Newbie
 
Posts: 2
Joined: Sat Apr 23, 2011 1:56 pm

Re: Help Me

Postby getmizanur » Sat Apr 23, 2011 4:47 pm

does your code enter if() statement?
User avatar
getmizanur
Forum Commoner
 
Posts: 71
Joined: Sun Sep 06, 2009 12:28 pm

Re: Help Me

Postby Megobrebi » Sun Apr 24, 2011 3:03 am

Yes there is many if() you can see in code. :roll:
Megobrebi
Forum Newbie
 
Posts: 2
Joined: Sat Apr 23, 2011 1:56 pm

Re: Help Me

Postby getmizanur » Sun Apr 24, 2011 5:14 pm

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


mmm...

what i mean is, does your code meet this condition
Syntax: [ Download ] [ Hide ]
if($row = mysql_fetch_array($result)){


is there any data in $result variable?
User avatar
getmizanur
Forum Commoner
 
Posts: 71
Joined: Sun Sep 06, 2009 12:28 pm

Re: Help Me

Postby superdezign » Sun Apr 24, 2011 6:53 pm

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.
User avatar
superdezign
DevNet Master
 
Posts: 4135
Joined: Sun Jan 21, 2007 12:06 am


Return to PHP - Theory and Design

Who is online

Users browsing this forum: No registered users and 1 guest