The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Page 2 -
PHP-General - Cant get a select list working with joined table. HELP
Page 2 - Discuss Cant get a select list working with joined table. HELP in the PHP Development forum on Dev Shed. Cant get a select list working with joined table. HELP PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

October 3rd, 2012, 01:16 PM
|
|
Contributing User
|
|
Join Date: Sep 2012
Posts: 67
Time spent in forums: 15 h 54 m 55 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by gw1500se Nope. Use poochieProd.ProdID |
yes i tried that
<?php
$query2 = sprintf("
SELECT DISTINCT
stock.stockID, size.Size
FROM
poochieProd AS prod
LEFT JOIN poochieStock AS stock ON Prod.ID = stock.ID
LEFT JOIN poochieSizes AS size ON stock.SizeID = size.SizeID
WHERE
poochieProd.ProdID = '%s' AND stock.stock > 0
ORDER BY
size.SizeID ASC", GetSQLValueString($var3_Recordset1, "int"));
$results2 = mysql_query($query2);
while($row2 = mysql_fetch_array($results2)){
?>
and got the following error?
Error in query: SELECT DISTINCT stock.stockID, size.Size FROM poochieProd AS prod LEFT JOIN poochieStock AS stock ON Prod.ID = stock.ID LEFT JOIN poochieSizes AS size ON stock.SizeID = size.SizeID WHERE poochieProd.ProdID = '-1' AND stock.stock > 0 ORDER BY size.SizeID ASC. Unknown table 'poochieProd' in where clause
|

October 3rd, 2012, 01:17 PM
|
|
|
Quote: | Originally Posted by jonnyfreak i thought the poochieProd AS prod
was telling the next part to see poochieProd as prod so
WHERE prod.ProdID would see this? | That is correct, but the table "Prod" doesn't exist because you declared the table as "prod". It's case sensitive so you have to keep it in lowercase throughout the string.
|

October 3rd, 2012, 01:21 PM
|
|
Contributing User
|
|
Join Date: Sep 2012
Posts: 67
Time spent in forums: 15 h 54 m 55 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by SecurityDavid That is correct, but the table "Prod" doesn't exist because you declared the table as "prod". It's case sensitive so you have to keep it in lowercase throughout the string. |
i added the poochieProd.ProdID
and it returned
Unknown table 'poochieProd' in where clause
|

October 3rd, 2012, 01:31 PM
|
|
|
|
Post the output from 'show tables' on that database.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.
|

October 3rd, 2012, 01:34 PM
|
|
Contributing User
|
|
Join Date: Sep 2012
Posts: 67
Time spent in forums: 15 h 54 m 55 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by gw1500se Post the output from 'show tables' on that database. |
sorry how is that done?
thanks
|

October 3rd, 2012, 01:40 PM
|
|
|
|
The easiest way is to use the mysql command then type:
use <database name>;
show tables;
|

October 3rd, 2012, 01:52 PM
|
|
Contributing User
|
|
Join Date: Sep 2012
Posts: 67
Time spent in forums: 15 h 54 m 55 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by gw1500se The easiest way is to use the mysql command then type:
use <database name>;
show tables; |
just trying how to figure out how to do this
|

October 3rd, 2012, 01:57 PM
|
|
|
|
Are you on Windows or *NIX?
|

October 3rd, 2012, 01:58 PM
|
|
Contributing User
|
|
Join Date: Sep 2012
Posts: 67
Time spent in forums: 15 h 54 m 55 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by jonnyfreak just trying how to figure out how to do this |
can i do that from phpMyAdmin?
|

October 3rd, 2012, 02:04 PM
|
|
Contributing User
|
|
Join Date: Sep 2012
Posts: 67
Time spent in forums: 15 h 54 m 55 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by gw1500se Are you on Windows or *NIX? |
windows
|

October 3rd, 2012, 02:11 PM
|
|
|
|
Yes you can do that from PHPAdmin.
|

October 3rd, 2012, 02:18 PM
|
|
Contributing User
|
|
Join Date: Sep 2012
Posts: 67
Time spent in forums: 15 h 54 m 55 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by gw1500se Yes you can do that from PHPAdmin. |
i opened up the SQL box
Run SQL query
and typed
use <dbpoochie>;
show tables;
but it gave me
There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem
ERROR: Unknown Punctuation String @ 14
STR: >;
SQL: use <dbpoochie>;use <dbpoochie>;use <dbpoochie>;
SQL query:
use <dbpoochie>;
MySQL said:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<dbpoochie>' at line 1
|

October 3rd, 2012, 03:37 PM
|
|
Contributing User
|
|
Join Date: Sep 2012
Posts: 67
Time spent in forums: 15 h 54 m 55 sec
Reputation Power: 1
|
|
|
i have included all the values of the tables if that helps
Table name: poochieCat
CatID - int(11) - auto_increment
name - varchar(200)
image - varchar(200)
Table name: poochieProd
ProdID - int(11) - auto_increment
Prodname - varchar(200)
ProdDesc - text
CatID - varchar(80)
Table name: poochieSizes
SizeID - int(11) - auto_increment
Size - varchar(200)
Table name: poochieStock
stockID - int(11) - auto_increment
ProdID - varchar(80)
sizeID - varchar(80)
stock - varchar(30)
sold - varchar(10)
its that ok?
|

October 3rd, 2012, 04:09 PM
|
|
|
Quote: | Originally Posted by jonnyfreak i added the poochieProd.ProdID
and it returned
Unknown table 'poochieProd' in where clause | That's not what I said. Your statement declared the table "poochieProd AS prod" but then in your first join, you called your table "Prod" with a capital "P". If you declare your table as "prod" all in lower case, you need to call your table in all lower case every time, you can't change the case of your table name in the string. Also, once you've declared it as "prod" I believe you have to call it by the name you have declared; you can't go back to the real table name once you've declared it as something different. You're also referencing two different id fields (prod.ID and prod.ProdID) for the poochieProd table and your last post only indicated one. So, based on the last query string you posted, keeping the case the same would look like this.
PHP Code:
$query2 = sprintf("
SELECT DISTINCT stock.stockID, size.Size
FROM poochieProd AS prod
LEFT JOIN poochieStock AS stock ON prod.ProdID = stock.ID
LEFT JOIN poochieSizes AS size ON stock.SizeID = size.SizeID
WHERE prod.ProdID = '%s' AND stock.stock > 0
ORDER BY size.SizeID ASC", GetSQLValueString($var3_Recordset1, "int"));
|

October 3rd, 2012, 04:16 PM
|
|
Contributing User
|
|
Join Date: Sep 2012
Posts: 67
Time spent in forums: 15 h 54 m 55 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by SecurityDavid That's not what I said. Your statement declared the table "poochieProd AS prod" but then in your first join, you called your table "Prod" with a capital "P". If you declare your table as "prod" all in lower case, you need to call your table in all lower case every time, you can't change the case of your table name in the string. Also, once you've declared it as "prod" I believe you have to call it by the name you have declared; you can't go back to the real table name once you've declared it as something different. You're also referencing two different id fields (prod.ID and prod.ProdID) for the poochieProd table and your last post only indicated one. So, based on the last query string you posted, keeping the case the same would look like this.
PHP Code:
$query2 = sprintf("
SELECT DISTINCT stock.stockID, size.Size
FROM poochieProd AS prod
LEFT JOIN poochieStock AS stock ON prod.ProdID = stock.ID
LEFT JOIN poochieSizes AS size ON stock.SizeID = size.SizeID
WHERE prod.ProdID = '%s' AND stock.stock > 0
ORDER BY size.SizeID ASC", GetSQLValueString($var3_Recordset1, "int"));
|
ok thanks i have changed that and it is now giving me another error
Error in query: SELECT DISTINCT stock.stockID, size.Size FROM poochieProd AS prod LEFT JOIN poochieStock AS stock ON prod.ProdID = stock.ID LEFT JOIN poochieSizes AS size ON stock.SizeID = size.SizeID WHERE prod.ProdID = '-1' AND stock.stock > 0 ORDER BY size.SizeID ASC. Unknown column 'stock.ID' in 'on clause'
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|