LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   grabbing data and displaying an image (https://www.linuxquestions.org/questions/linux-newbie-8/grabbing-data-and-displaying-an-image-842432/)

eoc92866 11-04-2010 05:31 PM

grabbing data and displaying an image
 
i am attempting to grab roughly 40 pieces of data that is a combination of 0 and 1 flags from mysql. based off of the 0 or 1... either pictA or pictB will be displayed.

can someone please assist me in evaluating my code? i believe the logic is incorrect.


PHP Code:

$status = `mysql -u username -ppassword -h x.x.x.x -e 'SELECT help FROM table' database`;

declare -
ARRAY

for ((
i=1i=$statusi++));
do
        echo ${ARRAY[$(
i)]}
done


if [${ARRAY[]} = ];
then
       
echo "<img src='pictA.gif'>";

else [${ARRAY[]} = 
];
       echo 
"<img src='pictB.gif'>";
fi 


Tinkster 11-04-2010 06:25 PM

Ummm ... w/ the square brackets in the if and the condition
tacked onto the else I'm wondering why it would produce anything
at all; that doesn't look like valid PHP.


Cheers,
Tink

eoc92866 11-04-2010 08:15 PM

apologies, the code is actually written in bash.

Code:

$status = `mysql -u username -ppassword -h x.x.x.x -e 'SELECT help FROM table' database`;

declare -A ARRAY

for ((i=1; i=$status; i++));
do
        echo ${ARRAY[$(i)]}
done


if [${ARRAY[]} = 1 ];
then
      echo "<img src='pictA.gif'>";

else [${ARRAY[]} = 0 ];
      echo "<img src='pictB.gif'>";
fi


alan99 11-04-2010 10:30 PM

What is declare? is that a bash statement

alan99 11-04-2010 11:15 PM

Quote:

Originally Posted by eoc92866 (Post 4149562)
i am attempting to grab roughly 40 pieces of data that is a combination of 0 and 1 flags from mysql. based off of the 0 or 1... either pictA or pictB will be displayed.

can someone please assist me in evaluating my code? i believe the logic is incorrect.


PHP Code:

$status = `mysql -u username -ppassword -h x.x.x.x -e 'SELECT help FROM table' database`;

declare -
ARRAY

for ((
i=1i=$statusi++));
do
        echo ${ARRAY[$(
i)]}
done


if [${ARRAY[]} = ];
then
       
echo "<img src='pictA.gif'>";

else [${ARRAY[]} = 
];
       echo 
"<img src='pictB.gif'>";
fi 


first of all $status = will fail as $status will reference a variable, not declare one. It should be status=`statement`

Second you try to assign a index variable using $status. $status is not an integer. it will be a series of strings. First set returned are the column names of the table. next comes the rows of the table.


All times are GMT -5. The time now is 05:41 PM.