Forum Moderators: coopster

Message Too Old, No Replies

how to pass array argument?

         

brnco

5:17 pm on Jul 10, 2007 (gmt 0)

10+ Year Member



Hi,
please could you tell me how to pass array as an argument which is mysql_fetch_array output? The variable
$datac ---> $datac["druh"] should get some number from $datac["druh"]
but there is always a result like: select * from _cis_druh WHERE id!='Array'

thanks in advance

function from_toupdate($ciselnik,$tab_databaza,$datac) {
global $datac;

echo $cis = "select * from $tab_databaza WHERE id!='$datac'";
$quer = mysql_query($cis);

$cis_row = "select * from $tab_databaza WHERE id ='$datac'";
$quer_row = mysql_query($cis);
$islike_row = mysql_fetch_row($quer_row);

echo ('<select name="'.$ciselnik.'">');
echo ('<option value="'.$datac.'">'.$islike_row[1].'</option>');

for($a=0;$a<mysql_num_rows($quer);$a++) {
$row_sel = mysql_fetch_row($quer);
echo ('<option value="'.$row_sel[0].'">'.$row_sel[1].'</option>');}
echo "</select>"; }?>
<?php

from_toupdate("druh","_cis_druh",$datac["druh"]);?>

eelixduppy

7:46 pm on Jul 10, 2007 (gmt 0)



Hello,

Try removing this line:

global $datac;

see if that works

brnco

7:58 pm on Jul 10, 2007 (gmt 0)

10+ Year Member



Thank you for the answer.

Unfortunately, I had tried it before and the script wasn't working.

eelixduppy

8:04 pm on Jul 10, 2007 (gmt 0)



Are you getting any errors when the script stops working? The way I see it, removing that line should make it work correctly...

brnco

8:07 pm on Jul 10, 2007 (gmt 0)

10+ Year Member



No errors. The only problem is that it can't pass the variable which is an array output from mysql_fetch_array function.

eelixduppy

8:29 pm on Jul 10, 2007 (gmt 0)



I'm sorry it looks like I was looking at the wrong "problem". To use an array within the query, you can use the IN function [dev.mysql.com] in the query, and the implode [php.net] the array (separated by commas) to have the string properly formatted. So it would look something like this:

$cis = "select * from $tab_databaza WHERE id IN('".implode("','",$datac)."')";

brnco

8:56 pm on Jul 10, 2007 (gmt 0)

10+ Year Member



OK. Problem solved.

Thanks a lot

Brano