douyan8961 2015-02-24 16:07
浏览 46

从SQL数据库填充下拉列表

So I'm creating a photo gallery for a social network. At the minute I'm creating a pre-upload page. I have set up 5 fields to enter images with appropriate captions. However, my main issue is populating the drop-down list. The drop-down list should contain categories of photos from a database (photo_category), but the drop-down list is turning up empty. Any suggestions on where I'm going wrong?

Edit: so now I've changed what's in $row by adding category_id and category_name but it now says " Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING on line 16". The line in quesion is preceded by 2 stars.

<?php
require 'configphot.inc.php';



$_photo_upload_fields='';
$count=1;

$nofields=(isset($_GET['number_of_fields']))?
(int) ($_GET['number_of_fields']):5;
$result = mysqli_query($link,"SELECT category_id, category_name FROM photo_category");


while($row=mysqli_fetch_array($result)){
$_photo_category_list .= <<<__HTML_END
**<option value="$row['category_id']">$row['category_name']**</option>n
__HTML_END;

}

mysqli_free_result($result);


while($counter<=$nofields)
{
$photo_upload_fields .= <<<__HTML_END

<tr><td>
Photo{$counter}:
<input name = "photo_filename[]" type= "file" />
</td></tr>
<tr><td>
Caption:
<textarea name ="photo_caption[]" cols = "30" rows ="1"></textarea>
</td></tr>
__HTML_END;
$counter++;
}

//End output

echo <<<__HTML_END

<html>
<head>
<title> Upload photos here</title>
</head>
<body>
<form enctype="multipart/form-data" action="upload.php" method="post" name= "upload_form">
<table width="90%" border="0" align="center" style="width: 90%;">
<tr>
<td>Select Category
<select name="category">
$photo_category_list</select></td>
</tr>

<!image fields here -->

$photo_upload_fields
<tr><td>
<input type ="submit" name="submit" value= "Add photos">
</td></tr>
</table>
</form>
</body>
</html>
__HTML_END;








?>
  • 写回答

2条回答 默认 最新

  • duanduji2986 2015-02-24 16:45
    关注

    First of all: Plase format your code. Some tabs really help to keep track of the code.

    In your SQL statement you selecting just one column: SELECT category_name FROM photo_category

    2 lines later you referencing to two columns: $row[0] (that's your category_name from your sql query) and $row[1]. The $row[1] does not exist and therefore is empty (and should produce an PHP Notice at least).

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line