I want to do a trap that if the array has a value the same within the database. they will then proceeded to the if condition I build. So far this is my code.
我想做一个陷阱,如果数组在数据库中有相同的值。然后,他们将继续进行我所构建的if条件。到目前为止,这是我的代码。
$a = $_POST['a'];
$b = $_POST['b'];
foreach ($_POST['b'] as $b)
{
$result = mysql_query("select * from ehr_schedule3 where (sched3_time='$b' and sched2_id='$a') ");
$row = mysql_fetch_array($result);
$num = mysql_num_rows($result);
}
if(strpos($b, $result)==true) //$b is the array value I will insert to the db.
{
header("Location: ../edit_sched2.php?asdfghjkl=".$a."?false");
$_SESSION["A"] = "E" ;
}
I don't know how to play with array in the mysql_query. I just want to proceed it to if
if there is just one of the same value. I originally planning to make it a string so that if the strpos
have confirmed it has the same value, it will proceed then to the if
我不知道如何在mysql_query中使用数组。我只是想让它,如果有一个相同的值。我本来计划把它做成一个字符串,这样如果strpos确认它有相同的值,它就会继续到if。
1 个解决方案
#1
0
I think one day you could use a DISTINCT
clause in your query so you would not get duplicates. By the way, you should use mysqli
since mysql_functions are deprecated. I want to comment for clarification so I can help you more but I don't have 50 reputation yet. So for my understanding so far this is what I would do:
我认为有一天你可以在你的查询中使用一个不同的子句,这样你就不会得到重复了。顺便说一下,您应该使用mysqli,因为mysql_functions已经被废弃了。我想澄清一下,这样我可以帮助你更多,但是我还没有50个名声。到目前为止,我的理解是:
$a = $_POST['a'];
$b = $_POST['b'];
$query = "SELECT schedule3_time, schedule2 FROM ehr_schedule3 WHERE sched3_time LIKE $a and sched2_time LIKE $b "
$key = mysqli_connect($host, $user, $passwd, $database)
or die(mysql_error); /*your credientials */
foreach ($_POST['b'] as $b)
{
$result = mysqli_query($key, $query);
$row = mysqli_fetch_array($result);
$num = mysqli_num_rows($result);
}
if(strpos($b, $result)==true) {
$sql = "INSERT INTO tablename (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')"; /* put your table here*/
if (mysqli_query($key, $query)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$key->close();
} //$b is the array value I will insert to the db.
{
header("Location: ../edit_sched2.php?asdfghjkl=".$a."?false");
$_SESSION["A"] = "E" ;
}
Check out this post to help you with your question.
看看这篇文章,帮你解决问题。
#1
0
I think one day you could use a DISTINCT
clause in your query so you would not get duplicates. By the way, you should use mysqli
since mysql_functions are deprecated. I want to comment for clarification so I can help you more but I don't have 50 reputation yet. So for my understanding so far this is what I would do:
我认为有一天你可以在你的查询中使用一个不同的子句,这样你就不会得到重复了。顺便说一下,您应该使用mysqli,因为mysql_functions已经被废弃了。我想澄清一下,这样我可以帮助你更多,但是我还没有50个名声。到目前为止,我的理解是:
$a = $_POST['a'];
$b = $_POST['b'];
$query = "SELECT schedule3_time, schedule2 FROM ehr_schedule3 WHERE sched3_time LIKE $a and sched2_time LIKE $b "
$key = mysqli_connect($host, $user, $passwd, $database)
or die(mysql_error); /*your credientials */
foreach ($_POST['b'] as $b)
{
$result = mysqli_query($key, $query);
$row = mysqli_fetch_array($result);
$num = mysqli_num_rows($result);
}
if(strpos($b, $result)==true) {
$sql = "INSERT INTO tablename (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')"; /* put your table here*/
if (mysqli_query($key, $query)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$key->close();
} //$b is the array value I will insert to the db.
{
header("Location: ../edit_sched2.php?asdfghjkl=".$a."?false");
$_SESSION["A"] = "E" ;
}
Check out this post to help you with your question.
看看这篇文章,帮你解决问题。