Home > Backend Development > PHP Tutorial > 求教一个php调用数据库输出的有关问题

求教一个php调用数据库输出的有关问题

WBOY
Release: 2016-06-13 10:15:52
Original
2558 people have browsed it

求教一个php调用数据库输出的问题
目的是做一个 选择范围然后 通过这些范围查询数据库并格式化输出结果的

但是做到输出就出问题了 弄了半天很不理解
以下是错误部分代码

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->mysql_query('set names gbk',$conn);mysql_select_db('htc',$conn);$count = 'select count(*) from phone';$query = mysql_query($count,$conn);//记录总数$recordcount = mysql_result($query, 0,0);//每页多条$pagesize = 5;//总页数$pagecount = ceil($recordcount/$pagesize);//当前页$currpage = 1;if($_GET){    $currpage = (int)$_GET['p'];    }    $currpage = $currpage$pagecount ? $pagecount : $currpage;                        $start = ($currpage-1)*$pagesize;    $sql = "select * from phone order by id desc limit $start,$pagesize";    $result = mysql_query($sql,$conn);    while($row=mysql_fetch_array($result)){    foreach ($row as $k=>$va){    //echo '<pre class="brush:php;toolbar:false">';    //print_r($row);                                echo "<div class="p_list">";    echo "<div class="p_list_pic"><a><img  src="." alt="求教一个php调用数据库输出的有关问题" >"."</a></div>";    echo "<div class="p_list_con">        <p class="p_list_con_title">$va[1]</p>
<br>            $va[4],$va[5]<br>            $va[6],$va[7]<br>            $va[8],$va[9]<br>              <p class="p_list_con_state">$va[10]</p>
</div>";            echo "<div>售价:¥$va[3]<br>            <img  src="image/gm.gif" alt="求教一个php调用数据库输出的有关问题" >
</div>";            echo "</div>";            //echo '
Copy after login
'; } } echo '首页 '; echo '下页 '; echo '上页 '; echo "末页  "; echo "[{$currpage}/{$pagecount}][共{$recordcount}记录,每页{$pagesize}条]"; ?>

错误提示是很多行  
但基本上都是提示说


Notice: Uninitialized string offset: 6 in D:\Program Files\Apache\htdocs\pro\phone_zone.php on line 183

Notice: Uninitialized string offset: 7 in D:\Program Files\Apache\htdocs\pro\phone_zone.php on line 183

求教

------解决方案--------------------
while($row=mysql_fetch_array($result)){//mysql_fetch_array($result)返回的是一维数组
foreach ($row as $k=>$va){//所以$va是单值数据
//echo '
';<br>   //print_r($row);<br>                          <br>   echo "<div class="p_list">";<br>   echo "<div class="p_list_pic"><a><img  src="." alt="求教一个php调用数据库输出的有关问题" >"."</a></div>";<br>   echo "<div class="p_list_con">
<br>       <p class="p_list_con_title">$va[1]</p>
<br><br>           $va[4],$va[5]<br><br>           $va[6],$va[7]<br>//所以$va[6],$va[7]只能是单个字符,如果$val没有那么长,则就要报错了<br><br>我认为你的本意应该是<br><br>   while($val=mysql_fetch_array($result)){<br>   //foreach ($row as $k=>$va){<br><br>也就是说:$va[6],$va[7]是第6,7个字段的值<br><font color="#e78608">------解决方案--------------------</font><br>去掉foreach那层循环。<br>while($va = mysql_fetch_row($result) ){<br>// ...<br>}<br><br>至于你#2说的问题,我不会正则表达式所以帮不上忙<br><font color="#e78608">------解决方案--------------------<div class="clear">
                 
              
              
        
            </div></font>
</div>
</div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template