下面这段代码,为什么不会输出我想要的数据?
<?
//连接到本地mysql数据库
$myconn=mysql_connect("localhost","root","");
//选择test为操作库
mysql_select_db("test",$myconn);
$fir='select * from first where id=2';
$sec='select * from second where id=3';
//
?>
<li><?echo $fir.$sec?></li>

<li><?echo $fir.$sec?></li>输出如下:
select * from first where id=2select * from second where id=3 select * from first where id=2select * from second where id=3 

解决方案 »

  1.   

    建议看一下PHP的教程和mysql在PHP中的操作<?php
    // Connecting, selecting database
    $myconn = mysql_connect('localhost', 'root', '')
        or die('Could not connect: ' . mysql_error());
    echo 'Connected successfully';
    mysql_select_db('test',$myconn) or die('Could not select database');// Performing SQL query
    $query = 'select * from first where id=2';
    $result = mysql_query($query) or die('Query failed: ' . mysql_error());// Printing results in HTMLwhile ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
        foreach ($line as $col_value) {
            echo "<li>$col_value</li>\n";
        }
    }// Free resultset
    mysql_free_result($result);// Closing connection
    mysql_close($myconn);
    ?>
      

  2.   


    <? 
    $myconn=mysql_connect("localhost","root",""); 
    mysql_select_db("test",$myconn); 
    $fir='select * from first where id=2'; 
    $sec='select * from second where id=3'; 
    $result1=$myconn.query($fir);
    $result2=$myconn.query($sec);
    $row1 = $result1->fetch_row();
    $row2 = $result2->fetch_row();
    ?> 
    <li> <?echo $row1[0].$row2[0]?> </li> <li> <?echo $row1[0].$row2[0]?> </li> 
    省去了很多判断语句,仅供功能测试
      

  3.   

    运行时报错:
    Fatal error: Call to a member function on a non-object in d:\usr\www\html\showname.php on line 60
    请问:->这是运算符吗?是什么意思?我刚接触Php,还请赐教,谢谢!
      

  4.   

    $result1=$myconn->query($fir); 
      

  5.   

    直接 $result1=mysql_query($fir);
      

  6.   

    修改后第62行又出错($row1 = $result1->fetch_row();)
    Fatal error: Call to a member function on a non-object in d:\usr\www\html\showname.php on line 62请教!
      

  7.   


    $row1 = mysql_fetch_row($result1);
      

  8.   

    谢谢,已经可以运行了。我是刚接触php,在请教一下 -> 是啥意思?
      

  9.   

    不是,是方法的引用。建议参考一下PHP的帮助手册。 否则在这贴出来也是一大堆文字来解释。