从数据库打印数据到网页问题 [英] Print data from databaseto webpage problem

查看:79
本文介绍了从数据库打印数据到网页问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
我写了这段代码来显示我数据库中来自数据库的数据
这是我的代码:

hi
I wrote this code to show data from data base in my webpage
this is my code:

<br />
<pre lang="php">@ $db=mysql_pconnect(''localhost'',''bookshop'');<br />
        if (!$db)<br />
        {<br />
            echo ''Error: coud not connect to database. please try again later.'';<br />
            exit;<br />
        }<br />
        mysql_select_db(''bookshop'');<br />
        $query="select * from books where ".$searchtype." like ''%".$searchterm."%''";<br />
        $result=mysql_query($query);<br />
        $num_results=mysql_num_rows($result);<br />
        echo ''<p>Number of books found: ''.$num_results.''</p>'';<br />
        for ($i=0;$i<1;$i++)<br />
        {<br />
            $row=mysql_fetch_array($result);<br />
            echo ''<p><strong>''.($i+1).''.title: '';<br />
            echo htmlspecialchars(stripslashes($row[''title'']));<br />
            }</pre><br />
<br />


但我有这个错误


but I had this erors

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\chapter1\resultpage.php on line 35
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\chapter1\resultpage.php on line 39


我该怎么办
我使用mysql_eror()函数检查了结果,然后看到以下消息:没有选择数据库,如何选择数据库


what can I do with this problem
I checked result with mysql_eror() function and I saw this message: No database selected how I can select the database

推荐答案

db = mysql_pconnect(''localhost, "书店");< br/> 如果(!
db=mysql_pconnect(''localhost'',''bookshop'');<br /> if (!


db)< br/> {< br/> echo''错误:无法连接数据库.请稍后再试.'';< br/> 出口;< br/> }< br/> mysql_select_db(''bookshop'');< br/>
db)<br /> {<br /> echo ''Error: coud not connect to database. please try again later.'';<br /> exit;<br /> }<br /> mysql_select_db(''bookshop'');<br />


query ="select * from图书在.
query="select * from books where ".


这篇关于从数据库打印数据到网页问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆