Jump to content

Probelm with exploded array.


NebuJohn

Recommended Posts

I have retrived a set of numbers from a device, I divided it into two parts and compared if that exist in a table. When i gave a random array it worked properly. Below I give the code.


<?php
$array=$_POST['tel']; //numbers fetched from contact of mobile
$jstring = (array)json_decode($array,JSON_FORCE_OBJECT);
$ttutt =implode("','", $jstring);
$tet = explode(',', $ttutt);

foreach( $tet as $value ) //loop over values
{
$four = mb_substr($value, 0,-10); //to get the first chara's
$ten = mb_substr($value, -10); // to get the last ten chara
$corn=mysqli_connect("localhost","bukado","********","frocd"); //connection to the database
     $result = mysqli_query($corn, "SELECT * From prip WHERE nob IN ($ten) AND cdac IN ($four)");
        
while($row = mysqli_fetch_array($result, MYSQL_ASSOC))
{

$forl[] = $row[no];
}
mysqli_close($corn);

}
?>
Can any body please help me? any help will be appreciable. Regards. Thanks in advance.
 

 

Link to comment
Share on other sites

I have no idea what you are doing, but JSON_FORCE_OBJECT is not part of json_decode().  This is an option that controls whether you get objects or arrays, look it up.  Also, look at where you encode it and encode as array or object.  Why implode() and then explode()?

Link to comment
Share on other sites

Have you checked that the variables contain expected values? For example, what do you get for the following:

 

 

<?php
$array=$_POST['tel']; //numbers fetched from contact of mobile
print '<pre>' . print_r($array, true) . '</pre>';
 
$jstring = (array)json_decode($array,JSON_FORCE_OBJECT);
print '<pre>' . print_r($jstring, true) . '</pre>';
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.