Page 1 of 1
need to stop echo showing but not sure how
Posted: Fri Sep 15, 2006 8:44 am
by rsmarsha
Code: Select all
foreach ($_POST as $postName => $postValue)
{
//negative exception start
$exception_search = "SELECT exception_id,description FROM products,exceptions LEFT JOIN categories ON products.category_id=categories.category_id WHERE exceptions.product_id=products.product_id AND negative='1' AND products.product_id='$postValue' ORDER BY category_order ASC";
$eq2 = mysql_query($exception_search) or die("Query $exception_search Failed".mysql_error());
//finds product description and then cycles though the ones posted
while ($er2 = mysql_fetch_assoc($eq2))
{
echo ''.$design1.'Product '.$er2['description'].' must be chosen with one of : - <br /><br />'; //this is the echo i want to not sure
$exception_search = "SELECT * FROM exceptions,products LEFT JOIN categories ON products.category_id=categories.category_id WHERE products.product_id=exceptions.product_id AND products.product_id='$postValue' AND exceptions.negative='1' ORDER BY category_order ASC";
$eq = mysql_query($exception_search) or die("Query $exception_search Failed".mysql_error());
while ($er = mysql_fetch_assoc($eq)) //this finds all products that much match the one in the first while loop and for each matching product increases $neg_count by 1
{
$neg_count=0;
foreach ($_POST as $postName => $postValue)
{
if ($er['exception_id']==$postValue)
{
$neg_count++;
}
}
if ($neg_count==0) //if no products in while loop 2 matched the one linked from while loop 1, it shows an error
{$text = "SELECT products.description FROM exceptions,products WHERE exceptions.exception_id=products.product_id AND exceptions.exception_id='".$er['exception_id']."'";
$tq = mysql_query($text) or die("Query $exception_search Failed".mysql_error());
$tr = mysql_fetch_assoc($tq);
echo ''.$tr['description'].'<br />';
$count++;
$nopass++;
}
}
echo $design2; //closes the error display box
}
} //neg exception end
The problem i have is that if there are no errors for the product in while loop 1, i can't get the first echo not to display as i don't know there are no errors until after it has been shown.
Posted: Fri Sep 15, 2006 8:48 am
by volka
Posted: Fri Sep 15, 2006 8:50 am
by rsmarsha
? for what ?
I can't think of another way to work it that i'm doing atm.
Each product is posted though as $postName $postValue
I need to take each value and get it's description.
Next find any exceptions in the table matching the current $postValue.
Increment a count which shows that there was 1 or more found and then if that count is 0 show an error. As if a matching product is found to the rule that exists then all is ok.
If none are found the error is shown in a box with the products listed that the current $postValue should be used with.
The problem is the echo line near the top which says Product '.$er2['description'].' must be chosen with one of : - , i only want this to show if the count is 0 for the loop. The problem is this count isn't set until further down the page and i'm not sure how to find out further up.

Posted: Fri Sep 15, 2006 9:44 am
by volka
foreach ($_POST as $postName => $postValue)
{
//negative exception start
$exception_search = "SELECT exception_id,description FROM products,exceptions LEFT JOIN categories ON products.category_id=categories.category_id WHERE exceptions.product_id=products.product_id AND negative='1' AND products.product_id='$postValue' ORDER BY category_order ASC";
$eq2 = mysql_query($exception_search) or die("Query $exception_search Failed".mysql_error());
//finds product description and then cycles though the ones posted
while ($er2 = mysql_fetch_assoc($eq2))
{
echo ''.$design1.'Product '.$er2['description'].' must be chosen with one of : - <br /><br />'; //this is the echo i want to not sure
$exception_search = "SELECT * FROM exceptions,products LEFT JOIN categories ON products.category_id=categories.category_id WHERE products.product_id=exceptions.product_id AND products.product_id='$postValue' AND exceptions.negative='1' ORDER BY category_order ASC";
These two queries are more or less the same (if I'm not mistaken). What's the point in this?
Posted: Fri Sep 15, 2006 9:54 am
by rsmarsha
The first one gets the product desc which i need to be outside of the 2nd while loop or it will show that product desc along with each product found in query 2.
It works like this :
I need to check each product coming though as $postValue in the db. The table checked is called exceptions, but in this case i'm looking for those with negative tagged as 1. This means i'm looking for products in the field exception_id that match each postValue sent through from the previous page.
I need to loop though each postValue to find these products for one postValue.
So if there was a rule saying product 1 had to be posted with 2 or 3, then i'd look in the table for all exceptions where the product_id is 1 and the exception id is 2 or 3. If these are found then no error should show, if they are not then i need to show :
product 1 (posted though as $postValue), must be chosen along with products 2 or 3 (also posted as postValue).
this is what i'm trying to do, have gotten into a bit of a mess with it and am stressed atm, lol. If you can help me get this outcome i'd be very grateful.
Posted: Fri Sep 15, 2006 6:08 pm
by volka
Seems a lot easier to me to first pull all the dependencies from the database, re-arrange them as an product_id->exception array and then check the posted values. At least if there are less than dozens of product ids in one request.
That takes only one single sql query, a while loop to fetch and re-arrange the db data and one loop to check the posted values.
Posted: Mon Sep 18, 2006 3:48 am
by rsmarsha
At the moment i have :
Code: Select all
foreach ($_POST as $postName => $postValue)
{
$exception_search = "SELECT * FROM exceptions,products LEFT JOIN categories ON products.category_id=categories.category_id WHERE products.product_id=exceptions.product_id AND products.product_id='$postValue' AND exceptions.negative='1' ORDER BY category_order ASC";
$eq = mysql_query($exception_search) or die("Query $exception_search Failed".mysql_error());
if (mysql_num_rows($eq)>0)
{
while ($er = mysql_fetch_assoc($eq))
{
foreach ($_POST as $postName => $postValue)
{
if ($er['exception_id']==$postValue)
{
$neg_count++;
}
}
if ($neg_count==0)
{
echo ''.$design1.'Product '.$er['description'].' must be chosen with one of : - <br /><br />';
$text = "SELECT products.description FROM exceptions,products WHERE exceptions.exception_id=products.product_id AND exceptions.product_id='".$er['product_id']."'";
$tq = mysql_query($text) or die("Query $exception_search Failed".mysql_error());
while ($tr = mysql_fetch_assoc($tq))
{
echo ''.$tr['description'].'<br />';
}
$count++;
$nopass++;
echo $design2;
}
}
}
} //neg exception end
I want it to only do the bits inside $neg_count to only echo once for each product. As atm if there are 2 exceptions for product 1 it will show it twice, the $tr shows all exceptions products for the current product in the loop with a box. So once it's shown those for the current looped product i don't need to show them again.