duandu8202 2014-12-29 21:22 采纳率: 0%
浏览 24
已采纳

PHP半随机字生成器[关闭]

The following code is working. But I'd like to improve it. Basically, this page displays a random str per each categories and reloads a page when a user pushes a button. Can it be different so I could manage the data easier(I want to update the words library frequently). I also wonder if this is short enough for quick loading. Thank you so much for your help in advance.

<!-- begin -->
<html>
<head>
</head>

<body>


<?php 
#hash = random url generated from 128 chars


$words = array('apple', 'orange', 'banana'); 
$rword = rand(0,2);

$syms = array('chair', 'sofa', 'table', 'coffee table');
$rsym = rand(0,3); 

$value1 = $words[$rword];
$final1 = strtoupper($value1);

$value2 = $syms[$rsym];
$final2 = strtoupper($value2);

?>


<h2>Fruit</h2><p><?php echo $final1 = strtolower($value1); ?></p>
<h2>Furniture</h2><p><?php echo $final2 = strtolower($value2); ?></p>


<FORM METHOD="LINK" ACTION="random.php">
<INPUT TYPE="submit" VALUE="generate again">
</FORM>



</body>
</html>

<!-- end -->
  • 写回答

1条回答 默认 最新

  • dqmdlo9674 2014-12-29 22:01
    关注

    I would create a Database with 2 tables.

    Table 1 would be Categories: This would contain Fruit,Furniture,Rivers,etc.

    Table 2 would be Items: This would contain chair,apple,sofa,orange,etc. all associated to the correct Categories id.

    You could then query for ALL categories and return that into a full array. You could then foreach your way through the array of categories and do another query set to an array of items. Once you do that you can get the length of items and do much the same as you are doing.

    This is a descriptive answer to give you an idea that you should move to. Without knowledge of your exact idea and structure set I do not want to risk writing faulty code.

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

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘