ThaiSEOBoard.com

พัฒนาเว็บไซต์ => Programming => ข้อความที่เริ่มโดย: dekjaidee ที่ 20 กรกฎาคม 2018, 02:10:32



หัวข้อ: [PHP] เขียนอะไรผิดครับ ช่วยที ไม่มีค่าแสดงออกมา!!!!
เริ่มหัวข้อโดย: dekjaidee ที่ 20 กรกฎาคม 2018, 02:10:32
โค๊ด:
<?
require_once "connectdb.php";

$number="$_POST[number]";
if (strlen($number) != 1)
{
$loop=strlen($number)-1;
for($i=0;$i<$loop;$i++)
{
 //echo substr($number,$i,2)."<br>";
 $strs = substr($number,$i,2);
 
 $sqlhr="select * from horotest where numb='$strs'";
$db_query=mysql_query($sqlhr);
$reshr=mysql_fetch_array($db_query);
$numtxt=$reshr[numtxt];

 echo "$strs [$numtxt]<br>";
}
}else{
 echo "$number";
}
?>



จาก Code ด้านบนครับ ค่า $numtxt ไม่มีค่าไรแสดงออกมา ไม่ทราบว่าเขียนผิดตรงไหนครับ
รบกวนทีครับ

 :wanwan017: :wanwan017:


หัวข้อ: Re: [PHP] เขียนอะไรผิดครับ ช่วยที ไม่มีค่าแสดงออกมา!!!!
เริ่มหัวข้อโดย: narincr ที่ 20 กรกฎาคม 2018, 02:22:44
โค๊ด:
<?
require_once "connectdb.php";

$number="$_POST[number]";
if (strlen($number) != 1)
{
$loop=strlen($number)-1;
for($i=0;$i<$loop;$i++)
{
 //echo substr($number,$i,2)."<br>";
 $strs = substr($number,$i,2);
 
 $sqlhr="select * from horotest where numb='$strs'";
$db_query=mysql_query($sqlhr);
$reshr=mysql_fetch_array($db_query);
$numtxt=$reshr[numtxt];

 echo "$strs [$numtxt]<br>";
}
}else{
 echo "$number";
}
?>

จาก Code ด้านบนครับ ค่า $numtxt ไม่มีค่าไรแสดงออกมา ไม่ทราบว่าเขียนผิดตรงไหนครับ
รบกวนทีครับ

 :wanwan017: :wanwan017:

$numtxt=$reshr[numtxt];
ค่า $reshr จะ return เป็น array ครับ
ให้เปลี่ยนเป็น $numtxt=$reshr[0][numtxt];

แบบนี้ครับ ลองดูครับ


หัวข้อ: Re: [PHP] เขียนอะไรผิดครับ ช่วยที ไม่มีค่าแสดงออกมา!!!!
เริ่มหัวข้อโดย: dekjaidee ที่ 20 กรกฎาคม 2018, 02:28:59
โค๊ด:
<?
require_once "connectdb.php";

$number="$_POST[number]";
if (strlen($number) != 1)
{
$loop=strlen($number)-1;
for($i=0;$i<$loop;$i++)
{
 //echo substr($number,$i,2)."<br>";
 $strs = substr($number,$i,2);
 
 $sqlhr="select * from horotest where numb='$strs'";
$db_query=mysql_query($sqlhr);
$reshr=mysql_fetch_array($db_query);
$numtxt=$reshr[numtxt];

 echo "$strs [$numtxt]<br>";
}
}else{
 echo "$number";
}
?>

จาก Code ด้านบนครับ ค่า $numtxt ไม่มีค่าไรแสดงออกมา ไม่ทราบว่าเขียนผิดตรงไหนครับ
รบกวนทีครับ

 :wanwan017: :wanwan017:

$numtxt=$reshr[numtxt];
ค่า $reshr จะ return เป็น array ครับ
ให้เปลี่ยนเป็น $numtxt=$reshr[0][numtxt];

แบบนี้ครับ ลองดูครับ

$sqlhr="select * from horotest where numb='$strs'";
   $db_query=mysql_query($sqlhr);
   $reshr=mysql_fetch_array($db_query);
   $numtxt=$reshr[0][numtxt];

อย่างนี้เปล่าครับ ถ้าตามนี้ ก็ยังไม่แสดงครับ

 :wanwan017: :wanwan017:


หัวข้อ: Re: [PHP] เขียนอะไรผิดครับ ช่วยที ไม่มีค่าแสดงออกมา!!!!
เริ่มหัวข้อโดย: sinomoney ที่ 20 กรกฎาคม 2018, 04:18:09
เปิด PHP แบบเต็มด้วยครับ

<?php

?>


หัวข้อ: Re: [PHP] เขียนอะไรผิดครับ ช่วยที ไม่มีค่าแสดงออกมา!!!!
เริ่มหัวข้อโดย: dekjaidee ที่ 20 กรกฎาคม 2018, 07:15:29
เปิด PHP แบบเต็มด้วยครับ

<?php

?>

เปิดตามนี้แล้วครับ แต่ยังไม่แสดงครับ

 :wanwan017: :wanwan017:


หัวข้อ: Re: [PHP] เขียนอะไรผิดครับ ช่วยที ไม่มีค่าแสดงออกมา!!!!
เริ่มหัวข้อโดย: del555 ที่ 20 กรกฎาคม 2018, 07:35:48
โค๊ด:
<?
require_once "connectdb.php";

$number="$_POST[number]";
if (strlen($number) != 1)
{
$loop=strlen($number)-1;
for($i=0;$i<$loop;$i++)
{
 //echo substr($number,$i,2)."<br>";
 $strs = substr($number,$i,2);
 
 $sqlhr="select * from horotest where numb='$strs'";
$db_query=mysql_query($sqlhr);
$reshr=mysql_fetch_array($db_query);
$numtxt=$reshr[numtxt];

 echo "$strs [$numtxt]<br>";
}
}else{
 echo "$number";
}
?>

จาก Code ด้านบนครับ ค่า $numtxt ไม่มีค่าไรแสดงออกมา ไม่ทราบว่าเขียนผิดตรงไหนครับ
รบกวนทีครับ

 :wanwan017: :wanwan017:

$numtxt=$reshr[numtxt];
ค่า $reshr จะ return เป็น array ครับ
ให้เปลี่ยนเป็น $numtxt=$reshr[0][numtxt];

แบบนี้ครับ ลองดูครับ

$sqlhr="select * from horotest where numb='$strs'";
   $db_query=mysql_query($sqlhr);
   $reshr=mysql_fetch_array($db_query);
   $numtxt=$reshr[0][numtxt];

อย่างนี้เปล่าครับ ถ้าตามนี้ ก็ยังไม่แสดงครับ

 :wanwan017: :wanwan017:

ลองเปลี่ยนจาก $reshr=mysql_fetch_array($db_query);
มาเป็น $reshr=mysql_fetch_assoc($db_query); หน่อยคับ


หัวข้อ: Re: [PHP] เขียนอะไรผิดครับ ช่วยที ไม่มีค่าแสดงออกมา!!!!
เริ่มหัวข้อโดย: del555 ที่ 20 กรกฎาคม 2018, 07:38:03
ลืมอีกอย่างคับ รับค่าแบบนี้นะคับ
$numtxt=$reshr[0][numtxt];


หัวข้อ: Re: [PHP] เขียนอะไรผิดครับ ช่วยที ไม่มีค่าแสดงออกมา!!!!
เริ่มหัวข้อโดย: Mrpoohling ที่ 20 กรกฎาคม 2018, 07:52:32
<?
require_once "connectdb.php";

$number=$_POST[number];
if (strlen($number) != 1)
{
$loop=strlen($number)-1;
for($i=0;$i<$loop;$i++)
{
 //echo substr($number,$i,2)."<br>";
 $strs = substr($number,$i,2);
 
 $sqlhr="select * from horotest where numb='".$strs."'";
   $db_query=mysql_query($sqlhr);
   $reshr=mysql_fetch_array($db_query);
   $numtxt=$reshr[numtxt];
   
 echo $strs [$numtxt]."<br>";
}
}else{
 echo $number;
}
?>


หัวข้อ: Re: [PHP] เขียนอะไรผิดครับ ช่วยที ไม่มีค่าแสดงออกมา!!!!
เริ่มหัวข้อโดย: dekjaidee ที่ 20 กรกฎาคม 2018, 08:22:10
<?
require_once "connectdb.php";

$number=$_POST[number];
if (strlen($number) != 1)
{
$loop=strlen($number)-1;
for($i=0;$i<$loop;$i++)
{
 //echo substr($number,$i,2)."<br>";
 $strs = substr($number,$i,2);
 
 $sqlhr="select * from horotest where numb='".$strs."'";
   $db_query=mysql_query($sqlhr);
   $reshr=mysql_fetch_array($db_query);
   $numtxt=$reshr[numtxt];
   
 echo $strs [$numtxt]."<br>";
}
}else{
 echo $number;
}
?>

ขอบคุณทุกท่านเลยครับ แต่แก้ตามแล้ว ค่า numtxt ก็ยังไม่แสดงครับ

 :wanwan017: :wanwan017:


หัวข้อ: Re: [PHP] เขียนอะไรผิดครับ ช่วยที ไม่มีค่าแสดงออกมา!!!!
เริ่มหัวข้อโดย: ten1312 ที่ 20 กรกฎาคม 2018, 08:58:39
มือใหม่ให้ใช้ echo กับ print_r เยอะๆ
code แค่นี้ให้มันแสดงค่าออกมาทุกแถวก็ยังได้


หัวข้อ: Re: [PHP] เขียนอะไรผิดครับ ช่วยที ไม่มีค่าแสดงออกมา!!!!
เริ่มหัวข้อโดย: Tutorcuu ที่ 20 กรกฎาคม 2018, 09:25:15
สู้ต่อไปครับ สู้ๆ


หัวข้อ: Re: [PHP] เขียนอะไรผิดครับ ช่วยที ไม่มีค่าแสดงออกมา!!!!
เริ่มหัวข้อโดย: l3master ที่ 20 กรกฎาคม 2018, 09:47:09
ขั้นตอนในการ Debug ต้องไล่ Print ดูทุก loop


หัวข้อ: Re: [PHP] เขียนอะไรผิดครับ ช่วยที ไม่มีค่าแสดงออกมา!!!!
เริ่มหัวข้อโดย: maneemeena ที่ 20 กรกฎาคม 2018, 10:15:11
ตอนผมหัด php ใหม่ๆ แล้วไล่หาบรรทัดเออเรอ ไม่เจอ ผมใช้วิธีการ

โค๊ด:
die("ผ่าน");

ไล่ทีละแถวเลยครับ  :wanwan020: :wanwan020: :wanwan020:


หัวข้อ: Re: [PHP] เขียนอะไรผิดครับ ช่วยที ไม่มีค่าแสดงออกมา!!!!
เริ่มหัวข้อโดย: killer777 ที่ 20 กรกฎาคม 2018, 10:25:35
ลองไล่ echo ทีละบรรทัดครับ ใช้คำสั่ง  echo ควบคู่กับ exit() จะได้รู้ว่า error ที่บรรทัดไหนครับ


หัวข้อ: Re: [PHP] เขียนอะไรผิดครับ ช่วยที ไม่มีค่าแสดงออกมา!!!!
เริ่มหัวข้อโดย: dekjaidee ที่ 20 กรกฎาคม 2018, 14:09:49
ตอนนี้ได้แล้วครับ สอบถามเพิ่มเติมอีกนิดครับ

อ้างถึง
<?
require_once "connectdb.php";

$number="$_POST[number]";
if (strlen($number) != 1)
{
$loop=strlen($number)-1;
for($i=0;$i<$loop;$i++)
{
 //echo substr($number,$i,2)."<br>";
 $strs = substr($number,$i,2);
 
 $sqlhr="select * from horotest where numb='$strs'";
   $db_query=mysql_query($sqlhr);
   $reshr=mysql_fetch_array($db_query);
   $numtxt=$reshr[numtxt];
   
 echo "$strs [$numtxt]<br>";
}
}else{
 echo "$number";
}
?>

กรอก 1111
ค้าที่ได้ก็จะเป็น 11 / 11/ 11 เลขซ้ำกันอ่ะครับ

เราเขียนดักอย่างไรให้แสดงแค่ 11 อย่างเดียวครับ

 :wanwan017: :wanwan017:


หัวข้อ: Re: [PHP] เขียนอะไรผิดครับ ช่วยที ไม่มีค่าแสดงออกมา!!!!
เริ่มหัวข้อโดย: Hairremove ที่ 20 กรกฎาคม 2018, 16:10:14
 :wanwan013: :wanwan013: :wanwan013:


หัวข้อ: Re: [PHP] เขียนอะไรผิดครับ ช่วยที ไม่มีค่าแสดงออกมา!!!!
เริ่มหัวข้อโดย: dekjaidee ที่ 20 กรกฎาคม 2018, 20:52:14
ตอนนี้ได้แล้วครับ สอบถามเพิ่มเติมอีกนิดครับ

อ้างถึง
<?
require_once "connectdb.php";

$number="$_POST[number]";
if (strlen($number) != 1)
{
$loop=strlen($number)-1;
for($i=0;$i<$loop;$i++)
{
 //echo substr($number,$i,2)."<br>";
 $strs = substr($number,$i,2);
 
 $sqlhr="select * from horotest where numb='$strs'";
   $db_query=mysql_query($sqlhr);
   $reshr=mysql_fetch_array($db_query);
   $numtxt=$reshr[numtxt];
   
 echo "$strs [$numtxt]<br>";
}
}else{
 echo "$number";
}
?>

กรอก 1111
ค้าที่ได้ก็จะเป็น 11 / 11/ 11 เลขซ้ำกันอ่ะครับ

เราเขียนดักอย่างไรให้แสดงแค่ 11 อย่างเดียวครับ

 :wanwan017: :wanwan017:

 :wanwan017: :wanwan017:


หัวข้อ: Re: [PHP] เขียนอะไรผิดครับ ช่วยที ไม่มีค่าแสดงŪ
เริ่มหัวข้อโดย: mytony ที่ 21 กรกฎาคม 2018, 02:31:33
ตอนนี้ได้แล้วครับ สอบถามเพิ่มเติมอีกนิดครับ

อ้างถึง
<?
require_once "connectdb.php";

$number="$_POST[number]";
if (strlen($number) != 1)
{
$loop=strlen($number)-1;
for($i=0;$i<$loop;$i++)
{
 //echo substr($number,$i,2)."<br>";
 $strs = substr($number,$i,2);
 
 $sqlhr="select * from horotest where numb='$strs'";
   $db_query=mysql_query($sqlhr);
   $reshr=mysql_fetch_array($db_query);
   $numtxt=$reshr[numtxt];
   
 echo "$strs [$numtxt]<br>";
}
}else{
 echo "$number";
}
?>

กรอก 1111
ค้าที่ได้ก็จะเป็น 11 / 11/ 11 เลขซ้ำกันอ่ะครับ

เราเขียนดักอย่างไรให้แสดงแค่ 11 อย่างเดียวครับ

 :wanwan017: :wanwan017:
ตรงนี้ผิดหรือป่าว
$db_query=mysql_query($sqlhr);
   $reshr=mysql_fetch_array($db_query);
   $numtxt=$reshr[numtxt];
ลองเปลี่ยนตามนี้ดูนะครับ
$db_query=mysqli_query($con,$sqlhr);
$result = mysqli_fetch_assoc($db_query);


หัวข้อ: Re: [PHP] เขียนอะไรผิดครับ ช่วยที ไม่มีค่าแสดงออกมา!!!!
เริ่มหัวข้อโดย: CherryX ที่ 21 กรกฎาคม 2018, 05:31:52
ตอนผมหัด php ใหม่ๆ แล้วไล่หาบรรทัดเออเรอ ไม่เจอ ผมใช้วิธีการ

โค๊ด:
die("ผ่าน");

ไล่ทีละแถวเลยครับ  :wanwan020: :wanwan020: :wanwan020:

ต้องไล่ทีละแถวแบบนี้คะ ได้หรือยังคะ


หัวข้อ: Re: [PHP] เขียนอะไรผิดครับ ช่วยที ไม่มีค่าแสดงออกมา!!!!
เริ่มหัวข้อโดย: dekjaidee ที่ 21 กรกฎาคม 2018, 08:45:21
ตอนผมหัด php ใหม่ๆ แล้วไล่หาบรรทัดเออเรอ ไม่เจอ ผมใช้วิธีการ

โค๊ด:
die("ผ่าน");

ไล่ทีละแถวเลยครับ  :wanwan020: :wanwan020: :wanwan020:

ต้องไล่ทีละแถวแบบนี้คะ ได้หรือยังคะ

งงจริงๆ ครับ

อ้างถึง
<?
require_once "connectdb.php";

$number="$_POST[number]";

$loop=strlen($number)-1;
for($i=0;$i<$loop;$i++)
{
$strs = substr($number,$i,2);

$sqlhr="select distinct numb,numtxt from horotest where numb='$strs'";
   $db_query=mysql_query($sqlhr);
    $reshr=mysql_fetch_array($db_query);
    $numbb = $reshr[numb];
   $numtxt = $reshr[numtxt];
   echo "$numbb<br>";

}
?>

INPUT ค่า  1111 เข้ามา มันก็ยังเป็น
11
11
11

แทนที่จะเป็น 11 แถวเดียวครับ

 :P :P


หัวข้อ: Re: [PHP] เขียนอะไรผิดครับ ช่วยที ไม่มีค่าแสดงออกมา!!!!
เริ่มหัวข้อโดย: snohomish ที่ 21 กรกฎาคม 2018, 11:30:38
อ้างถึง
<?
require_once "connectdb.php";

$number="$_POST[number]";

$loop=strlen($number)-1;
for($i=0;$i<$loop;$i++)
{
$strs = substr($number,$i,2);

$sqlhr="select distinct numb,numtxt from horotest where numb='$strs'";
   $db_query=mysql_query($sqlhr);
    $reshr=mysql_fetch_array($db_query);
    $numbb = $reshr[numb];
   $numtxt = $reshr[numtxt];
   echo "$numbb<br>";

}
?>

ลองสร้างเงื่อนไขใน loop ดูครับ


หัวข้อ: Re: [PHP] เขียนอะไรผิดครับ ช่วยที ไม่มีค่าแสดงออกมา!!!!
เริ่มหัวข้อโดย: Mrpoohling ที่ 23 กรกฎาคม 2018, 11:08:03
ได้หรือยังครับ