bash and php parsing
i am trying to get a script that i'm calling to have information from a sql populate into rows... but i'm not getting the data to output correctly into the rows. can someone please help?
<table> <thead> <tr> <th>Name</th> <th>Help</th> <th>Folder</th> <th>Department</th> </tr> </thead> <?php while ($result = shell_exec("/bin/bash someScript.sh")) $row = $result { echo "<tr>"; echo "<td>".$row['name']."</td>"; if ($row['help']==0) { echo "<td><img src='images/Red.gif'></td>"; } else { echo "<td><img src='images/Green.gif'></td>"; } echo "<td>".$row['folder']."</td>"; echo "<td>".$row['department']."</td>"; echo "</tr>"; } ?> </table> |
First... code tags (or in this case, php tags), which provide proper code formatting and indentation, would help us to read your code more easily.
Second, '$row = $result' should throw a syntax error as there's no semicolon delimiting the end of the statement. Third, Code:
while ($result = shell_exec("/bin/bash someScript.sh")) Code:
{ Fourth, shell_exec() returns a string, not an array. It returns the output (stdout) printed by the called command. So if your shell script (which you haven't posted) outputs some data from a database, you'll have to parse that in PHP. And fifth, I think this should probably go in the programming forum, since it's more related to PHP programming than newbie Linux. But oh well. At any rate, try fixing those errors. And you should always have 'error_reporting(E_ALL);' at the top of your code, as it makes debugging much easier. PHP hides notices and such by default, so if you have some little error such as misusing data types, PHP won't tell you unless you set reporting to E_ALL. |
hi,
i made some of the adjustments that you asked. i'm not quite sure on the array that you're referring to, my hope with the shell script is to have the sql information populate result and then parse out the sql data. then, create new rows as there are multiple lines of information that i'd like to separate into columns. i'm just not sure entirely how to get there. :) <?php 'error_reporting(E_ALL);' ?> <table> <thead> <tr> <th>Name</th> <th>Help</th> <th>Folder</th> <th>Department</th> </tr> </thead> <?php while ($result = shell_exec("/bin/bash someScript.sh")) { '$row = $result;' echo "<tr>"; echo "<td>".$row['name']."</td>"; if ($row['help']==0) { echo "<td><img src='images/Red.gif'></td>"; } else { echo "<td><img src='images/Green.gif'></td>"; } echo "<td>".$row['folder']."</td>"; echo "<td>".$row['department']."</td>"; echo "</tr>"; } ?> </table> |
Quote:
Quote:
Quote:
And please put your code in [CODE] [/CODE] BB code tags. You can easily do this using the PHP file icon on the editor toolbar. |
Code:
$row = $result['name', 'help', 'folder', 'department']; |
hi i remade the data... so i change the parameters around and i'm trying to place the array data into while statement that will be looped to recreate more lines as information is populated.
unfortunately i'm not getting this to work. Code:
<?php |
The first part of the code looks much better; it looks like it should run fine now. Your problem is in your output loop.
Quote:
Code:
$i = -1; // -1 because ++$i on the first while condition check will make this 0. Code:
$i = -1; // -1 because ++$i on the first while condition check will make this 0. |
i now can make the lines repeat to the number of files required...
Code:
for ($i=1; $i<=count($assoc_array); $i++) Code:
$result = shell_exec("/bin/bash someScript.sh"); Code:
mysql -u username -ppassword -h x.x.x.x -b -B -e "SELECT name, help, folder, department FROM tableName" database |
Quote:
I'd like to advise against the use of PHP tags; the colour coding of the source is of less benefit IMNSHO than the need to scroll sideways forever to read loooong lines of text ... Cheers, Tink |
Out of curiosity ... which RDBMS are you using? I find the concept
of using a shell-script to retrieve SQL results from PHP rather bewildering, to say the least. Ooops ... just noticed in the last post: MySQL. Why don't you just use PHPs MySQL classes to interrogate the database? Makes MUCH more sense. Cheers, Tink |
most of the previous work has been written in bash and i'd like to transition the data from writing to text utilizing bash to working with sql+php and bash to execute the major work going on.
|
Quote:
That aside, yes, by default, the mysql command-line client provides output in a tabular format (for readability in an interactive context). You may want to look at these two options (from the man page): Code:
· --batch, -B EDIT: Ah, well you sneaked in a post while I was typing. ;) Bash isn't doing the work in that mysql command. It's the mysql client (written in C) that does the work. Is this really better than letting the PHP MySQL client (also written in C) do the work for you? EDIT 2: Oh wow, I just noticed that you are using the batch option. Sorry about that. Have you tried simply running the Bash script without PHP to make sure it's producing the output you expect? |
yes, i ran the sql command in terminal and get an ouput that's not tab delineated of the information that i need.
i'm hoping to address the security concern afterwards... may not be the best idea, but it's something that i have to think about moving forwards and will probably be another discussion. :) |
Quote:
Quote:
|
i tried:
Code:
SELECT fields FROM table LIMIT 0, 38 |
All times are GMT -5. The time now is 02:13 PM. |