Page 2 of 2

Posted: Mon May 17, 2004 1:59 pm
by feyd
stupid question, what's $maingroup set to?

Posted: Mon May 17, 2004 2:16 pm
by reverend_ink
feyd wrote:stupid question, what's $maingroup set to?
It is a value that is set by a previous function in the script

but can be 2,4,6,7,20 or so on, its an id variable.

Posted: Mon May 17, 2004 2:20 pm
by reverend_ink
This may help somewhat, as I am still trying to debug

I entered print $maingroup; in the functions page BEFORE the WHILE statement but it returns nothing.

That would make sense as to why it isnt working I would think.

I am still at this

If you would like to see the pages for both (index.php & functions1.php) I will be happy to post

Posted: Mon May 17, 2004 2:22 pm
by magicrobotmonkey
are you calling it correctly?

Posted: Mon May 17, 2004 2:25 pm
by reverend_ink
magicrobotmonkey wrote:are you calling it correctly?
You know I am starting to doubt it.

I dont know what is going on.

Posted: Mon May 17, 2004 2:28 pm
by reverend_ink
Calling the function from index.php

Code: Select all

<?php
$product_list=show_products($maingroup); 


?>
The function on functions1.php

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; 
} 

?>
returning the function on index.php

Code: Select all

<?php
<? echo $product_list ?>

?>

Posted: Mon May 17, 2004 2:36 pm
by markl999
Sounds like the problem is before :
$product_list=show_products($maingroup);

What's the code that sets/gets $maingroup ?

Posted: Mon May 17, 2004 2:39 pm
by reverend_ink
markl999 wrote:Sounds like the problem is before :
$product_list=show_products($maingroup);

What's the code that sets/gets $maingroup ?
I think I found the problem.

Now to find the solution.

The script generates this info as the link to click which queries the db for the show_products function

index.php?level=2&maingroup=4&choice=4

Now in the function I

Code: Select all

<? print $maingroup; ?>
and I get no return value.

So to correct this I inserted into the top of the functions1.php

Code: Select all

<?php
 $maingroup = $HTTP_POST_VARS["maingroup"];

?>
Just in case register_globals was turned off.

This didnt correct the problem

Posted: Mon May 17, 2004 2:42 pm
by leenoble_uk
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; 
} 

?> 

?>

Posted: Mon May 17, 2004 2:45 pm
by reverend_ink
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; 
} 

?> 

?>
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.

I am now down to the real problem.

The maingroup is not being posted to the function.

It cant very well get results if it has nothing to get with

Posted: Mon May 17, 2004 2:47 pm
by leenoble_uk
Within the function yes?
Because it must be within the function.

Posted: Mon May 17, 2004 2:49 pm
by reverend_ink
leenoble_uk wrote:Within the function yes?
Because it must be within the function.
That part works, I replaced the variable with a real number and it worked.

Its getting the variable $maingroup to the function than back to the index.php

Posted: Mon May 17, 2004 2:52 pm
by feyd
reverend_ink wrote: index.php?level=2&maingroup=4&choice=4

Code: Select all

<?php
 $maingroup = $HTTP_POST_VARS["maingroup"];

?>
This didnt correct the problem
might try

Code: Select all

$maingroup = $_GET['maingroup'];

Posted: Mon May 17, 2004 2:59 pm
by reverend_ink
feyd wrote:
reverend_ink wrote: index.php?level=2&maingroup=4&choice=4

Code: Select all

<?php
 $maingroup = $HTTP_POST_VARS["maingroup"];

?>
This didnt correct the problem
might try

Code: Select all

$maingroup = $_GET['maingroup'];
feyd thank you, been looking at code too long!