|
![](/images/resource/spacer.gif) |
|
**สอบถาม** เรื่อง function random สีครับ มันสามารถ ไม่ให้ดึงสีซ้ำกันได้ไหมครับ |
|
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
จาก กระทู้นี้ครับ >>>>>> https://www.thaicreate.com/php/forum/060640.html
คือผมจะสุ่มสี ไปใส่ ในกราฟวงกลมของผม ซึ่ง ข้อมูลดึงจากฐานข้อมูล จึงไม่สามารำกำหนดสีไปตรงๆได้
นี้คือโค้ดสุ่มสีครับ
Code (PHP)
function mixTextColor($length) {
$colors = array('#0DA068','#194E9C','#ED9C13','#ED5713','#057249','#5F91DC','#F88E5D');
$result = substr(str_shuffle($text), 0, $length);
for($i = 0; $i < $length; $i++) {
echo $colors[array_rand($colors)];
}
}
แล้วนี้ตอนที่ใส่ครับ
Code (PHP)
<table id="chartData">
<tr>
<th>ตำแหน่งที่เสีย</th>
<th>จำนวน</th>
</tr>
<?php
while($schedule_repair = mysql_fetch_array($query_schedule_repair))
{
?>
<tr style="color: <?php mixTextColor(1); ?>">
<td><?php echo $schedule_repair['Position']; ?></td>
<td><?php echo $schedule_repair['Czone']; ?></td>
</tr>
<?php
}
?>
</table>
แต่ผลลัพที่ได้อกมา มัักจะได้แบบนี้
![misscolor misscolor](https://www.thaicreate.com/upload/stock/20160911085247.png?v=1001)
เลยจะถามว่ามันสามารถ ไม่ให้มันดึงสี ที่ซ้ำกันได้ไหมอ่ะครับ
Tag : PHP, MySQL, HTML/CSS, JavaScript
![](/images/adv.jpg?v=1001)
|
ประวัติการแก้ไข 2016-09-11 08:53:11
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2016-09-11 08:51:02 |
By :
nutzaaclub |
View :
1989 |
Reply :
2 |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ไม่ต้องสุ่มได้ไหมอะแค่ให้มันไม่ซ้ำ
Code (PHP)
<?php
$colors = ['#0DA068','#194E9C','#ED9C13','#ED5713','#057249','#5F91DC','#F88E5D'];
$i = 0;
while($schedule_repair = mysql_fetch_array($query_schedule_repair))
{
?>
<tr style="color: <?php echo $colors($i); ?>">
<td><?php echo $schedule_repair['Position']; ?></td>
<td><?php echo $schedule_repair['Czone']; ?></td>
</tr>
<?php
$i++;
}
?>
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2016-09-12 09:55:09 |
By :
โดย |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
|
|
|
![](/images/digitalocean-banner.jpg)
|
Load balance : Server 04
|