douwen1915 2013-08-27 10:57
浏览 52
已采纳

从两个不同的表中选择并显示

i have 2 different table named productlist and rsales

the ff data in productlist are

id|pcode|
1 |1220 |

and the ff data in rsales are

id|total|total_discount|
3 |500  |      50      |

my problem is that i want to select data from two different table which is productlist and rsales and display it horizontally. i tried everything but it display vertically. the result must be something like this

id|pcode|total|total_discount|
1 |1220 |500  |   50         | 

this is my code so far but it only display data from single table

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("inventory", $con);



$result = mysql_query("SELECT * FROM productlist");

while($row = mysql_fetch_array($result))
  {
echo '<tr>';
echo '<td>'.$row['pcode'].'</td>';
echo '</tr>';
  }

mysql_close($con);
?>
  • 写回答

3条回答 默认 最新

  • doushenjia8514 2013-08-27 11:10
    关注

    there is no link between rsales and produclist but you can try like this, you will get all fileds from both the tables using this

    $result = mysql_query("SELECT * FROM productlist,rsales");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错