PDA

View Full Version : [PHP] Help



Luno1599
08-02-2008, 06:50 PM
Hey,

I am makeing an online catalog for my dads company. However im haveing some issues, I am getting errors when trying to split it up, Can you guys have a look and see if you can fix it.

Code:

<?php
// List Products
include("config.php");
$cet_idd = $_GET['categorie'];
if($cet_idd == "1"){
$name = "<font class='top_name'><u>TIG AC/DC</u></font><br><br>";
}elseif($cet_idd == "2"){
$name = "<font class='top_name'><u>TIG DC</u></font><br><br>";
}elseif($cet_idd == "3"){
$name = "<font class='top_name'><u>MIG MAG Welding</u></font><br><br>";
}elseif($cet_idd == "4"){
$name = "<font class='top_name'><u>Plasma</u></font><br><br>";
}elseif($cet_idd == "5"){
$name = "<font class='top_name'><u>MMA Arcwelding</u></font><br><br>";
}elseif($cet_idd == "6"){
$name = "<font class='top_name'><u>Chargers</u></font><br><br>";
}else{
$name = "Please selece a catorgire.";
}
echo "$name";

if($name != "Please selece a catorgire."){
$result = mysql_query("SELECT * FROM products WHERE cat_id = '$cet_idd'");
if(mysql_fetch_array($result) == 0){
echo "This catogrie currently has no items in it.";
mysql_close();
}else{
/////////////////////////////////////////////////
/////////////////////////////////////////////////
/////////////////////////////////////////////////
/////////////////////////////////////////////////
/////////////////////////////////////////////////
/////////////////////////////////////////////////
$pagess = $_GET['page'];
$resultsperpage = 5 ; // this is how many results you want to show per page
$pg = max(intval($pagess , 1 )); // if they did not requst page, they are on page 1
$aadsa = intval(($pg -1)*$resultsperpage);
$query = "SELECT * FROM products WHERE cat_id = '$cet_idd' LIMIT '$aadsa' , $resultsperpage";
$res = mysql_query ($query) ;
// this is your total number of items with no regards to LIMIT in the query
// doing query over just to get this number is pointless
$found_count = mysql_result (mysql_query ("SELECT FOUND_ROWS() ") , 0 ) ;
// now you loop over your results
$products = '' ;
while ($row = mysql_fetch_assoc ($res) ) { //do something with your products here
$id = $row["id"];
$prod_id = $row["prod_id"];
$prod_name = $row["prod_name"];
$prod_dis = $row["prod_dis"];
$url = $row["URL"];
$prod_offer_text = $row["prod_offer_text"];
$prod_offer_price = $row["prod_offer_price"];
$prod_price = $row["prod_price"];
//
if($prod_offer_text == ""){
$new_offer_text = "";
}else{
$new_offer_text = "$prod_offer_text";
}
if($prod_offer_text || $prod_offer_price != ""){
$price = "<STRIKE>&pound;$prod_price</STRIKE> - &pound;$prod_offer_price";
}else{
$price = "&pound;$prod_price";
}
echo "<table width='100%' cellpadding='0' cellspacing='0'>";
echo "
<tr>
<td width='13%' rowspan='3' align='center' valign='top'><a href='?view=view_products&&id=$prod_id'><img src='$url' width='150' height='150' border='0'></a></td>
<td colspan='3'><font class='product_name'><b>&nbsp;&nbsp;#$prod_id - $prod_name</b></font></td>
</tr>
<tr>
<td height='96' colspan='3' valign='top'><br>$prod_dis<br></td>
</tr>
<tr>
<td width='59%' height='33'><font class='product_offer'>&nbsp;&nbsp;$new_offer_text</font></td>
<td width='23%'><font class='product_price'>$price</font></td>
<td width='5%' align='right'><a href='?view=view_products&&id=$prod_id'>More?</a></td>
</tr>
";
echo "</table><hr><br>";
//////////////////
////////////////////
//////////////////
/////////////////
// $products .= $r['name'] ."<br>" ;
}}}
if (!$products) {
//there were no products , do something about it
echo "error";
}
// here are simple pagination links
$pages = '';
for ($i=1 ; $i <= ceil($found_count / $resultsperpage) ; $i++ ) {
$pages .= '<a href="products.php?pg='.$i.'">'.$i.'</a>';
}
// $pages string now has your navigation in it
?>

Error:

Warning: Wrong parameter count for max() in /home/master/public_html/...... on line 38

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/master/public_html/...... on line 49
error

Danny

Florx
08-02-2008, 10:28 PM
Well the SQL error is because:
it needs to be LIMIT BY 0,1 or something similar:

LIMIT BY $aadsa,$resultsperpage
And the parameter count for max is wrong because you haven't put enough of these or too many. I haven't had a look at your code.:



max('one','two','three')

Blob
09-02-2008, 02:15 PM
Well the SQL error is because:
it needs to be LIMIT BY 0,1 or something similar:

LIMIT BY $aadsa,$resultsperpage
And the parameter count for max is wrong because you haven't put enough of these or too many. I haven't had a look at your code.:



max('one','two','three')


No, as $aadsa and $resultsperpage are obviously set to like 10 or 21

Luno1599
09-02-2008, 03:22 PM
I got another Error


Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/master/public_html/..... on line 14

Some of the code:

$sql = mysql_query("SELECT * FROM products WHERE cet_idd = '$cet_idd' LIMIT $start_from, $datashow");
// Start
while ($row = mysql_fetch_row($sql)) { //do something with your products here
$id = $row["id"];
$prod_id = $row["prod_id"];
$prod_name = $row["prod_name"];

(Line 14 is in there (first Line))

Florx
09-02-2008, 04:45 PM
LIMIT BY whatever,whatever

and @BLOB that's what I meant :p

Want to hide these adverts? Register an account for free!