Member Avatar for mehnihma

in the string XX is always changed and string can be longer or shorter and it can be without searched word, where XX is a number example:

1 kom. nije naručeno, obično dolazi za 5 dana., slični: sony-6am6ptb1a (0 kom.), sony-s006pb1a (-9 kom.)
So from that I need to output just: obično dolazi za 5 dana

So how can I chose just &find in any case?

my example that does not work:

foreach(int intIndex = 1; intIndex <= 31; intIndex++)
                        {
                            $find_kad = "obično dolazi za " . strval(intIndex) . " dana."
                            $find_kad_eng = "usually comes in " . strval(intIndex) . " days."

                            if (strpos($availability,$find_kad) !== false) 
                            {
                            //echo '$string contains $find';
                            $dostupno_je="Po narudžbi  ".$find_kad;
                            $dostupno_je_eng="On order it  ".$find_kad_eng;

                            mysql_query("UPDATE ps_stock_available SET out_of_stock=1 WHERE id_product = $ztoro_id_product");

                            mysql_query("UPDATE ps_product_lang SET available_later="$dostupno_je" WHERE id_product = $ztoro_id_product AND id_lang=1");

                            mysql_query("UPDATE ps_product_lang SET available_later="$dostupno_je_eng" WHERE id_product = $ztoro_id_product AND id_lang=6");


                            }
                            else{
                                // just write not avaiable
                                $find_kad= "NIJE DOSTUPNO":

                            }
                        }

I get error on frist line:

Parse error: syntax error, unexpected T_STRING in script.php on line 618

Recommended Answers

All 3 Replies

Member Avatar for diafol

I'm slightly confused. You shouldn't store the complete string in the field, just the num_of_days. Let php build the phrase once a language has been chosen by the user.

e.g.

if($lang == 'en'){
    echo ".en." . $num_of_days . ".en.";
}else{
    echo ".cy." . $num_of_days . ".cy.";
}

I wouldn't do this for every instance of language string though. Using string arrays in a language file would be a better option.

Member Avatar for mehnihma

There is no user input, this is to update database

Member Avatar for diafol

Regardless, I'm not sure if this is the best way to store language strings. You're mixing the value (say '5') with the associated language string. THis may make the string unwieldy and difficult to update.

For each product, in the products table, I'd have the value in its own field, e.g. 'available_in' storing just integers

If you're storing language strings in the ps_product_lang table, it would benefit from have a generic statement that could be used for all products using a placeholder, e.g.

translations

translated_id (int/PK)
langstring_id (int/FK)
lang_id (tinyint/FK)
content (varchar or text)

1
5
4
Bydd y cynnyrch hwn ar gael ymhen %d diwrnod.

This would be related to a couple of tables:

langstrings

langstring_id (int/PK)
linkcode (varchar[30])
original (varchar or text)

5
PRODUCT_AVAILABLE_IN
This will be available in %d days.

langs

lang_id (tinyint/PK)
lang_code (varchar [10])
lang_encoding (varchar [10])
default_lang_name (varchar [15])
native_lang_name (varchar [15])

4
cy_gb
utf8
Welsh
Cymraeg

Using sprintf(), you can substitute the placeholder for a real value. This can be done easily enough with a join query and some php formatting.

I apologise if I went off track and didn't actually anser your question or if I misunderstood what you're trying to do. It's just that your data structure looks awkward. Feel free to ignore this post.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.