Forum Moderators: coopster
i have a database table with a filed called product_addon which will on occasion have a 'Y' in the field
this code will display the "Y" if it exists
<?php
$db->p("product_addon");
?>
this is what i am trying to use to make 'Y' show different results
<?php
if ( $product_addon === "Y" )
{
echo "this and that";
}
else
{
echo "the other thing";
}
?>
so far all i can get this to do is show 'the other thing' whne the 'Y' is present
any ideas on how to get this to work?
many thanks
$product_addon before the if conditional. My guess is that you aren't even setting this variable. In above function call you said that it will display Y if it exists, not set the variable. Just make sure that the variable is being set first, is all ;) Best of luck!
Here's a good link: Comparison operators [us2.php.net].
iggy99,
If this doesn't work then there is a problem: ;)
$product_addon = "Y";
if($product_addon == "Y")
{
echo "this and that";
} else {
echo "the other thing";
}
Now, this is not what you are going to have when you are ready to impement the function you have that returns this value. Instead of having this static product_addon variable declared here you are going to return it.
[url=http://us3.php.net/manual/en/language.functions.php]function[/url] p($field) {
$link = [url=http://us3.php.net/manual/en/function.mysql-connect.php]mysql_connect[/url]("localhost","username","password");
[url=http://us3.php.net/manual/en/function.mysql-select-db.php]mysql_select_db[/url]("database");
$query = "SELECT ".$field." FROM product WHERE some_col = 'something'";
/*
In the previous line I'm assuming that you are only retrieving one row in which case you need to limit it somehow, possibly using unique id's
*/
$result = [url=http://us3.php.net/manual/en/function.mysql-query.php]mysql_query[/url]($query,$link) or [url=http://us3.php.net/manual/en/function.die.php]die[/url]([url=http://us3.php.net/manual/en/function.mysql-error.php]mysql_error[/url]());
if($result) {
$row = [url=http://us3.php.net/manual/en/function.mysql-fetch-array.php]mysql_fetch_array[/url]($result);
[url=http://us3.php.net/manual/en/functions.returning-values.php]return[/url] $row[$field];
} else {
[url=http://us3.php.net/manual/en/functions.returning-values.php]return[/url] 0;
}
}
Then you would be able to do something like this:
//Here you would initiate $db to the correct class
$product_addon = $db->p("product_addon");
if($product_addon == FALSE) {
echo "An error has occurred";
}
else if($product_addon == "Y") {
echo "Found Y";
} else {
echo 'This and that';
}
I hope this makes some sense. We'll see when you respond ;)
Although you may not need any of the resources I linked to, it just gives me something to do when there isn't a lot of action around WW ;)
seems we are already connection to the database -
this page is called product.php
this is on the top and i think this is how data from table 'products' is being pulled into the page
<?php
eval(load_class("product", "ps_product"));
$ps_product = new ps_product;
eval(load_class("product", "ps_product_category"));
$ps_product_category = new ps_product_category;
eval(load_class("product", "ps_product_attribute"));
$ps_product_attribute = new ps_product_attribute;
?>
i have noticed this before a tag that is pulling data...
<?php
if (!$ps_product->is_product($product_id)) {
$product_id = $ps_product->get_field($product_id, "product_parent_id");
}
$q = "SELECT * FROM product WHERE ";
$q .= "product_id='$product_id'";
$db->query($q);
$db->next_record();
?>
then this which displays the actual data
<?php
$db->p("product_name");
?>
<?php
$q = "SELECT * FROM product WHERE ";
$q .= "product_id='$product_id'";
$db->query($q);
$db->next_record();
$num=1;
$qt="quantity";
$qt .=$num;
$pa="product_id";
$or="order";
$or .=$xo_num;
?>
so i am of course confused :)
not sure how to get this variable out of the filed product_addon for any given product id
thoughts?