duanjue7508 2013-05-29 19:03
浏览 47
已采纳

插入mysql但选择何时显示...?

What I want to do is next:

person makes a new post, let say it is a post for latest news. After form is populated, he/or she have a radio button or check-box to choose to display the latest news right away, or to wait for approval. I tried making a column 'visible' with the type of tinyint ... but no luck, because post is shown no matter if the tinyint value is '0', or '1'. Am i doing this wrong? '0' = false, '1' = true, right?

Example:

$headline = $_POST['headline'];
$news = $_POST['news_text'];
$visible = $_POST['visible'];

$query = "INSERT INTO news ( headline, news_text, visible) VALUES ($headline,      $news_text, $visible");

<input type="radio" name="visible" value="0> No
<input type="radio" name="visible" value="1> Yes

Seem's a bit dull ... Help is appreciated ...

  • 写回答

1条回答 默认 最新

  • dou1908 2013-05-29 19:32
    关注

    Make sure your visible field is an INT field type (or TINYINT), and only make sure you use 0 or 1 for the value of that field.

    So your table should look like this:

    +----------+-----------+---------+
    | headline | text      | visible |
    +----------+-----------+---------+
    | Test 1   | Text One  | 0       |
    | Test 2   | Text Two  | 1       |
    +----------+-----------+---------+
    

    Then, when you go to display the articles (only if visibility is 1):

    SELECT headline, text 
    FROM tableName 
    WHERE visible = 1
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分