Current location: Hot Scripts Forums » Programming Languages » PHP » Dropdown problem


Dropdown problem

Reply
  #1 (permalink)  
Old 08-04-04, 06:42 AM
Space_kadett Space_kadett is offline
New Member
 
Join Date: Aug 2004
Location: Oslo, Norway and St Thomas, USVI
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Dropdown problem

I'm making a dropdown list populated with all productnames from a pricelist (table), where users can select a product, and hit the button to proceed to a page that displays product details and price.
Works like a charm - except for ONE small problem: the first product in the table doesn't appear on the dropdown list, it starts out with a empty line.
If you select the empty line, you get a
-You have an error in your SQL syntax near '' at line 1- message on the next page, all the others work perfect....
I'm confused here - can anyone help??
PHP Code:

<?php

//connect
$db mysql_connect("host""user""password");

mysql_select_db("database"$db);
// We have now connected, unless you got an error message 

//get ID and item from table
$query_art "SELECT ID, art FROM prices";
$art mysql_query($query_art) or die(mysql_error());
$row_art mysql_fetch_row($art);
?>

<!--sends ID from selected item to display.php-->

<form name="form" method="post" action="display.php">
  
   <select name="fieldOne">
    <option value="">Velg artikkel</option>
    
<?php
//insert item into dropdown with ID as value
do 
    {  
?>

    <option value="<?php echo $row_art['ID']?>"><?php echo $row_art['art']?></option>
<?php
    

while (
$row_art mysql_fetch_assoc($art));
?>
  </select>
          
    <input type="submit" name="Submit" value="Finn prisen" >

</form>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 08-08-04, 11:12 AM
Space_kadett Space_kadett is offline
New Member
 
Join Date: Aug 2004
Location: Oslo, Norway and St Thomas, USVI
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Ok, so you couldn't solve it either...

Well, I "hid" the problem by adding a empty row to the table and sort by art to the query, so now it LOOKS right..............

:-)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 08-09-04, 04:38 AM
Mickey1984 Mickey1984 is offline
New Member
 
Join Date: Aug 2004
Location: China
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
you can try my code:
<?php
while($row_art = mysql_fetch_row($art))
{
?>
<option value="<?php echo $row_art['ID']?>"><?php echo $row_art['art']?></option>

<?php
}
?>
the problem may be the do^while,because when you run the code first time,the $row_art doesn't konw the exact result if the table prices has too many recorde!!(I hope you can understande my mean ,my english is very poor,English is not my native language)
and i think Space_kadett's way is not bad!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 08-09-04, 05:19 AM
darkfreak's Avatar
darkfreak darkfreak is offline
Newbie Coder
 
Join Date: Jun 2004
Location: Kuopio, Finland, Europe
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Space_kadett
PHP Code:

<?php

//insert item into dropdown with ID as value
do 
    {  
?>

    <option value="<?php echo $row_art['ID']?>"><?php echo $row_art['art']?></option>
<?php
    

while (
$row_art mysql_fetch_assoc($art));
?>
  </select>
          
    <input type="submit" name="Submit" value="Finn prisen" >

</form>
Wouldn't it help if you just turn the loop upside down - now that you have the DO before WHILE you apparently don't have any value in $row_art['ID'] at the first round. Try to do it something like:

PHP Code:

<?php

while( $row_art mysql_fetch_assoc($art) ) {

        echo 
"<option value=$row_art[ID]>$row_art[art]</option>\n";

// end of while
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie found a solution to a date problem. mickey_kamer Perl 4 05-09-07 06:54 AM
Count problem kasic ASP.NET 1 10-20-04 01:23 AM
an unusual problem.... fabulosas10 PHP 0 07-16-04 03:03 AM
DHTML layer "behind" dropdown menus !?! paulwynd JavaScript 3 01-14-04 08:57 AM
Multiple dropdown plus link problem bastiaan JavaScript 0 11-17-03 05:22 PM


All times are GMT -5. The time now is 11:23 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.