Page 1 of 1

Syntax help!

Posted: Thu Oct 30, 2008 12:39 am
by kidney514
Can't seem to get the syntax correctly can anyone assist me with this, would greatly appreciated.

here is the code..

Code: Select all

if (($step > 1) && (!$not_found)) {
    $products = tep_db_fetch_array($products_query)
    if count($products)=1 {
      $product_array = array('id' => $products['products_id'],                 'text' => $products['products_name'] . ' (' . $products['products_model'] . ')' . ': ' . $currencies->format($products['products_price'], true, $order->info['currency'], $order->info['currency_value'])); 
    } else {
  $product_array = array(array('id' => 0, 'text' => TEXT_SELECT_PRODUCT));
  while($products = tep_db_fetch_array($products_query)) {
    $product_array[] = array('id' => $products['products_id'],                 'text' => $products['products_name'] . ' (' . $products['products_model'] . ')' . ': ' . $currencies->format($products['products_price'], true, $order->info['currency'], $order->info['currency_value']));
  }
}
 
This is probably one of many questions to come, since I am no where near to be a programmer or coders, but I enjoy this so much, I just can't stay away from it LOL
Anyways any help is more that welcome.....

Re: Syntax help!

Posted: Thu Oct 30, 2008 1:28 am
by s.dot
Need a ; after $products = tep_db_fetch_array($products_query)

Would be more helpful next time if you could post the syntax error message you are receiving. :)

Re: Syntax help!

Posted: Thu Oct 30, 2008 7:20 am
by kidney514
Thanks and will do so in the future....

New code:

Code: Select all

 
 if (($step > 1) && (!$not_found)) {
    $products = tep_db_fetch_array($products_query);
    if count($products)=1 {
      $product_array = array('id' => $products['products_id'],                 'text' => $products['products_name'] . ' (' . $products['products_model'] . ')' . ': ' . $currencies->format($products['products_price'], true, $order->info['currency'], $order->info['currency_value'])); 
    } else {
  $product_array = array(array('id' => 0, 'text' => TEXT_SELECT_PRODUCT));
  while($products = tep_db_fetch_array($products_query)) {
    $product_array[] = array('id' => $products['products_id'],                 'text' => $products['products_name'] . ' (' . $products['products_model'] . ')' . ': ' . $currencies->format($products['products_price'], true, $order->info['currency'], $order->info['currency_value']));
  }
 }
 
That gives me that error now
"Parse error: syntax error, unexpected T_STRING, expecting '(' in /home/hsmmqs/public_html/catalog/admin/edit_orders_add_product.php on line 247"
line 247 = line 4

Re: Syntax help!

Posted: Thu Oct 30, 2008 2:16 pm
by Syntac
Should be:

Code: Select all

if (count($products)=1) {
Conditions must always be encased in parentheses.

Re: Syntax help!

Posted: Thu Oct 30, 2008 2:57 pm
by kidney514
Thanks will test it

Re: Syntax help!

Posted: Thu Oct 30, 2008 3:02 pm
by kidney514
NOw i'm getting this:

Fatal error: Can't use function return value in write context in .../edit_orders_add_product.php on line 247

Re: Syntax help!

Posted: Thu Oct 30, 2008 3:23 pm
by requinix
There were two problems with that line: the parentheses and the =.

= is for assignment. == is for comparison.

Code: Select all

if (count($products)==1) {

Re: Syntax help!

Posted: Thu Oct 30, 2008 4:05 pm
by kidney514
Regardless of what I put == or =

Here is the code:

Code: Select all

 
if (($step > 1) && (!$not_found)) {
    $products = tep_db_fetch_array($products_query)
    if (count($products)=1) {
      $product_array = array('id' => $products['products_id'],                 'text' => $products['products_name'] . ' (' . $products['products_model'] . ')' . ': ' . $currencies->format($products['products_price'], true, $order->info['currency'], $order->info['currency_value'])); 
    } else {
  $product_array = array(array('id' => 0, 'text' => TEXT_SELECT_PRODUCT));
  while($products = tep_db_fetch_array($products_query)) {
    $product_array[] = array('id' => $products['products_id'],                 'text' => $products['products_name'] . ' (' . $products['products_model'] . ')' . ': ' . $currencies->format($products['products_price'], true, $order->info['currency'], $order->info['currency_value']));
 }
}
 
Still give me this error:
syntax error, unexpected T_IF in

Re: Syntax help!

Posted: Thu Oct 30, 2008 4:09 pm
by kidney514
Maybe I should explain what I was hoping to achieve with that code.
Basically if there is only one result from the search I want it to be selected right away
and if there is more than one results I want my popup that there!

Re: Syntax help!

Posted: Thu Oct 30, 2008 4:19 pm
by kidney514
Actually, thinking about this might asswell submit the form since they will be nothing to do!

Code: Select all

 
    if (isset($_POST['add_product_options'])) {
      foreach($_POST['add_product_options'] as $option_id => $option_value_id) {
        echo '<input type="hidden" name="add_product_options['.$option_id.']" value="' . $option_value_id . '">';
      }
    }
    echo '<input type="hidden" name="add_product_categories_id" value="' . $add_product_categories_id . '"><input type="hidden" name="add_product_products_id" value="' . $add_product_products_id . '"><input type="hidden" name="step" value="5"></td>' . "\n" .
         '          </tr>' . "\n" .
         '          </form>' . "\n";
  }
 
I think this the section that submits the result to the invoice not sure....

Re: Syntax help!

Posted: Thu Oct 30, 2008 4:45 pm
by requinix
kidney514 wrote:Still give me this error:
syntax error, unexpected T_IF in
Kinda frustrating when the code you post changes...
This time you deleted a semicolon from the line before the if. It was there before but isn't now.

Re: Syntax help!

Posted: Thu Oct 30, 2008 4:50 pm
by kidney514
Wasnt the plan, I just made a mistake... Nothing else, but thanks for pointing it out.......