|
-
Oct 16th, 2006, 04:48 AM
#1
Thread Starter
Junior Member
[RESOLVED] Whats wrong with my code
Hi all..i dont know what's wrong with my codes below..i have one table named category which have cat_id,cat_code,cat_desc.I want to list out cat_code.It success.All data will listed out but in blank.Thanks in advance
PHP Code:
<select name="cat_code">
<?
$sqlstmt=mysql_query(" SELECT cat_code FROM category");
while($result=mysql_fetch_array($sqlstmt))
{?>
<option value="<? echo $result['cat_code']?>"></option>
<? } ?>
</select>
-
Oct 16th, 2006, 05:20 AM
#2
Junior Member
Re: Whats wrong with my code
Your option has no caption or text, so it is displayed blank.
PHP Code:
<option value="<? echo $result['cat_code']?>">PUT CAPTION HERE</option>
Last edited by hairball; Oct 16th, 2006 at 05:24 AM.
Break out from your mental box.
I found better company. Iced chocolate with coffee jelly, anyone?
-
Oct 19th, 2006, 03:34 PM
#3
Re: Whats wrong with my code
<option value="<? echo $result['cat_code']?>"><? echo $result['cat_desc'] ?></option>
-
Oct 20th, 2006, 02:07 AM
#4
Junior Member
Re: Whats wrong with my code
Looks better.
PHP Code:
<select name="cat_code">
<?
$sqlstmt=mysql_query(" SELECT cat_code, cat_desc FROM category");
while($result=mysql_fetch_array($sqlstmt))
{?>
<option value="<? echo $result['cat_code']?>"><? echo $result['cat_desc'] ?></option>
<? } ?>
</select>
Break out from your mental box.
I found better company. Iced chocolate with coffee jelly, anyone?
-
Oct 24th, 2006, 03:52 PM
#5
Re: Whats wrong with my code
-
Oct 25th, 2006, 07:51 PM
#6
Junior Member
Re: Whats wrong with my code
 Originally Posted by mendhak
Stickler.
Likewise.
Break out from your mental box.
I found better company. Iced chocolate with coffee jelly, anyone?
-
Oct 25th, 2006, 08:40 PM
#7
Re: Whats wrong with my code
 Originally Posted by hairball
Looks better.
PHP Code:
<select name="cat_code">
<?
$sqlstmt=mysql_query(" SELECT cat_code, cat_desc FROM category");
while($result=mysql_fetch_array($sqlstmt))
{?>
<option value="<? echo $result['cat_code']?>"><? echo $result['cat_desc'] ?></option>
<? } ?>
</select>
Never use the short tags <? and <?=. These are not supported on many servers, and most likely will not be forwards compatible with PHP 6.
If you only want to reference rows by name, mysql_fetch_assoc() is more efficient.
Also, with constructs spanning HTML sections, you can use the alternative syntax, like this:
PHP Code:
<select name="cat_code">
<?php
$result_set = mysql_query("SELECT cat_code, cat_desc FROM category");
while ($row = mysql_fetch_assoc($result_set)):
?>
<option value="<?php echo $row['cat_code'] ?>"><?php echo $row['cat_desc'] ?></option>
<?php endwhile; ?>
</select>
Finally, I do recommend using a better data access API, like PDO, etc., if you can.
-
Oct 30th, 2006, 09:28 PM
#8
Thread Starter
Junior Member
Re: Whats wrong with my code
Thanks a lot everybody..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|