首页 \ 问答 \ 使用PHP,mysqli和mysqli_fetch_assoc显示主题列表(Displaying a list of topics with PHP, mysqli and mysqli_fetch_assoc)

使用PHP,mysqli和mysqli_fetch_assoc显示主题列表(Displaying a list of topics with PHP, mysqli and mysqli_fetch_assoc)

我正在努力建立一个准系统论坛。 我有一个非常简单的数据库叫做talk,有一个叫做main的表,有一个名为title,content和id的列。 $ con是我的连接,我很肯定它有效,因为我用它在我的代码中的其他地方插入数据库。

我试图显示该表的所有标题,以及该主题页面的链接,基本上为我的论坛制作主题列表。 我没有得到任何东西,而是没有给我一张显示每个标题的表格。 它只是空白。 我上下搜索谷歌和stackoverflow,找到了几个相关的问题,都有完全不同的解决方案,但没有发现任何适合我的东西。 我已经尝试了这段代码的其他一些措辞,但这似乎是我认为最接近工作的代码。 这应该是您需要查看的所有代码,但如果您需要更多信息,请告诉我们。

<?php 
$sql = "SELECT 
            title,
            content,
            id 
            from main
            ORDER BY id DESC;"

if ($result = mysqli_query($con, $sql))
{
echo '<table class="table table-striped">
<tr>
<td>
<h4><strong><center>';

while($row = mysqli_fetch_assoc($result)) {
    echo '<a href="topic.php?id=' . $row['id'] . '">
    ' . $row['title'] . '</a>'

echo '</center></strong></h4>
</td>
</tr>';
}
echo '</table>';
}
?>

感谢您的帮助stackoverflow。


I am trying to make a barebones forum. I have a very simple database called talk, with a table called main, with columns called title, content, and id. $con is my connection, and I'm positive it works because I use it to insert into the database elsewhere in my code.

I am trying to display all the titles of this table, along with a link to that topics page, essentially making a topics list for my forum. Instead of giving me a table that displays each title, I get nothing. It's just blank. I've searched google and stackoverflow up and down, have found several related questions, all with wildly different solutions, but haven't found anything that works for me. I've tried a few other wordings of this code, but this seems to be the code that I think is closest to working. This should be all the code you need to see, but if you need more information, let me know.

<?php 
$sql = "SELECT 
            title,
            content,
            id 
            from main
            ORDER BY id DESC;"

if ($result = mysqli_query($con, $sql))
{
echo '<table class="table table-striped">
<tr>
<td>
<h4><strong><center>';

while($row = mysqli_fetch_assoc($result)) {
    echo '<a href="topic.php?id=' . $row['id'] . '">
    ' . $row['title'] . '</a>'

echo '</center></strong></h4>
</td>
</tr>';
}
echo '</table>';
}
?>

Thank you for your help stackoverflow.


原文:
更新时间:2022-03-27 06:03

最满意答案

你在寻找的是一个Reader-Writer锁 。 互联网上有一些实现,例如这个


What you are looking for is a Reader-Writer lock. There are some implementations of it on the internet, for example this one.

相关问答

更多
  • 要允许多个读取器和一个写入器同时访问数据库,请启用预写日志 。 WAL适用于小型交易,因此您不需要累积写入。 请注意,WAL不适用于网络文件系统,为了获得最佳性能,需要定期检查点。 To allow multiple readers and one writer to access the database concurrently, enable write-ahead logging. WAL works well with small transactions, so you don't need t ...
  • 首先,可能认为本地机器大小的读写是原子的,但是处理器/内核之间的缓存一致性有很多问题需要处理。 在Windows上使用Interlocked *等原子操作,在Linux上使用等价的操作。 C ++ 0x将有一个“原子”模板来将它们包装在一个漂亮的跨平台界面中。 现在,如果您正在使用平台抽象层,它可能会提供这些功能。 ACE确实,看到类模板ACE_Atomic_Op 。 At first one might think that reads and writes of the native machine s ...
  • 锁定相当复杂 。 很有可能,SQL Server每页锁定你的表。 这意味着写入一个页面不会阻止对其他页面的读取。 最佳做法是监视日志中的死锁 。 如果没有发生死锁,则不需要自定义锁定。 如果出现死锁,您将遇到特定的问题需要解决。 解决方案可能涉及使用表提示修改查询,配置SQL Server或更改逻辑。 但如果不知道细节,这是不可能的。 Locking is quite complicated. Likely, SQL Server locks your table per page. That means ...
  • 当RxAndroidBle库启动时, RxAndroidBle库中没有Single或Completable类。 这些结构很适合RxAndroidBle并且已经计划好了,但是它需要来自库的作者的一些工作,并且会改变API - 将要求版本碰撞为2.0.0。 When the RxAndroidBle library was started there were no Single nor Completable classes in the RxJava library. These constructs wo ...
  • 就像引用“测量改变状态”一样,你必须先浪费一个写,以证明你可以正确地读回来。 擦除单元将所有位设置为1,以便可以写入0x00,检查所有位是否符合您的期望,然后写入0xFF完成一个完整周期。 如果该单元已经'清除'到0xFF,那么该单元仍然是好的。 但是,如果将实际数据放入其中,则无法保证下一次写入会起作用。 跟踪每个单元/块的状态并验证写入内容是通常在磨损均衡例程中实现的内容的一部分,并允许您尽可能长时间提供数据完整性。 Just like the quote, "measurement changes s ...
  • 您正在打开包含数据的现有文件。 你正在覆盖它(没有O_APPEND)。 因此,在编写X数据时,文件系统需要获取内容(=块),将其写入,然后将块推回磁盘。 You are opening an existing file, with data. You are overwriting it (no O_APPEND). Thus, when writing X data, a filesystem needs to get the content (= block), put your writing ove ...
  • 这里涉及很多因素。 例如,缓存中的索引数据是? 数据块是否在缓存中? 查询检索了多少行? 锄头等行中的许多行我已经被问过这个问题(或它的一个变种)多次。 我宁愿提供一些信息,以便提出问题的人可以做出明智的决定,而不是给出号码。 这是一个“信封的背面”计算示例,其中包含一些假设条件。 可以说,这个桌子有100M行 可以说一行平均是200字节 比表示消耗大约19GB(忽略任何压缩) 让我们假设这个索引是完全缓存的,并且需要零时间 让我们假设数据必须从磁盘读取,每读取5ms 让我们假设您的IO子系统可以以10 G ...
  • 你是完全正确的,它没有记录的那样。 我认为Play的JSON组合器仍然处于不稳定的状态,因此文档可能会受到影响。 快速修复:将creatureWrites更改为def ,因此允许“前向引用”(这是一个递归函数调用): implicit def creatureWrites: Writes[Creature] = ( ... ) You're completely right, it doesn't work as documented. I think Play's JSON Combinators ...
  • 你在寻找的是一个Reader-Writer锁 。 互联网上有一些实现,例如这个 。 What you are looking for is a Reader-Writer lock. There are some implementations of it on the internet, for example this one.
  • 首先,就名称而言,我倾向于使用EventsIO或类似的东西。 或者,正如Adriano建议的那样,您可以将两者连接在一起并使其成为ReaderWriter。 然而,这对我来说并不像你所描述的那样重要...... 我的真实建议 我建议真正看看常见功能是什么。 在没有看到你的代码的情况下我不能100%确定地说这个,但看起来你应该使用Composition over Inheritance ,或者在你的情况下使用组合而不是组合。 您可以将EventsReader和EventsWriter保留为使用处理常用功能的类 ...

相关文章

更多

最新问答

更多
  • 您如何使用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)