如何在PHP中回显两列SQL数据与两者的区别

如何在PHP中回显两列SQL数据与两者的区别

问题描述:

Can someone help with the following code. Im simply trying to display the total number of values between the starting num and ending num. ie: If the start is 200 and end is 205, I need to print 200,201,202,203,204 and 205 on the screen. Please assist with the following code

<?php

$con=mysql_connect('localhost','root') or die ("Server connection failure!");
$db=mysql_select_db('regional_data',$con) or die ("Couldn't connect the database");
$SQL="SELECT startnum, endnum FROM newchk";
$run=mysql_query($SQL,$con) or die ("SQL Error");
$nor=mysql_num_rows($run);


while ($rec = mysql_fetch_array($run))
{
    for($i=$rec['startnum']; $i=$rec['endnum']; $i++)
    {
    echo $i;
    }
}

?> 

有人可以帮助您使用以下代码。 我只是试图显示起始数和结束数之间的总值。 即:如果开始是200,结束是205,我需要在屏幕上打印200,201,202,203,204和205。 请协助以下代码 p>

 &lt;?php 
 
 $ con = mysql_connect('localhost','root')或die(“服务器连接失败!”  ); 
 $ db = mysql_select_db('regional_data',$ con)或死(“无法连接数据库”); 
 $ SQL =“SELECT startnum,endnum FROM newchk”; 
 $ run = mysql_query(  $ SQL,$ con)或die(“SQL Error”); 
 $ nor = mysql_num_rows($ run); 
 
 
while($ rec = mysql_fetch_array($ run))
 {
 for($  i = $ rec ['startnum']; $ i = $ rec ['endnum']; $ i ++)
 {
 echo $ i; 
} 
} 
 
?&gt;  
  code>  pre> 
  div>

You missed the < in your for loop condition.

for($i=$rec['startnum']; $i<=$rec['endnum']; $i++)
{
    echo $i;
}

Note: the code dose not contain comma in the output, it will produce 200201202203204205 in the screen.

If you want to print comma concentrated string, you could do:

echo implode(',', range($rec['startnum'], $rec['endnum']));