Answer the question
In order to leave comments, you need to log in
Why are there 30+ elements in the database and why does count see only 2 and also does not work out the search in the array?
<?php
$host="localhost";
$user="root";
$pass="";
$db_name="base";
$link=mysql_connect($host,$user,$pass);
mysql_select_db($db_name,$link);
?>
<? $i=23//для примера
$result = mysql_query(" SELECT i FROM tablebase");
$iDb = mysql_fetch_array($result);
foreach ($iDb as $key => $value) {
if (in_array(23,$iDb)) {
$insert_sql = "INSERT INTO tablebase (i)" .
"VALUES('{$i}');";
mysql_query($insert_sql);
echo $i;
}
}
?>
<?echo count($iDb);?>
Answer the question
In order to leave comments, you need to log in
Here's another option:
$host = "localhost";
$user = "root";
$pass = "";
$db_name = "base";
$db = mysql_connect($host,$user,$pass);
mysql_select_db($db_name,$db);
$id = 23; // для примера
$res = mysql_query(" SELECT id FROM table_name");
while ($item = mysql_fetch_array($res))
{
if ($item['id'] == $id)
{
$query = "INSERT INTO table_name (id) VALUES('{$id}')";
mysql_query($insert_sql);
echo $i . ", ";
}
}
echo "<br>" . mysql_num_rows($res);
if (in_array(23, $value))
Generally strange code, it's not quite clear what you are trying to do.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question