[SOLVED] - MYSQL_QUERY Question - Driving me nuts
Moderator: General Moderators
-
reverend_ink
- Forum Contributor
- Posts: 151
- Joined: Sun Apr 20, 2003 1:18 am
- Location: Las Vegas | London
-
reverend_ink
- Forum Contributor
- Posts: 151
- Joined: Sun Apr 20, 2003 1:18 am
- Location: Las Vegas | London
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
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
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
-
reverend_ink
- Forum Contributor
- Posts: 151
- Joined: Sun Apr 20, 2003 1:18 am
- Location: Las Vegas | London
-
reverend_ink
- Forum Contributor
- Posts: 151
- Joined: Sun Apr 20, 2003 1:18 am
- Location: Las Vegas | London
Calling the function from index.php
The function on functions1.php
returning the function on index.php
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 ?>
?>-
reverend_ink
- Forum Contributor
- Posts: 151
- Joined: Sun Apr 20, 2003 1:18 am
- Location: Las Vegas | London
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 ?
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; ?>So to correct this I inserted into the top of the functions1.php
Code: Select all
<?php
$maingroup = $HTTP_POST_VARS["maingroup"];
?>This didnt correct the problem
-
leenoble_uk
- Forum Contributor
- Posts: 108
- Joined: Fri May 03, 2002 10:33 am
- Location: Cheshire
- Contact:
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.
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;
}
?>
?>-
reverend_ink
- Forum Contributor
- Posts: 151
- Joined: Sun Apr 20, 2003 1:18 am
- Location: Las Vegas | London
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; } ?> ?>
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
-
leenoble_uk
- Forum Contributor
- Posts: 108
- Joined: Fri May 03, 2002 10:33 am
- Location: Cheshire
- Contact:
-
reverend_ink
- Forum Contributor
- Posts: 151
- Joined: Sun Apr 20, 2003 1:18 am
- Location: Las Vegas | London
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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'];-
reverend_ink
- Forum Contributor
- Posts: 151
- Joined: Sun Apr 20, 2003 1:18 am
- Location: Las Vegas | London
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'];