求教一个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="/static/imghwm/default1.png" data-src="." class="lazy" 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 ''; } } 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="/static/imghwm/default1.png" data-src="." class="lazy" 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>

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP is not dying, but constantly adapting and evolving. 1) PHP has undergone multiple version iterations since 1994 to adapt to new technology trends. 2) It is currently widely used in e-commerce, content management systems and other fields. 3) PHP8 introduces JIT compiler and other functions to improve performance and modernization. 4) Use OPcache and follow PSR-12 standards to optimize performance and code quality.

The future of PHP will be achieved by adapting to new technology trends and introducing innovative features: 1) Adapting to cloud computing, containerization and microservice architectures, supporting Docker and Kubernetes; 2) introducing JIT compilers and enumeration types to improve performance and data processing efficiency; 3) Continuously optimize performance and promote best practices.

In PHP, trait is suitable for situations where method reuse is required but not suitable for inheritance. 1) Trait allows multiplexing methods in classes to avoid multiple inheritance complexity. 2) When using trait, you need to pay attention to method conflicts, which can be resolved through the alternative and as keywords. 3) Overuse of trait should be avoided and its single responsibility should be maintained to optimize performance and improve code maintainability.

Dependency Injection Container (DIC) is a tool that manages and provides object dependencies for use in PHP projects. The main benefits of DIC include: 1. Decoupling, making components independent, and the code is easy to maintain and test; 2. Flexibility, easy to replace or modify dependencies; 3. Testability, convenient for injecting mock objects for unit testing.

SplFixedArray is a fixed-size array in PHP, suitable for scenarios where high performance and low memory usage are required. 1) It needs to specify the size when creating to avoid the overhead caused by dynamic adjustment. 2) Based on C language array, directly operates memory and fast access speed. 3) Suitable for large-scale data processing and memory-sensitive environments, but it needs to be used with caution because its size is fixed.

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

In JavaScript, you can use NullCoalescingOperator(??) and NullCoalescingAssignmentOperator(??=). 1.??Returns the first non-null or non-undefined operand. 2.??= Assign the variable to the value of the right operand, but only if the variable is null or undefined. These operators simplify code logic, improve readability and performance.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)