W
W
Web_Questions2015-10-03 01:33:45
PHP
Web_Questions, 2015-10-03 01:33:45

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);?>

in_array does not find 23 although there are 30 of its pieces
count shows only 2 elements

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mokhirjon Naimov, 2015-10-03
@Web_Questions

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);

S
Stalker_RED, 2015-10-03
@Stalker_RED

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 question

Ask a Question

731 491 924 answers to any question