如何添加PHP代码以允许用户添加喜欢的名称? [英] How can I add PHP code to allow users to add favorite names?
问题描述
所以我有一个名为的表: BabyNames
我有属性: BoyNames,GirlNames,UserID和收藏夹 - 我添加了最后一个两个,所以我可以添加一个最喜欢的选项
在我的PHP脚本中,有一个脚本允许用户选择一个字母,它显示相关的婴儿名称
我也希望他们有一个喜欢的按钮,这样他们就可以存储一些他们喜欢的名字
可以有人帮帮我?同时使用SQL和PHP代码。我是否需要为男孩和女孩的名字分配一个ID?
目前见下面的PHP。
我尝试过:
if(isset($ _ GET [initial])){
$ initial = $ _ GET [initial];
$ dbQuery = $ conn-> prepare(select * from BabyNames Where BoyNames like:initial AND GirlNames like:initial);
$ initial = $ initial。'%';
$ dbParams = array('initial'=> $ initial);
$ dbQuery-> execute($ dbParams);
echo< table border ='1'width ='400'>
< br>< tr>
< th>男孩姓名< / th>
< th>女孩姓名< / th>
< th>女孩姓名< / th>
< / tr>< / br>;
while($ dbRow = $ dbQuery-> fetch(PDO :: FETCH_ASSOC)){
echo< tr>;
echo< td>;
echo $ dbRow [BoyNames]。< td>。$ dbRow [GirlNames];
}
}
_GET [initial])){
初始=
_GET [ 初始];
So i have a table named: BabyNames
I have attributes: BoyNames, GirlNames, UserID and Favourites - i have added the last two in so I can add a favorite option
On my php script, there is script in which allows user to select a letter and it displays the baby names related
I also want them to have a favorite button so they can store some of their favorite names
Can someone help me out? with both SQL and PHP code. Do i need to assign an ID to the boy and girl names?
See below PHP at present.
What I have tried:
if (isset($_GET["initial"])) { $initial=$_GET["initial"]; $dbQuery=$conn->prepare("select * from BabyNames Where BoyNames like :initial AND GirlNames like :initial"); $initial=$initial.'%'; $dbParams=array('initial'=>$initial); $dbQuery->execute($dbParams); echo "<table border='1' width='400'> <br><tr> <th> Boy Names</th> <th> Girl Names</th> <th> Girl Names</th> </tr></br>"; while ($dbRow = $dbQuery->fetch(PDO::FETCH_ASSOC)) { echo "<tr>"; echo "<td>"; echo $dbRow["BoyNames"]."<td>".$dbRow["GirlNames"]; } }
_GET["initial"])) {
initial=
_GET["initial"];
这篇关于如何添加PHP代码以允许用户添加喜欢的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!