首页 \ 问答 \ PHP来自多个表,但在同一个数据库中(PHP results from multiple tables but in the same database)

PHP来自多个表,但在同一个数据库中(PHP results from multiple tables but in the same database)

我有我的PHP SELECT查询工作,但我需要它显示超过1表的数据。

$sql = "SELECT * from paymentPersonal where `custID`='$custID'";

$result = $conn->query($sql);

if ($result->num_rows > 0) {
     // output data of each row
     while($row = $result->fetch_assoc()) {
         echo "<br> custID: ". $row["custID"]. " - FirstName: ". $row["firstname"]. " LastName" . $row["lastname"] .  " - Mobile: ". $row["mobile"]. " - homephone: ". $row["homephone"]. " - Email: ". $row["email"]."<br>";

这是显示1表的数据的代码,但我需要几个,我试过将它更改为此,看看它会显示更多的表:

$sql = "SELECT * from `paymentPersonal`, `paymentsPayment` where `custID`='$custID'";

    $result = $conn->query($sql);

    if ($result->num_rows > 0) {
         // output data of each row
         while($row = $result->fetch_assoc()) {
             echo "<br> custID: ". $row["custID"]. " - FirstName: ". $row["firstname"]. " LastName" . $row["lastname"] .  " - Mobile: ". $row["mobile"]. " - homephone: ". $row["homephone"]. " - Email: ". $row["email"]."<br>";

             echo "<br> custID: ". $row["custID"]. " - CcName: ". $row["nameoncard"]. " CcNumber" . $row["ccnumber"] .  " - ccYear: ". $row["year"]. " - ccMonth: ". $row["month"]. " - ccCode: ". $row["code"]."<br>";

但没有任何运气只是得到一个错误说;

Notice: Trying to get property of non-object in /Applications/XAMPP/xamppfiles/htdocs/horizonphotography/findingcode.php on line 19
0 results

(仅供参考,所有表格中的custID )如果您对如何在其他表格上显示数据有所了解,请提供帮助! 谢谢!


ive got my php SELECT query working but i need it to display more then 1 table worth of data.

$sql = "SELECT * from paymentPersonal where `custID`='$custID'";

$result = $conn->query($sql);

if ($result->num_rows > 0) {
     // output data of each row
     while($row = $result->fetch_assoc()) {
         echo "<br> custID: ". $row["custID"]. " - FirstName: ". $row["firstname"]. " LastName" . $row["lastname"] .  " - Mobile: ". $row["mobile"]. " - homephone: ". $row["homephone"]. " - Email: ". $row["email"]."<br>";

this is the code that displays the data for the 1 table but i need serveral and ive tried changing it to this to see wether it would display more tables:

$sql = "SELECT * from `paymentPersonal`, `paymentsPayment` where `custID`='$custID'";

    $result = $conn->query($sql);

    if ($result->num_rows > 0) {
         // output data of each row
         while($row = $result->fetch_assoc()) {
             echo "<br> custID: ". $row["custID"]. " - FirstName: ". $row["firstname"]. " LastName" . $row["lastname"] .  " - Mobile: ". $row["mobile"]. " - homephone: ". $row["homephone"]. " - Email: ". $row["email"]."<br>";

             echo "<br> custID: ". $row["custID"]. " - CcName: ". $row["nameoncard"]. " CcNumber" . $row["ccnumber"] .  " - ccYear: ". $row["year"]. " - ccMonth: ". $row["month"]. " - ccCode: ". $row["code"]."<br>";

but without any luck just getting an error saying;

Notice: Trying to get property of non-object in /Applications/XAMPP/xamppfiles/htdocs/horizonphotography/findingcode.php on line 19
0 results

(FYI the custID is in all of the tables) if you have an idea on how to display the data on this other table please help! thank you!


原文:https://stackoverflow.com/questions/37022063
更新时间:2021-09-09 19:09

最满意答案

我不熟悉croniter,但freezegun可以帮助解决这个问题 - 它使用freezegun.api.FakeDatetime实例修补对datetime.datetime所有引用,因此在some_code() ,任何datetime.datetimes都应该使用freezegun.api.FakeDatetime实例freezegun.api.FakeDatetime 。 从经验来看,如果你使用freezegun试图模拟时间的流逝,你也可以避免许多令人头疼的间歇性测试失败。

from datetime import datetime, timedelta
from freeze_gun import freeze_time
from other_module import some_code

fake_today = datetime.datetime(2017, 7, 11)
with_freeze_time(fake_today):
    some_code()
# simulate passage of time to tomorrow
with_freeze_time(fake_today + timedelta(days=1))
    some_code()

I'm not familiar with croniter, but freezegun may help with this— it patches all references to datetime.datetime with instances of freezegun.api.FakeDatetime, so within some_code(), any datetime.datetimes should use instances of freezegun.api.FakeDatetime. Speaking from experience, you'll also save yourself lots of headaches with intermittent test failures when trying to simulate the passage of time if you use freezegun.

from datetime import datetime, timedelta
from freeze_gun import freeze_time
from other_module import some_code

fake_today = datetime.datetime(2017, 7, 11)
with_freeze_time(fake_today):
    some_code()
# simulate passage of time to tomorrow
with_freeze_time(fake_today + timedelta(days=1))
    some_code()

相关问答

更多
  • 答案是相对简单的。 秒表使用性能计数器对处理器计时器进行计数,处理器之间的机制不同。 DateTime查询系统时钟 - 系统时钟由主板上(可能是石英)水晶时钟的输出通过窗口定期更新。 所有时钟漂移,这两种不同的时序机制将以不同的速率漂移。 在引擎盖下, Stopwatch 使用这个API Stopwatch类帮助操纵托管代码中与时间相关的性能计数器。 具体而言,可以使用Frequency字段和GetTimestamp方法来代替非托管Win32 API QueryPerformanceFrequency和Qu ...
  • 对于单元测试,我建议你看一看Microsoft Moles ,一个隔离框架,它可以让你用你自己的代理来替换对DateTime.Now的调用,它可以返回你想要的任何日期。 For unit testing I would recommend you to take a look at Microsoft Moles, an isolation framework that would let you replace a call to DateTime.Now with your own delegate w ...
  • 这可能是系统上time.sleep的限制,而不是datetime.now() ......或两者兼而有之。 您运行的是什么操作系统以及Python的哪个版本和发行版? 您的系统可能不提供time.sleep文档中提到的“亚秒级精度”: sleep(...) sleep(seconds) Delay execution for a given number of seconds. The argument may be a floating point number for sub ...
  • 我不熟悉croniter,但freezegun可以帮助解决这个问题 - 它使用freezegun.api.FakeDatetime实例修补对datetime.datetime所有引用,因此在some_code() ,任何datetime.datetimes都应该使用freezegun.api.FakeDatetime实例freezegun.api.FakeDatetime 。 从经验来看,如果你使用freezegun试图模拟时间的流逝,你也可以避免许多令人头疼的间歇性测试失败。 from datetime ...
  • DateTime.Now不是属性,它是静态只读属性。 在封面下,readonly属性只是一个返回值的函数调用,因此它可以进行任何想要的处理。 希望这可以帮助。 DateTime.Now isn't an attribute, it's a static readonly property. Under the covers a readonly property is just a function call that returns a value, so it can do any amount of ...
  • 如果DateTime.Kind既不是Utc也不是Local,则省略UTC偏移量(例如,“ - 05:00 ”或“Z”)。 您可以按如下方式创建此类DateTime值: DateTime.UtcNow.ToString("o"); // "2012-02-08T19:19:38.5767158Z" new DateTime(DateTime.UtcNow.Ticks).ToString("o"); // "2012-02-08T19:19:38.5767158" new DateTime(DateTime ...
  • 最简单的方法是查询一系列日期: game.select().where(game.created_at.between( datetime.date.today(), datetime.date.today() + datetime.timedelta(days=1)) The easiest way is query a range of dates: game.select().where(game.created_at.between( datetime.date.today ...
  • 如果您查看此MSDN文章,您会发现它( 强调我的 ): 在内部, DateTime值表示为自0001年1月1日午夜12:00:00起经过的刻度数(100纳秒间隔的数量) 。 实际的DateTime值与在用户界面元素中显示或写入文件时该值的显示方式无关。 DateTime值的出现是格式化操作的结果。 格式化是将值转换为字符串表示的过程。 由于日期和时间值的出现取决于诸如文化,国际标准,应用程序要求和个人偏好等因素,因此DateTime结构通过其ToString方法的重载在格式化日期和时间值方面提供了极大的灵活 ...
  • 时间戳是一个有用的元数据。 它不是 - 正如您所发现的 - 可靠的订购标准。 想象一下,你在你的机器上想出了一些解决方案,但现在必须使用两台机器? 你可以让他们的时钟在一纳秒内保持同步吗? 减? 在事件源中,典型的保证仅是事件在单个流中排序,例如一个聚合。 无论如何,这是您的交易保证。 为什么不使用整数来跟踪流中的每个事件的序列? 您的聚合可以生成它,因为它一直在跟踪所有事件。 如果您希望跨流进行排序,则必须集中生成该序列号(使用表示的耦合),或者接受多个流的多次读取并不总是以相同的顺序返回事件,只是一个流 ...
  • 它与DateTime.Now相同。 从DateTime获取刻度并将其放在构造函数中将为您提供相同的日期时间: msdn => DateTime(int64 ticks) 但是,您可以从DateTime.Now中丢失时区感知: The Kind property is initialized to Unspecified. For applications in which portability of date and time data or a limited degree of time zone ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)