Jump to content

select db using array key value


bulz

Recommended Posts

Hi guyz, please help me :(

I want to get an id from my database, I use a word to search it which is stored as keys of array.

But all the keys can't be found in my database, even though it's there. Here some parts of my code

 

$arrKeys = array_keys($arrResult);
foreach($arrKeys as $key)
{

	//if($arrResult[$key]>1)
	{
		echo $key/*."=>". $arrResult[$key]*/."<br>";
		//$q = mysql_query("select id_katadasar from tb_katadasar where katadasar='".$key."'");
		$kon->query("select id_katadasar from tb_katadasar where katadasar='".$key."'");
		var_dump($kon->query);
		//echo "select id_katadasar from tb_katadasar where katadasar='".$key."'";
		//$jum = $kon->getJumlah();
		//$row = mysql_fetch_array($q, MYSQL_ASSOC) or die(mysql_error() . ''. $q);
		//echo count($row);
		if($row = $kon->tampilkan()) 
		//if($row = mysql_fetch_array($q, MYSQL_NUM))
		{
			//$res = $kon->tampilkan();
			echo $row[0];
		}
		//else
		{
			//echo "tidak ada di db <br><br>";
		}
	}

}

 

$kon->query is equal to mysql_query()

$kon->tampilkan return $row=mysql_fetch_array(query)

 

Thanks

Link to comment
Share on other sites

 

It would be handy to see a print_r of the of $arrResult.

 

But what does something like this print out..

 

   foreach($arrResult as $key => $value)
   {
      
      if($key>1)
      {
         echo $key;
         $kon->query(" select id_katadasar from tb_katadasar where katadasar='".$key."' ");

         var_dump($kon->query);

         if($row = $kon->tampilkan()) 
         {
            echo $row[0];
         }

      }

   }

 

Link to comment
Share on other sites

Thanks for reply :D

Actually, I will do something inside the if..

But, in my example, I would like to check, which one is exist in my database, which is not..

so, I try to echo the "id", if the word is exist in my database..

 

Link to comment
Share on other sites

@freelance - You've removed array_keys() from the code meaning not every key will necessarily be an integer, so the if statement would fail each time there was a key string. Using count() is a nice an easy way to avoid this issue, because even if the array key was a string or not, it'd be counted since it just counts the keys. if ( count($key) > 1 )

 

Also to further help, I do need to see the contents of $arrResult. Before you start the foreach loop, can you add print_r($arrResult); and give us what it outputs bulz?

Link to comment
Share on other sites

$arrResult is a result from stemming file, which is an array with key.

The keys are words, with value of frequency of specific words appear in that file.

 

Example:

key(string) => value(int)

hello=> 20

php=>15

freaks=>9

forum=>8

 

 

 

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.