Re: [PHP] Help me learn! with an explanation of these two functions.

2002-11-07 Thread Jason Wong
On Thursday 07 November 2002 15:15, Steve Jackson wrote:
 My second query still doesn't return anything? Even with $orderid = $row
 removed as Jason suggested.

What exactly do you mean by doesn't return anything?

a) Does the second query fail?
b) Do you get any errors?

If no to both (a) and (b) then your query succeeded.

Now, your code below as-is does not do anything with the 2nd query results. 
You've only used extract() on it, which by itself is not much use, unless you 
use the variables that has been extracted. Read my previous post about what 
extract() does (and read the manual for heaven's sake)

Also make liberal use of print_r() to see what values your variables contain 
at different stages of your program.

 This is my current function.


 function get_order_numbers()
 {
 $conn = db_connect();
 $query = select orders.orderid from orders, email where orders.orderid
 = email.orderid and email.checked='no';
 $result = mysql_query($query) or die(Error: cannot select
 orderidBR$queryBR.mysql_error());
 while( $row = mysql_fetch_array($result))
   {
   extract($row);
   //$orderid = $row;
   print_r($row);
   $query2 = SELECT * FROM orders WHERE orderid=\$orderid\;
   $result2 = mysql_query($query2) or die(Error: cannot fetch
 orderBR$query2BR.mysql_error());
   extract(mysql_fetch_array($result2));
   }
 }

-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
One Bell System - it works.
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Help me learn! with an explanation of these two functions.

2002-11-07 Thread Steve Jackson
Finally I have it!
Cheers to all that helped. I was querying twice when I didn't need to
and as Jason said not doing anything with the extracted information.
This code works and displays data nicely.
function get_order_numbers()
{
$conn = db_connect();
$query = select * from orders, email where orders.orderid =
email.orderid and email.checked='no';
$result = mysql_query($query) or die(Error: cannot select
orderidBR$queryBR.mysql_error());
while( $row = mysql_fetch_array($result))
  {
extract($row);
if (is_array($row))
//print_r($row);
{
//echo tests and ; 
echo $row[orderid];
echo $row[ship_name];
}

  }
}

Steve Jackson
Web Developer
Viola Systems Ltd.
http://www.violasystems.com
[EMAIL PROTECTED]
Mobile +358 50 343 5159



 -Original Message-
 From: Jason Wong [mailto:php-general;gremlins.com.hk] 
 Sent: 7. marraskuuta 2002 10:06
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP] Help me learn! with an explanation of 
 these two functions.
 
 
 On Thursday 07 November 2002 15:15, Steve Jackson wrote:
  My second query still doesn't return anything? Even with $orderid = 
  $row removed as Jason suggested.
 
 What exactly do you mean by doesn't return anything?
 
 a) Does the second query fail?
 b) Do you get any errors?
 
 If no to both (a) and (b) then your query succeeded.
 
 Now, your code below as-is does not do anything with the 2nd 
 query results. 
 You've only used extract() on it, which by itself is not much 
 use, unless you 
 use the variables that has been extracted. Read my previous 
 post about what 
 extract() does (and read the manual for heaven's sake)
 
 Also make liberal use of print_r() to see what values your 
 variables contain 
 at different stages of your program.
 
  This is my current function.
 
 
  function get_order_numbers()
  {
  $conn = db_connect();
  $query = select orders.orderid from orders, email where 
  orders.orderid = email.orderid and email.checked='no'; $result = 
  mysql_query($query) or die(Error: cannot select 
  orderidBR$queryBR.mysql_error());
  while( $row = mysql_fetch_array($result))
  {
  extract($row);
  //$orderid = $row;
  print_r($row);
  $query2 = SELECT * FROM orders WHERE orderid=\$orderid\;
$result2 = mysql_query($query2) or die(Error: cannot fetch 
  orderBR$query2BR.mysql_error());
extract(mysql_fetch_array($result2));
  }
  }
 
 -- 
 Jason Wong - Gremlins Associates - www.gremlins.com.hk
 Open Source Software Systems Integrators
 * Web Design  Hosting * Internet  Intranet Applications 
 Development *
 
 /*
 One Bell System - it works.
 */
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Help me learn! with an explanation of these two functions.

2002-11-07 Thread Jason Wong
On Thursday 07 November 2002 16:28, Steve Jackson wrote:
 Finally I have it!

sigh if this is your final code then you still don't have it !

 Cheers to all that helped. I was querying twice when I didn't need to
 and as Jason said not doing anything with the extracted information.

   extract($row);
You're still not gaining anything by using extract() ...

   if (is_array($row))
   //print_r($row);
   {
   //echo tests and ;
   echo $row[orderid];
   echo $row[ship_name];

... the whole point of using extract() is that instead of using 

  echo $row['orderid'];

you could simply use:

  echo $orderid;

-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
Don't feed the bats tonight.
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Help me learn! with an explanation of these two functions.

2002-11-07 Thread Steve Jackson
Of course you are correct.
I forgot to remove the $row[orderid] etc.. 

I was just testing the function and thought I'd post the code rather
than waste someones time answering me.
However thanks for the help. Much appreciated.

Steve Jackson
Web Developer
Viola Systems Ltd.
http://www.violasystems.com
[EMAIL PROTECTED]
Mobile +358 50 343 5159



 -Original Message-
 From: Jason Wong [mailto:php-general;gremlins.com.hk] 
 Sent: 7. marraskuuta 2002 11:51
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP] Help me learn! with an explanation of 
 these two functions.
 
 
 On Thursday 07 November 2002 16:28, Steve Jackson wrote:
  Finally I have it!
 
 sigh if this is your final code then you still don't have it !
 
  Cheers to all that helped. I was querying twice when I 
 didn't need to 
  and as Jason said not doing anything with the extracted information.
 
  extract($row);
 You're still not gaining anything by using extract() ...
 
  if (is_array($row))
  //print_r($row);
  {
  //echo tests and ;
  echo $row[orderid];
  echo $row[ship_name];
 
 ... the whole point of using extract() is that instead of using 
 
   echo $row['orderid'];
 
 you could simply use:
 
   echo $orderid;
 
 -- 
 Jason Wong - Gremlins Associates - www.gremlins.com.hk
 Open Source Software Systems Integrators
 * Web Design  Hosting * Internet  Intranet Applications 
 Development *
 
 /*
 Don't feed the bats tonight.
 */
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Help me learn! with an explanation of these two functions.

2002-11-06 Thread Steve Jackson

Ok this is starting to get complex! (For me anyway)
This is my function:
function get_order_numbers()
{
$conn = db_connect();
$query = select orders.orderid from orders, email where orders.orderid
= email.orderid and email.checked='no';
$result = mysql_query($query) or die(Error: cannot select
orderidBR$queryBR.mysql_error());
while( $row = mysql_fetch_array($result))
{
extract($row);
$orderid = $row;
$query2 = SELECT * FROM orders WHERE orderid=\$orderid\;
$result2 = mysql_query($query2) or die(Error: cannot fetch
orderBR$query2BR.mysql_error());
extract(mysql_fetch_array($result2));
}
}


The SQL works Ok. At least I get no errors now.
It's my PHP to display the SQL I think I get a result of 8 errors with
the following message.
Warning: Wrong datatype in call to extract() in
/www/u1255/eadmin/eshop_fns.php on line 40.
Where line 40 is:
extract(mysql_fetch_array($result2));

I am trying to display the message on another page using:
? include ('eshop_fns.php');
get_order_numbers(); 
$ship_name = $result2[ship_name];
echo tests and $ship_name; ?


What does extract do? I am under the assumption it extracts row
information so why a datatype error?
Any pointers?


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Help me learn! with an explanation of these two functions.

2002-11-06 Thread Ernest E Vogelsinger
At 09:52 06.11.2002, Steve Jackson said:
[snip]
function get_order_numbers()
{
$conn = db_connect();
$query = select orders.orderid from orders, email where orders.orderid
= email.orderid and email.checked='no';
$result = mysql_query($query) or die(Error: cannot select
orderidBR$queryBR.mysql_error());
while( $row = mysql_fetch_array($result))
   {
   extract($row);
   $orderid = $row;
   $query2 = SELECT * FROM orders WHERE orderid=\$orderid\;
$result2 = mysql_query($query2) or die(Error: cannot fetch
orderBR$query2BR.mysql_error());
extract(mysql_fetch_array($result2));
   }
}


The SQL works Ok. At least I get no errors now.
It's my PHP to display the SQL I think I get a result of 8 errors with
the following message.
Warning: Wrong datatype in call to extract() in
/www/u1255/eadmin/eshop_fns.php on line 40.
Where line 40 is:
extract(mysql_fetch_array($result2));

Steve,

maybe the second fetch doesn't return anything because the resultset is
empty? You should assign the second fetch to a variable and test it before
passing it to extract (as with the first fetch):

$row2 = mysql_fetch_array($result2);
if (is_array($row2)) {
extract($row2);
// ...
}

What does extract do? I am under the assumption it extracts row
information so why a datatype error?
Any pointers?

--- [doc] ---
int extract ( array var_array [, int extract_type [, string prefix]])

This function is used to import variables from an array into the current
symbol table. It takes an associative array var_array and treats keys as
variable names and values as variable values. For each key/value pair it
will create a variable in the current symbol table, subject to extract_type
and prefix parameters. 
--- [/doc] --

May I suggest getting the Camel Book, or at least consult the EXCELLENT
online PHP manual at http://www.php.net/manual/en/. If you read about
mysql_fetch_array you'll notice the additional optional parameter
result_type. Since you're going to pass the resulting data to extract it
helps to specify MYSQL_ASSOC as result_type, this will omit the numerically
indexed data from the fetched array, which isn't used by extract() anyway.


-- 
   O Ernest E. Vogelsinger
   (\)ICQ #13394035
^ http://www.vogelsinger.at/




Re: [PHP] Help me learn! with an explanation of these two functions.

2002-11-06 Thread Jason Wong
On Wednesday 06 November 2002 16:52, Steve Jackson wrote:
 Ok this is starting to get complex! (For me anyway)
 This is my function:
 function get_order_numbers()
 {
 $conn = db_connect();
 $query = select orders.orderid from orders, email where orders.orderid
 = email.orderid and email.checked='no';
 $result = mysql_query($query) or die(Error: cannot select
 orderidBR$queryBR.mysql_error());
 while( $row = mysql_fetch_array($result))
   {
   extract($row);

According to your query it should return a single result (assuming your 
orderid is unique -- and it should be), and that single result contains a 
single field called orderid.

Use print_r($row) to see exactly what it contains (good for reference and 
debugging).

extract($row) would assign to $orderid the value of $row['orderid'] (ie 
$orderid = $row['orderid']) ...

   $orderid = $row;

... thus, I don't know why you have this line here. Remove it.

   $query2 = SELECT * FROM orders WHERE orderid=\$orderid\;

This fails because $row is an array and you assigned that to $orderid.

 What does extract do? I am under the assumption it extracts row
 information so why a datatype error?

rtfm for details and examples.

-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
Take that, you hostile sons-of-bitches!
-- James Coburn, in the finale of _The_President's_Analyst_
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Help me learn! with an explanation of these two functions.

2002-11-06 Thread Steve Jackson
 On Wednesday 06 November 2002 16:52, Steve Jackson wrote:
  Ok this is starting to get complex! (For me anyway)
  This is my function:
  function get_order_numbers()
  {
  $conn = db_connect();
  $query = select orders.orderid from orders, email where 
  orders.orderid = email.orderid and email.checked='no'; $result = 
  mysql_query($query) or die(Error: cannot select 
  orderidBR$queryBR.mysql_error());
  while( $row = mysql_fetch_array($result))
  {
  extract($row);
 
 According to your query it should return a single result 
 (assuming your 
 orderid is unique -- and it should be), and that single 
 result contains a 
 single field called orderid.
 
 Use print_r($row) to see exactly what it contains (good for 
 reference and 
 debugging).


It doesn't contain a single result. It returns 16 order numbers (which
is correct - 8 should be in the table emails with no checked and
therefore the query has worked and pulled out 8 from the orders table
also). What I want the function to do is say OK where the orderid's
match pull out all the address details for each orderid and display what
I want displayed accordingly. At the moment I get this array returned by
using print_r($row).
Array ( [0] = 100040 [orderid] = 100040 ) Array ( [0] = 100041
[orderid] = 100041 ) Array ( [0] = 100043 [orderid] = 100043 ) Array
( [0] = 100044 [orderid] = 100044 ) Array ( [0] = 100046 [orderid] =
100046 ) Array ( [0] = 100050 [orderid] = 100050 ) Array ( [0] =
100051 [orderid] = 100051 ) Array ( [0] = 100052 [orderid] = 100052 )

Where do I go from here?


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Help me learn! with an explanation of these two functions.

2002-11-06 Thread Jason Wong
On Wednesday 06 November 2002 21:46, Steve Jackson wrote:

 It doesn't contain a single result. It returns 16 order numbers (which
 is correct - 8 should be in the table emails with no checked and
 therefore the query has worked and pulled out 8 from the orders table
 also). What I want the function to do is say OK where the orderid's
 match pull out all the address details for each orderid and display what
 I want displayed accordingly. At the moment I get this array returned by
 using print_r($row).
 Array ( [0] = 100040 [orderid] = 100040 ) Array ( [0] = 100041
 [orderid] = 100041 ) Array ( [0] = 100043 [orderid] = 100043 ) Array
 ( [0] = 100044 [orderid] = 100044 ) Array ( [0] = 100046 [orderid] =
 100046 ) Array ( [0] = 100050 [orderid] = 100050 ) Array ( [0] =
 100051 [orderid] = 100051 ) Array ( [0] = 100052 [orderid] = 100052 )

 Where do I go from here?

Well, like I said in my previous post if you remove the line:

  $orderid = $row;

then your second query *should* work.

-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
New members are urgently needed in the Society for Prevention of
Cruelty to Yourself.  Apply within.
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Help me learn! with an explanation of these two functions.

2002-11-06 Thread Steve Jackson
My second query still doesn't return anything? Even with $orderid = $row
removed as Jason suggested.
This is my current function.


function get_order_numbers()
{
$conn = db_connect();
$query = select orders.orderid from orders, email where orders.orderid
= email.orderid and email.checked='no';
$result = mysql_query($query) or die(Error: cannot select
orderidBR$queryBR.mysql_error());
while( $row = mysql_fetch_array($result))
{
extract($row);
//$orderid = $row;
print_r($row);
$query2 = SELECT * FROM orders WHERE orderid=\$orderid\;
  $result2 = mysql_query($query2) or die(Error: cannot fetch
orderBR$query2BR.mysql_error());
  extract(mysql_fetch_array($result2));
}
}



  What I want the function to do is say OK where the orderid's 
  match pull out all the address details for each orderid and display 
  what I want displayed accordingly. At the moment I get this array 
  returned by using print_r($row). Array ( [0] = 100040 [orderid] = 
  100040 ) Array ( [0] = 100041 [orderid] = 100041 ) Array ( [0] = 
  100043 [orderid] = 100043 ) Array ( [0] = 100044 
 [orderid] = 100044 
  ) Array ( [0] = 100046 [orderid] = 100046 ) Array ( [0] = 100050 
  [orderid] = 100050 ) Array ( [0] = 100051 [orderid] = 100051 ) 
  Array ( [0] = 100052 [orderid] = 100052 )
 
  Where do I go from here?
 
 Well, like I said in my previous post if you remove the line:
 
   $orderid = $row;
 
 then your second query *should* work.
 
 -- 
 Jason Wong - Gremlins Associates - www.gremlins.com.hk
 Open Source Software Systems Integrators
 * Web Design  Hosting * Internet  Intranet Applications 
 Development *




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Help me learn! with an explanation of these two functions.

2002-11-05 Thread Steve Jackson
Can someone run over these functions I have written to explain if my
logic is correct.
I'm still new to PHP and am trying to get my head round it!
This first function is to collect a list of order numbers from my
database where checked = no.
Am I correct in assuming that the variable $orderid will be an array of
results returned? How can I check this?

function get_live_orders()
{
$conn = db_connect();
$query = select orderid from email where checked='no';
$result = @mysql_query($query);
if(mysql_numrows($result)0)
$orderid = @mysql_fetch_array($result);
return $orderid;
}

This second function is to take these order numbers and compare them to
order numbers in a second table and return the result of that. So if
order number 11 is in the first array from the above function and
there is a number 11 in the second query result I want to take all
the data in that row and return it.

function get_order_details()
{
$orderid = get_live_orders();
$conn = db_connect();
$query = select * from orders where orderid='$orderid';
$result = @mysql_query($query);
if (!$result)
 return false;
   $result = mysql_result($result, 0, orderid);
   return $result;
}

I haven't actually run this yet but I'd like someone to explain to me
what these functions will do so I am not just copy pasting code and
hoping to get it right eventually! Probably I have written this wrong
anyway and would like help before I actually attempt to do what I am
after.
I'll look back on this tomorrow so any help will be greatly appreciated.
Kind regards,
Steve Jackson
Web Developer
Viola Systems Ltd.
http://www.violasystems.com
[EMAIL PROTECTED]
Mobile +358 50 343 5159


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Help me learn! with an explanation of these two functions.

2002-11-05 Thread Rick Emery
$orderid WILL NOT contain all the rows.  mysql_fetch_array() returns only one row each
time it is called.  Upon fetching last row, it returns NULL/FALSE/0.  Therefore, as you
fetch each row, you will then execute your second function to pull all the data for 
that
particular order number.  Finally, when executing mysql_query(), ALWAYS execute it in
conjuction with die(mysql_error()) in order to get error messages concerning failures.
Execute mysql_connect() and mysql_db_connect() only ONCE per script.

function get_live_orders()
{

$query = select orderid from email where checked='no';
$result = mysql_query($query) or die(Error: cannot select
orderidBR$queryBR.mysql_error());
while( $row = mysql_fetch_array($result))
{
extract($row);
$query2 = SELECT * FROM orders WHERE orderid=\$orderid\;
$result2 = mysql_query()) or die(Error: cannot fetch
orderBR$query2BR.mysql_error());
extract(mysql_fetch_array($result2));
}


- Original Message -
From: Steve Jackson [EMAIL PROTECTED]
To: PHP General [EMAIL PROTECTED]
Sent: Tuesday, November 05, 2002 8:50 AM
Subject: [PHP] Help me learn! with an explanation of these two functions.


Can someone run over these functions I have written to explain if my
logic is correct.
I'm still new to PHP and am trying to get my head round it!
This first function is to collect a list of order numbers from my
database where checked = no.
Am I correct in assuming that the variable $orderid will be an array of
results returned? How can I check this?

function get_live_orders()
{
$conn = db_connect();
$query = select orderid from email where checked='no';
$result = @mysql_query($query);
if(mysql_numrows($result)0)
$orderid = @mysql_fetch_array($result);
return $orderid;
}

This second function is to take these order numbers and compare them to
order numbers in a second table and return the result of that. So if
order number 11 is in the first array from the above function and
there is a number 11 in the second query result I want to take all
the data in that row and return it.

function get_order_details()
{
$orderid = get_live_orders();
$conn = db_connect();
$query = select * from orders where orderid='$orderid';
$result = @mysql_query($query);
if (!$result)
 return false;
   $result = mysql_result($result, 0, orderid);
   return $result;
}

I haven't actually run this yet but I'd like someone to explain to me
what these functions will do so I am not just copy pasting code and
hoping to get it right eventually! Probably I have written this wrong
anyway and would like help before I actually attempt to do what I am
after.
I'll look back on this tomorrow so any help will be greatly appreciated.
Kind regards,
Steve Jackson
Web Developer
Viola Systems Ltd.
http://www.violasystems.com
[EMAIL PROTECTED]
Mobile +358 50 343 5159


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Help me learn! with an explanation of these two functions.

2002-11-05 Thread 1LT John W. Holmes
Your first function is only going to return one row of 'checked=no' records.
The second function will only return one column of the result.

What you want is a JOIN. You can do all of this with a single query. Without
knowing the format of your tables exactly, I can't give you the syntax,
though.

Check the MySQL manual and read the chapter on JOINs.

---John Holmes...

- Original Message -
From: Steve Jackson [EMAIL PROTECTED]
To: PHP General [EMAIL PROTECTED]
Sent: Tuesday, November 05, 2002 9:50 AM
Subject: [PHP] Help me learn! with an explanation of these two functions.


 Can someone run over these functions I have written to explain if my
 logic is correct.
 I'm still new to PHP and am trying to get my head round it!
 This first function is to collect a list of order numbers from my
 database where checked = no.
 Am I correct in assuming that the variable $orderid will be an array of
 results returned? How can I check this?

 function get_live_orders()
 {
 $conn = db_connect();
 $query = select orderid from email where checked='no';
 $result = @mysql_query($query);
 if(mysql_numrows($result)0)
 $orderid = @mysql_fetch_array($result);
 return $orderid;
 }

 This second function is to take these order numbers and compare them to
 order numbers in a second table and return the result of that. So if
 order number 11 is in the first array from the above function and
 there is a number 11 in the second query result I want to take all
 the data in that row and return it.

 function get_order_details()
 {
 $orderid = get_live_orders();
 $conn = db_connect();
 $query = select * from orders where orderid='$orderid';
 $result = @mysql_query($query);
 if (!$result)
  return false;
$result = mysql_result($result, 0, orderid);
return $result;
 }

 I haven't actually run this yet but I'd like someone to explain to me
 what these functions will do so I am not just copy pasting code and
 hoping to get it right eventually! Probably I have written this wrong
 anyway and would like help before I actually attempt to do what I am
 after.
 I'll look back on this tomorrow so any help will be greatly appreciated.
 Kind regards,
 Steve Jackson
 Web Developer
 Viola Systems Ltd.
 http://www.violasystems.com
 [EMAIL PROTECTED]
 Mobile +358 50 343 5159


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Help me learn! with an explanation of these two functions.

2002-11-05 Thread Steve Jackson
Joins. Cool. Never heard of them before now but have started
experimenting with them.
What does this error mean?

Error: cannot select orderid
select orderid from orders, email where orders.orderid = email.orderid
and email.checked='no'
Column: 'orderid' in field list is ambiguous

My query function syntax is:

function get_order_numbers()
{
$conn = db_connect();
$query = select orderid from orders, email where orders.orderid =
email.orderid and email.checked='no';
$result = mysql_query($query) or die(Error: cannot select
orderidBR$queryBR.mysql_error());
while( $row = mysql_fetch_array($result))
{
extract($row);
$orderid = $row;
return $orderid;
}
}

What does it mean ambiguous? Cheeky error!

Steve Jackson
Web Developer
Viola Systems Ltd.
http://www.violasystems.com
[EMAIL PROTECTED]
Mobile +358 50 343 5159



 -Original Message-
 From: 1LT John W. Holmes [mailto:holmes072000;charter.net] 
 Sent: 5. marraskuuta 2002 16:59
 To: [EMAIL PROTECTED]; PHP General
 Subject: Re: [PHP] Help me learn! with an explanation of 
 these two functions.
 
 
 Your first function is only going to return one row of 
 'checked=no' records. The second function will only return 
 one column of the result.
 
 What you want is a JOIN. You can do all of this with a single 
 query. Without knowing the format of your tables exactly, I 
 can't give you the syntax, though.
 
 Check the MySQL manual and read the chapter on JOINs.
 
 ---John Holmes...
 
 - Original Message -
 From: Steve Jackson [EMAIL PROTECTED]
 To: PHP General [EMAIL PROTECTED]
 Sent: Tuesday, November 05, 2002 9:50 AM
 Subject: [PHP] Help me learn! with an explanation of these 
 two functions.
 
 
  Can someone run over these functions I have written to 
 explain if my 
  logic is correct. I'm still new to PHP and am trying to get my head 
  round it! This first function is to collect a list of order numbers 
  from my database where checked = no.
  Am I correct in assuming that the variable $orderid will be 
 an array of
  results returned? How can I check this?
 
  function get_live_orders()
  {
  $conn = db_connect();
  $query = select orderid from email where checked='no'; $result = 
  @mysql_query($query);
  if(mysql_numrows($result)0)
  $orderid = @mysql_fetch_array($result);
  return $orderid;
  }
 
  This second function is to take these order numbers and 
 compare them 
  to order numbers in a second table and return the result of 
 that. So 
  if order number 11 is in the first array from the above 
 function 
  and there is a number 11 in the second query result I 
 want to take 
  all the data in that row and return it.
 
  function get_order_details()
  {
  $orderid = get_live_orders();
  $conn = db_connect();
  $query = select * from orders where orderid='$orderid'; $result = 
  @mysql_query($query); if (!$result)
   return false;
 $result = mysql_result($result, 0, orderid);
 return $result;
  }
 
  I haven't actually run this yet but I'd like someone to 
 explain to me 
  what these functions will do so I am not just copy pasting code and 
  hoping to get it right eventually! Probably I have written 
 this wrong 
  anyway and would like help before I actually attempt to do 
 what I am 
  after. I'll look back on this tomorrow so any help will be greatly 
  appreciated. Kind regards,
  Steve Jackson
  Web Developer
  Viola Systems Ltd.
  http://www.violasystems.com
  [EMAIL PROTECTED]
  Mobile +358 50 343 5159
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Help me learn! with an explanation of these two functions.

2002-11-05 Thread Ernest E Vogelsinger
At 08:58 06.11.2002, Steve Jackson said:
[snip]
Joins. Cool. Never heard of them before now but have started
experimenting with them.
What does this error mean?

Error: cannot select orderid
select orderid from orders, email where orders.orderid = email.orderid
and email.checked='no'
Column: 'orderid' in field list is ambiguous
[snip] 

In this case both tables (order and email) have a column named orderid. The
select part pf your statement needs to specify the table name or alias
where the orderid field should be taken from:

select orders.orderid from orders, email where orders.orderid = email.orderid
and email.checked='no'


-- 
   O Ernest E. Vogelsinger
   (\)ICQ #13394035
^ http://www.vogelsinger.at/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php