Syntax help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kidney514
Forum Newbie
Posts: 8
Joined: Thu Oct 30, 2008 12:35 am

Syntax help!

Post 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.....
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Syntax help!

Post 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. :)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
kidney514
Forum Newbie
Posts: 8
Joined: Thu Oct 30, 2008 12:35 am

Re: Syntax help!

Post 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
User avatar
Syntac
Forum Contributor
Posts: 327
Joined: Sun Sep 14, 2008 7:59 pm

Re: Syntax help!

Post by Syntac »

Should be:

Code: Select all

if (count($products)=1) {
Conditions must always be encased in parentheses.
kidney514
Forum Newbie
Posts: 8
Joined: Thu Oct 30, 2008 12:35 am

Re: Syntax help!

Post by kidney514 »

Thanks will test it
kidney514
Forum Newbie
Posts: 8
Joined: Thu Oct 30, 2008 12:35 am

Re: Syntax help!

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Syntax help!

Post 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) {
kidney514
Forum Newbie
Posts: 8
Joined: Thu Oct 30, 2008 12:35 am

Re: Syntax help!

Post 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
kidney514
Forum Newbie
Posts: 8
Joined: Thu Oct 30, 2008 12:35 am

Re: Syntax help!

Post 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!
kidney514
Forum Newbie
Posts: 8
Joined: Thu Oct 30, 2008 12:35 am

Re: Syntax help!

Post 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....
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Syntax help!

Post 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.
kidney514
Forum Newbie
Posts: 8
Joined: Thu Oct 30, 2008 12:35 am

Re: Syntax help!

Post by kidney514 »

Wasnt the plan, I just made a mistake... Nothing else, but thanks for pointing it out.......
Post Reply