简体   繁体   English

如何获得查询的特定值? 在mysql_fetch_array中

[英]How can I get specific values of my query? within mysql_fetch_array

I have a table of 5 x 5 frames, I need to show the name of the book , year and location on each frame,the question is if is posible with just one query like 我有一张5 x 5帧的表格,我需要在每帧上显示书名,年份和位置,问题是是否可以只用一个查询

$res = SELECT * FROM books LIMIT 15

place each value in a random order within the frame or necessarily I have to do many queries, one for name, other for autor, and other for location, finally the out put should be something like the following picture 将每个值以随机顺序放置在框架内,或者我必须做很多查询,一个用于名称,另一个用于导师,以及另一个用于位置,最后输出应该类似于下图

在此处输入图片说明

I am trying to use while and for each but I can achieve the purpose 我正在尝试每次使用,但我可以达到目的

this is a test code 这是一个测试代码

<?php
 include("conexion.php");  
$res = mysql_query ("SELECT * FROM catalogos  ",$conexion);
$arreglo = array();
while($row=mysql_fetch_array($res)){
$arreglo[] = $row;
}
foreach ($arreglo as $rows){
$dato1= $rows[1];
$dato2=$rows[6];
$dato3=$rows[7];
}

and this is the test table 这是测试表

<table width="657" height="71" border="1">
  <tr>
    <td><? echo"$data1";?></td>
    <td><? echo "$data2";?></td>
    <td><? echo "$data3";?></td>
  </tr>
</table>

but in data 2 and 3 there is no values 但在数据2和3中没有值

Use this before foreach... 在上课之前使用它...

shuffle($arreglo);

You will get different values every times. 每次您将获得不同的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM