Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

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 Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old June 29th, 2003, 01:49 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
Add items to new category

Currently I am using a script to insert item in an 'items' table and a seperate script to add categories to the 'categories' table. The items table has a field called cat_id and references an id field in the categories table. I need to use a drop down box so that cat_title is displayed from 'categories' but a cat_id is inserted. Here is the code I am using now. Unfortunately if I use a new category with no items the new cat_id is assigned as zero.
<?
$dbcnx = @mysql_connect( "host", "test", "test");
mysql_select_db("testdb");
$query = "SELECT distinct cat_id, cat_title from store_items right join store_categories on store_items.cat_id = store_categories.id";
$result = mysql_query($query);
print "<SELECT name=cat_id>";
while ($line = mysql_fetch_array($result))
{
foreach ($line as $cat_id)

{
print "<OPTION value='$cat_id'";
}
print ">$cat_id</OPTION>";
}

print "</SELECT>";

?>
I am very new to this - any help is greatly appreciated.

Reply With Quote
  #2  
Old July 2nd, 2003, 10:41 AM
Jester Jester is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: England
Posts: 271 Jester User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Add items to new category

Would this be any better? (i.e. get the db to put together the option string?):

php Code:
Original - php Code
  1.  
  2. $query = "SELECT  DISTINCT CONCAT(  '<OPTION value=', field1,  '>', field2,  '</OPTION>'  )  AS  'option' FROM table(s)";
  3.  
  4. $result = mysql_query($query);
  5.  
  6. echo '<SELECT name=cat_id>';
  7. while ($line = mysql_fetch_array($result)) {
  8.   echo "n" . $val;
  9. }
  10. echo '</SELECT>';

Reply With Quote
  #3  
Old July 4th, 2003, 01:10 AM
fsylvia fsylvia is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 1 fsylvia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Add items to new category

- Very helpful - thank you!
php Code:
Original - php Code
  1.  
  2. query = "SELECT DISTINCT CONCAT( '<OPTION value=',id , '>', cat_title, 
  3. '</OPTION>'  )  AS  'option' FROM  store_categories";
  4.  
  5. $result = mysql_query($query);
  6.  
  7. echo '<SELECT name=cat_id>';
  8. while ($line = mysql_fetch_array($result))
  9. {
  10.     foreach ($line as $cat_id);
  11.     {
  12.       echo "n" . $cat_id;
  13.         }   
  14.        
  15. }
  16. echo '</SELECT>';
  17.    
  18. ?>

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Add items to new category


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway