doumu6997 2014-01-12 11:19
浏览 70
已采纳

使用if else或使用数据库中的值更改PHP中的字符串

I am looking to understand a good practice for the following situation:

If my profile has some value in the database, for example: 10000

and I want to display in the page You are level "Advanced user" what is the good way of doing this?

if row[user_xp] > 10000 print "You are Advanced user"

and I change this string "Advanced user" according to a value in the database.

Way Two:

Recording another value, that holds this names like "Beginner", "Advanced user", "Pro" and if row[user_xp] > 10000 mysqli_query SET user_level = 2 (where 2 is the number that means "Advanced user")

And then when I display the string level if row[user_level] = 2 print You are $userLevel (that will print string like "You are Advanced user")

As I am very beginner, I think maybe it will depend on my needs to record that value names in the database or not. But I am really not sure for the approach.

Thank you very much for the attention and your replies!

  • 写回答

1条回答 默认 最新

  • dongqiangse6623 2014-01-12 11:24
    关注

    If 10000 is some kind of value that will be changed in the future, necessarily save it in the database. It will be easy then to add or remove something from it. Then save sections in another table of database, for example:

    Category: Average User; min_value: 1000; max_value: 10000

    Category: Expert; min_value: 10001; max_value: 1000000

    In that case You can change these settings only in one place and in the future: if for example expert user will be from 9001 You can easily change it only in one database. And the index for each user stays the same :)

    Hope it helps

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿