dongyu9263 2012-07-03 16:07
浏览 6

too long

I'm writing sql code which gets the name of the columns its supposed to look up of a table from custom php code.

Part of this has to do with location i.e. country ,state, zip, etc. I have it so that on the php code, the user fills out the fields that correspond to these on their tables. However, it is possible that while these are all possibilities they may not have every piece, like the zip code.

If I the php doesn't get anything for the zip column name it throws off the entire code. Null columns are ok with me, but I'm struggling finding a way to make a placeholder for the column. Is there a sql placeholder I can tell the php variable to become if the user enters nothing and is therefore null?

$addressColumn = $_POST["address"];
$stateColumn = $_POST["state"];
$zipColumn = $_POST["zip"]; 
$cityColumn = $_POST["city"];
$countryColumn = $_POST["country"];
$database = $_POST["database"];

if one of these is not posted on the html page, then the code breaks. suggestions? I can change the value if null to something else if anyone knows of a placeholder value that sql will accept and then as I fetch rows will place null below it

  • 写回答

1条回答 默认 最新

  • douju8782 2012-07-03 16:36
    关注

    I think that working starting from column names is not a good idea. SQL doesn't concept like stree or ZIP but only stings and number or date.

    I suggest you to create a class with all your table columns as properties, putting the business logic in the right place (the PHP), so the method "query" (the one who query the DB) can validate/operate/manage the status of your object.

    The PHP that draw the for can get all infos from the class (eg: *get_object_vars* ) instead of DB.

    If you're worried from mapping your DB into class you can look at ActiveRecords.

    评论

报告相同问题?

悬赏问题

  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示