[PHP] Re: problems with looping array

2001-12-03 Thread Fred

Strings in your sql query must be quoted.  Try this instead:

$result = mysql_query(SELECT * FROM ar
LEFT JOIN company on ar.company_id=company.company_id
LEFT JOIN scale on ar.scale_id=scale.scale_id
WHERE item_number = \$item[$index]\);

Fred

Jordan [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 here's the situation.  I'm making a shopping cart, when an item is added
 it's item number is added into an array.  I then want this array's items
to
 be compared agains the database.  Unfortunately I haven't been able to use
a
 variable in the query string of MySQL.  something along the lines of


 ?PHP

include ('connect.php');

$result = mysql_query(SELECT * FROM ar
LEFT JOIN company on ar.company_id=company.company_id
LEFT JOIN scale on ar.scale_id=scale.scale_id
WHERE item_number = . $item[$index]);

 ?

 where $item is the array of item numbers and $index is an auto
incrementing
 number that increments at the end of the loop.  Please help if you know of
 anyway to use this variable.  Also, I can post my whole script if
needed...I
 just didn't want unneeded info posted.  Thanks in advance.

 -Jordan





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: problems with looping array

2001-12-03 Thread Jordan

I tried but nothing different happened.  I'm still playing though and I'll
see if I can make it work.  I'm new to all of this...so we'll see how it
goes.  Thanks for your help.

-jordan


Fred [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Strings in your sql query must be quoted.  Try this instead:

 $result = mysql_query(SELECT * FROM ar
 LEFT JOIN company on ar.company_id=company.company_id
 LEFT JOIN scale on ar.scale_id=scale.scale_id
 WHERE item_number = \$item[$index]\);

 Fred

 Jordan [EMAIL PROTECTED] wrote in message
 [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
  here's the situation.  I'm making a shopping cart, when an item is added
  it's item number is added into an array.  I then want this array's items
 to
  be compared agains the database.  Unfortunately I haven't been able to
use
 a
  variable in the query string of MySQL.  something along the lines of
 
 
  ?PHP
 
 include ('connect.php');
 
 $result = mysql_query(SELECT * FROM ar
 LEFT JOIN company on ar.company_id=company.company_id
 LEFT JOIN scale on ar.scale_id=scale.scale_id
 WHERE item_number = . $item[$index]);
 
  ?
 
  where $item is the array of item numbers and $index is an auto
 incrementing
  number that increments at the end of the loop.  Please help if you know
of
  anyway to use this variable.  Also, I can post my whole script if
 needed...I
  just didn't want unneeded info posted.  Thanks in advance.
 
  -Jordan
 
 





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: problems with looping array

2001-12-03 Thread Jim Musil


First, make sure $item[$index] has anything in it by inserting an 
echo $item[$index].

You also have to prepend item_number with the table name as in ar.item_number.

Try single quotes around $item[$index], too.

If $index is a name, I've had trouble in the past getting associative 
arrays to resolve correctly inside strings. Try using this ...

 $result = mysql_query(SELECT * FROM ar
LEFT JOIN company on ar.company_id=company.company_id
LEFT JOIN scale on ar.scale_id=scale.scale_id
WHERE ar.item_number = '.$item[$index].');


I tried but nothing different happened.  I'm still playing though and I'll
see if I can make it work.  I'm new to all of this...so we'll see how it
goes.  Thanks for your help.

-jordan


Fred [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
  Strings in your sql query must be quoted.  Try this instead:

  $result = mysql_query(SELECT * FROM ar
  LEFT JOIN company on ar.company_id=company.company_id
  LEFT JOIN scale on ar.scale_id=scale.scale_id
  WHERE item_number = \$item[$index]\);

  Fred

  Jordan [EMAIL PROTECTED] wrote in message
  [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
   here's the situation.  I'm making a shopping cart, when an item is added
   it's item number is added into an array.  I then want this array's items
  to
   be compared agains the database.  Unfortunately I haven't been able to
use
  a
   variable in the query string of MySQL.  something along the lines of
  
  
   ?PHP
  
  include ('connect.php');
  
  $result = mysql_query(SELECT * FROM ar
  LEFT JOIN company on ar.company_id=company.company_id
  LEFT JOIN scale on ar.scale_id=scale.scale_id
  WHERE item_number = . $item[$index]);
  
   ?
  
   where $item is the array of item numbers and $index is an auto
  incrementing
   number that increments at the end of the loop.  Please help if you know
of
   anyway to use this variable.  Also, I can post my whole script if
  needed...I
   just didn't want unneeded info posted.  Thanks in advance.
  
   -Jordan
  
  





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
Jim Musil
-
Multimedia Programmer
Nettmedia
-
212-629-0004
[EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]