PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 3rd, 2012, 10:57 AM
jonnyfreak jonnyfreak is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 67 jonnyfreak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 54 m 55 sec
Reputation Power: 1
PHP-General - Cant get a select list working with joined table. HELP

i am going round in circles. Maybe a fresh set of eyes can help
i have the following table joined

prod table

ID (prod)
name
CatID

Size Table

SizeID
Size

Stock Table

StockID
ID (prod)
SizeID
Stock

i am trying to populate a select list with sizes from a product

PHP Code:
 $var3_Recordset1 "-1";
if (isset(
$_GET['ProdID'])) {
  
$var3_Recordset1 $_GET['ProdID'];
}
mysql_select_db($database_poochie$poochie);
$query_Recordset1 sprintf("SELECT * FROM poochieProd, poochieStock, poochieSizes WHERE poochieProd.ProdID = %s" AND poochieStock.sizeID poochieSizes.SizeIDGetSQLValueString($var3_Recordset1"text"));
$Recordset1 mysql_query($query_Recordset1$poochie) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1)

<
select name="os0" class="text" id="selectSize">
      <
option value="Select Size">Select Size</option>
      <?
php
                $query2 
sprintf("
                SELECT DISTINCT
                    stock.stockID, size.Size 
                FROM 
                    poochieProd AS prod 
                    LEFT JOIN pochieStock AS stock ON prod.ID = stock.ID 
                    LEFT JOIN poochieSizes AS size ON stock.SizeID = size.SizeID
                WHERE
                    prod.ID = '%s' AND stock.Stock > 0
                ORDER BY
                    size.SizeID ASC"
GetSQLValueString($var3_Recordset1"int"));
                
$results2 mysql_query($query2);
                while(
$row2 mysql_fetch_array($results2)){
                    
?>
      <option value="<?php echo $row2['Size']; ?>"><?php echo $row2['Size']; ?></option>
      <?php
                
}
                
                
?>
    </select> 



i dont know where i am going wrong,

thanks in advance for any help

Reply With Quote
  #2  
Old October 3rd, 2012, 11:30 AM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,867 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 1 Week 5 Days 9 h 6 m 6 sec
Reputation Power: 581
You need to be more specific. Post some output or something that will help us understand the problem. What is wrong or missing? What error messages are you getting? Did you echo $query2 and then copy and paste that into a command line session?

P.S. You should consider changing to PDO rather than use the depreciated MySQL library.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.

Reply With Quote
  #3  
Old October 3rd, 2012, 11:39 AM
jonnyfreak jonnyfreak is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 67 jonnyfreak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 54 m 55 sec
Reputation Power: 1
Quote:
Originally Posted by gw1500se
You need to be more specific. Post some output or something that will help us understand the problem. What is wrong or missing? What error messages are you getting? Did you echo $query2 and then copy and paste that into a command line session?

P.S. You should consider changing to PDO rather than use the depreciated MySQL library.


ok the Output i got from the select list was

<b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/usr/users1/ort/public_html/ch/product-detail.php</b> on line <b>132</b>


and on line 132 the code is

while($row2 = mysql_fetch_array($results2)){

Reply With Quote
  #4  
Old October 3rd, 2012, 11:44 AM
jonnyfreak jonnyfreak is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 67 jonnyfreak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 54 m 55 sec
Reputation Power: 1
the full out from the select list is



<select name="os0" class="text" id="selectSize">
<option value="Select Size">Select Size</option>
<br />
<b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/usr/users1/ort/public_html/ch/product-detail.php</b> on line <b>132</b><br />
</select>

Reply With Quote
  #5  
Old October 3rd, 2012, 12:06 PM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,867 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 1 Week 5 Days 9 h 6 m 6 sec
Reputation Power: 581
Try debugging the warning with this:
PHP Code:
 $results2 mysql_query($query2) or die ("Error in query: $query2. ".mysql_error()); 

Reply With Quote
  #6  
Old October 3rd, 2012, 12:17 PM
jonnyfreak jonnyfreak is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 67 jonnyfreak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 54 m 55 sec
Reputation Power: 1
this is helping..it gave me an error regarding a spelling error

pochieStock

i corrected this to read poochieStock then it has given an 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 Prod.ID = '-1' AND stock.stock > 0 ORDER BY size.SizeID ASC. Unknown table 'Prod' in where clause


but i am unsure what table 'Prod' the error is referring to?

Reply With Quote
  #7  
Old October 3rd, 2012, 12:29 PM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,867 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 1 Week 5 Days 9 h 6 m 6 sec
Reputation Power: 581
You must not have a table named 'Prod' in your database (show tables). What is that particular column (Prod.ID) supposed to be?

Reply With Quote
  #8  
Old October 3rd, 2012, 12:34 PM
jonnyfreak jonnyfreak is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 67 jonnyfreak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 54 m 55 sec
Reputation Power: 1
the tables that i have and the joins are

poochieCat
CatID
name

poochieStock
stockID
ProdID
sizeID
stock

poochieSizes
SizeID
Size

poochieProd
ProdID
Prodname
CatID

Reply With Quote
  #9  
Old October 3rd, 2012, 12:49 PM
jonnyfreak jonnyfreak is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 67 jonnyfreak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 54 m 55 sec
Reputation Power: 1
the tables i included in the first post are not the correct ones from this post, i incorrectly added them so the ones on my previous ones are the correct one

Reply With Quote
  #10  
Old October 3rd, 2012, 12:49 PM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,867 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 1 Week 5 Days 9 h 6 m 6 sec
Reputation Power: 581
I think you want to remove the dot (.).

Reply With Quote
  #11  
Old October 3rd, 2012, 12:59 PM
jonnyfreak jonnyfreak is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 67 jonnyfreak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 54 m 55 sec
Reputation Power: 1
Quote:
Originally Posted by gw1500se
I think you want to remove the dot (.).



i have changes the query to

<?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
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 am now getting the results

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 prodID = '-1' AND stock.stock > 0 ORDER BY size.SizeID ASC. Column 'prodID' in where clause is ambiguous

so i changed this to prod.prodID and it returned

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 prod.prodID = '-1' AND stock.stock > 0 ORDER BY size.SizeID ASC. Unknown table 'Prod' in on clause

Reply With Quote
  #12  
Old October 3rd, 2012, 01:07 PM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,867 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 1 Week 5 Days 9 h 6 m 6 sec
Reputation Power: 581
Yes because table 'Prod' does not exist. What table do you want 'ProdID' to be taken from? It exists in more than 1.

Reply With Quote
  #13  
Old October 3rd, 2012, 01:10 PM
jonnyfreak jonnyfreak is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 67 jonnyfreak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 54 m 55 sec
Reputation Power: 1
Quote:
Originally Posted by gw1500se
Yes because table 'Prod' does not exist. What table do you want 'ProdID' to be taken from? It exists in more than 1.


i presume in need it to come from the poochieStock table.

Reply With Quote
  #14  
Old October 3rd, 2012, 01:11 PM
jonnyfreak jonnyfreak is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 67 jonnyfreak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 54 m 55 sec
Reputation Power: 1
Quote:
Originally Posted by gw1500se
Yes because table 'Prod' does not exist. What table do you want 'ProdID' to be taken from? It exists in more than 1.



i thought the poochieProd AS prod

was telling the next part to see poochieProd as prod so

WHERE prod.ProdID would see this?

Reply With Quote
  #15  
Old October 3rd, 2012, 01:13 PM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,867 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 1 Week 5 Days 9 h 6 m 6 sec
Reputation Power: 581
Nope. Use poochieProd.ProdID

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP-General - Cant get a select list working with joined table. HELP

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap