Posted: Mon May 17, 2004 1:59 pm
stupid question, what's $maingroup set to?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
It is a value that is set by a previous function in the scriptfeyd wrote:stupid question, what's $maingroup set to?
You know I am starting to doubt it.magicrobotmonkey wrote:are you calling it correctly?
Code: Select all
<?php
$product_list=show_products($maingroup);
?>Code: Select all
<?php
function show_products($maingroup) {
$query= "select cat_trans.catid,product.name,product.id from cat_trans,product_trans,product where
cat_trans.catid='$maingroup' and cat_trans.catid=product_trans.catid and product_trans.productid=product.id order by product.name asc";
$results=mysql_query($query) or die(mysql_error());
$x=1;
if(mysql_num_rows($results)){
while($row=mysql_fetch_array($results)) {
if($x == 1) {
$product_list .= '<tr><td><a href="productinfo.php?id='.$row[2].'"><FONT size="2" face="Verdana" color="#6699ff"><B>'.$row[1].'</b></a></td>';
} elseif ($x == 2) {
$product_list .= '<td><a href="productinfo.php?id='.$row[2].'"><FONT size="2" face="Verdana" color="#6699ff"><B>'.$row[1].'</b></a></td>';
} elseif($x == 3) {
$product_list .= '<td><a href="productinfo.php?id='.$row[2].'"><FONT size="2" face="Verdana" color="#6699ff"><B>'.$row[1].'</b></a></td></tr>';
}
$x++;
}
} else {
$product_list = "<tr><td>No results found.</td></tr>";
}
mysql_free_result($results);
return $product_list;
}
?>Code: Select all
<?php
<? echo $product_list ?>
?>I think I found the problem.markl999 wrote:Sounds like the problem is before :
$product_list=show_products($maingroup);
What's the code that sets/gets $maingroup ?
Code: Select all
<? print $maingroup; ?>Code: Select all
<?php
$maingroup = $HTTP_POST_VARS["maingroup"];
?>Code: Select all
<?php
<?php
function show_products($maingroup) {
global $sql; //You have got this?
$query= "select cat_trans.catid,product.name,product.id from cat_trans,product_trans,product where
cat_trans.catid='$maingroup' and cat_trans.catid=product_trans.catid and product_trans.productid=product.id order by product.name asc";
$results=mysql_query($query,$sql) or die(mysql_error()); //and this?
$x=1;
if(mysql_num_rows($results)){
while($row=mysql_fetch_array($results)) {
if($x == 1) {
$product_list .= '<tr><td><a href="productinfo.php?id='.$row[2].'"><FONT size="2" face="Verdana" color="#6699ff"><B>'.$row[1].'</b></a></td>';
} elseif ($x == 2) {
$product_list .= '<td><a href="productinfo.php?id='.$row[2].'"><FONT size="2" face="Verdana" color="#6699ff"><B>'.$row[1].'</b></a></td>';
} elseif($x == 3) {
$product_list .= '<td><a href="productinfo.php?id='.$row[2].'"><FONT size="2" face="Verdana" color="#6699ff"><B>'.$row[1].'</b></a></td></tr>';
}
$x++;
}
} else {
$product_list = "<tr><td>No results found.</td></tr>";
}
mysql_free_result($results);
return $product_list;
}
?>
?>Its ok, I am looking at the code in so many new ways that I am starting to go crazy, but the global $sql is set a little higher in the code.leenoble_uk wrote:I don't mean to be deliberately dense but are you taking out the crucial global line before you post it up here for some reason and the second parameter for the mysql_query function (I know it's not strictly necessary but since I can't see the db connection...)?
If so then ignore me.
Code: Select all
<?php <?php function show_products($maingroup) { global $sql; //You have got this? $query= "select cat_trans.catid,product.name,product.id from cat_trans,product_trans,product where cat_trans.catid='$maingroup' and cat_trans.catid=product_trans.catid and product_trans.productid=product.id order by product.name asc"; $results=mysql_query($query,$sql) or die(mysql_error()); //and this? $x=1; if(mysql_num_rows($results)){ while($row=mysql_fetch_array($results)) { if($x == 1) { $product_list .= '<tr><td><a href="productinfo.php?id='.$row[2].'"><FONT size="2" face="Verdana" color="#6699ff"><B>'.$row[1].'</b></a></td>'; } elseif ($x == 2) { $product_list .= '<td><a href="productinfo.php?id='.$row[2].'"><FONT size="2" face="Verdana" color="#6699ff"><B>'.$row[1].'</b></a></td>'; } elseif($x == 3) { $product_list .= '<td><a href="productinfo.php?id='.$row[2].'"><FONT size="2" face="Verdana" color="#6699ff"><B>'.$row[1].'</b></a></td></tr>'; } $x++; } } else { $product_list = "<tr><td>No results found.</td></tr>"; } mysql_free_result($results); return $product_list; } ?> ?>
That part works, I replaced the variable with a real number and it worked.leenoble_uk wrote:Within the function yes?
Because it must be within the function.
might tryreverend_ink wrote: index.php?level=2&maingroup=4&choice=4This didnt correct the problemCode: Select all
<?php $maingroup = $HTTP_POST_VARS["maingroup"]; ?>
Code: Select all
$maingroup = $_GET['maingroup'];feyd thank you, been looking at code too long!feyd wrote:might tryreverend_ink wrote: index.php?level=2&maingroup=4&choice=4This didnt correct the problemCode: Select all
<?php $maingroup = $HTTP_POST_VARS["maingroup"]; ?>Code: Select all
$maingroup = $_GET['maingroup'];