通过HREF链接更新MySQL表值 [英] Updating a MySQL table value through HREF link

查看:74
本文介绍了通过HREF链接更新MySQL表值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。


我一直在为希望使用该功能的客户撰写推荐书后端。应该如何工作是这样的:


用户将他们在沙龙的经验证明写入基本的HTML表单。当用户点击发送时,它会运行一个PHP脚本,将其插入MySQL表格。


该表有4个字段:id,msg,name,active


提交推荐书时,活动字段的默认值为0。这使得推荐不活跃。


沙龙所有者想要登录并查看所有待定的推荐(其中active = 0)。然后,她可以单独审查每一个。如果她想接受该推荐,那么她点击激活链接,该链接会将该推荐ID的有效值更新为1而不是0.


当用户来时在网站上,当活动值为1(意味着其活动)时,将拉出一个随机推荐。每次加载页面时,它都将是另一个页面,同样活动值为1.


我的问题是如何将活动值设置为1.我去过尝试了一系列不同的代码,这些代码都是由我为这篇文章编写的,或者是由其他开发者自由发布的简单解决方案。我很茫然,明天早上需要它。


这是我最近尝试过的代码。

Hey everyone.

I have been writing a testimonials backend for a client who wishes to use the feature. How it is supposed to work is like this:

The user writes a testimonial of their experience at the salon into a basic HTML form. When the user clicks send it runs a PHP script inserting it into a MySQL table.

The table has 4 fields: id, msg, name, active

When the testimonial is submitted it obtains a default value of 0 for the ''active'' field. This makes the testimonial ''inactive''.

The salon owner wants to login and see all the pending testimonials (where active = 0). She can then review each one individually. If she wants to accept that testimonial she then clicks on the ''Activate'' link, which will update the active value for that testimonial ID to 1 instead of 0.

When users come to the website one random testimonial will be pulled where the active value is 1 (meaning its active). Each time the page is loaded it will be a different one, again where the active value is 1.

My question is how to set the active value to 1. I''ve been trying an array of different codes, both written by me for this piece or by other developers who''ve freely posted simple solutions. I''m at a loss and it''s needed by tomorrow morning.

Here''s the code for what I have tried, most recently.

展开 | 选择 | Wrap | 行号

推荐答案

您是否只是想更新MySQL表中的值?


如果是这样,请查看 MySQL UPDATE 。否则,你能更简洁地解释一下吗?
Are you just trying to update the value in the MySQL table?

If so, check out MySQL UPDATE. Otherwise, could you explain a little more concisely?


这有点帮助,Markus。它现在更新了表值,但它只是让它从下到上激活。


我的意思是:


我的推荐书垂直显示如下:


---------------------------- ---------

|姓名:Mat |

|这个地方很棒! |

| |

|见证ID 1 |

---------------------------- --------


------------------------------ -------

|姓名:桑迪|

|这个地方是岩石! |

| |

|见证ID 2 |

---------------------------- --------


------------------------------ -------

|姓名:Liz |

|这个地方很酷。 |

| |

|推荐证书3 |

---------------------------- --------



我必须首先激活ID 3,然后激活ID 2,然后激活ID 1.我不能只选择一个来自要激活的列表。假设我想将ID 3和ID 2保留在挂起(活动= 0)并激活ID 1,我必须激活所有三个,然后从单独的页面取消激活ID 3和ID 2。 />

为什么会发生这种情况?
Well that helped a little bit, Markus. It now updates the table value, however it''s only letting it activate from bottom to top.

What I mean is this:

I have the testimonials displayed vertically like so:

-------------------------------------
| Name: Mat |
| this place is great! |
| |
|Testimonial ID 1 |
------------------------------------

-------------------------------------
| Name: Sandy |
| this place is rocks! |
| |
|Testimonial ID 2 |
------------------------------------

-------------------------------------
| Name: Liz |
| this place is cool. |
| |
|Testimonial ID 3 |
------------------------------------


I have to activate ID 3 first, then ID 2, then ID 1. I can''t just choose one from the list to activate. Let''s say I want to leave ID 3 and ID 2 in pending (active = 0) and activate ID 1, I''d have to activate all three and then unactivate ID 3 and ID 2 from a seperate page.

Why''s that happening?


你必须在URL字符串中传递ID ..


所以类似于:


< a href =" testimonialsindex.php?mode = activate& id = ID_OF _THE_RECORD">


然后,当您进行更新时,只更新该ID。
You have to pass the ID in the URL string..

So something like:

<a href="testimonialsindex.php?mode=activate&id=ID_OF _THE_RECORD">

Then when you do the update only update that ID.


这篇关于通过HREF链接更新MySQL表值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆