Jump to content

[SOLVED] can someone help?


menios

Recommended Posts

I ve been trying to display items from my product table but instead of selecting them by category id it just displays everything.

I can't find what goes wrong.

so here is the code if someone could help with  :)

 


<html>


<body>
<?php
 $rpp;		//Records Per Page
 $cps;		//Current Page Starting row number
 $lps;		//Last Page Starting row number

/////////////////////////////////////////////////////////////////////////////////
//Database connection
/////////////////////////////////////////////////////////////////////////////////
$user="root";
$password="asere";
$database="smalltownbooks";
$tablename="tbl_product";
$conn=mysql_connect("localhost",$user,$password);

mysql_select_db($database,$conn) or die( "Unable to select database");
mysql_query($sql,$conn);
if (isset($_GET['1']))
{
    $cat = $_GET['1'];      //  for simplicity only. 
                              
    $sql = "SELECT * FROM tbl_product WHERE cat_id = '$cat'";
    echo $sql or die ("dead");

}
/////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////
//Load for the first time First result printed user will click next to change
/////////////////////////////////////////////////////////////////////////////////	
if(empty($_GET["cps"])) 
{
	$cps = "0";
} 
else
{
	$cps = $_GET["cps"];
}
/////////////////////////////////////////////////////////////////////////////////

$a = $cps+1; 

$rpp = "15";

$lps = $cps - $rpp; //Calculating the starting row number for previous page

/////////////////////////////////////////////////////////////////////////////////
//Check for previus link If the user is viewing the first set of data then the link will
//be disabled, if on the next set then it will carry the $lps in its link and enable it
if ($cps <> 0)
{
	$prv =  "<a href='cookery.php?cps=$lps'>Previous</a>";
}
else	
{
	$prv =  "<font color='cccccc'>Previous</font>";
}
/////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
$q="Select SQL_CALC_FOUND_ROWS * from tbl_product limit $cps, $rpp";
$rs=mysql_query($q) or die(mysql_error());
$nr = mysql_num_rows($rs); //Number of rows found with LIMIT in action

$q0="Select FOUND_ROWS()";
$rs0=mysql_query($q0) or die(mysql_error());
$row0=mysql_fetch_array($rs0);
$nr0 = $row0["FOUND_ROWS()"]; //Number of rows found without LIMIT in action

/////////////////////////////////////////////////////////////////////////////////
//Check  the user has reached thelast page of the items	
if (($nr0 < 50) || ($nr < 10))
{
   		$b = $nr0;
}
else
{
	$b = ($cps) + $rpp;
}

/////////////////////////////////////////////////////////////////////////////////

?>
<br>
<table border="1" cellpadding="4" cellspacing="1" width="100%" align="center">
  
  <tr><td bgcolor="#000080" align='Center'><b><font face="verdana" color="#FFFFFF">Title</font></b></td>
  <td bgcolor="#000080" align='Center'><b><font face="verdana" color="#FFFFFF">test</font></b></td>
</tr>
<?php
while ($row=mysql_fetch_array($rs))
{
	/////////////////////////////////////////////////////////////////////////////////
	//loop after fullfilling the above SQL criteria.
	/////////////////////////////////////////////////////////////////////////////////
	$cps = $cps +1; 

	$val=$row["pd_name"];
	$val2=$row ["pd_price"];
	$val3=$row ["cat_id"];
	echo "<tr><td width='10%' align='center'><font face=verdana><img</font></td><td align='center'><font fave=verdana>$val $val2 $val3 </font></td></tr>";  

}

echo "<tr><td align='right' colspan=2>$prv";


//Check whether there is a Next link if not disable

if ($cps == $nr0)
{ 	
	echo "  |  <font color='CCCCCC'>Next</font>";
}
else
{
	if ($nr0 > 5)
	{ 
		echo "  |  <a href='cookery.php?cps=$cps&lps=$lps'>Next  </a>"; 
	}
}


?>
</td>
</tr>
</table>
</body>
</html>

Link to comment
Share on other sites

Lets look at it from a logical view.

 

If you do

 

echo $a

 

$a = 1

 

What would $a echo out?  Nothing right, because you are not setting it until after you echo it.

 

So you are doing a mysql query before you enter the parameters.

Link to comment
Share on other sites

which parameter am i missing cause i understand what what you mean by stating the parameters first but i m not using any parameters

all i wan to do is display only the content of a certain category. so i need to set a parameter about category_id?

I m getting confused about it to tell you the truth If you could help me understant it i would re appreciate it

Thanks in advance for your time

Link to comment
Share on other sites

Since that is solved i ve been trying to connect the results i m getting with some nested lists.

I m trying to display diff results in an iframe.So i need to connect the list(buttons)-with the .php files and display them in the iframe.

Any help with this?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.