Jump to content

link7722

Members
  • Posts

    28
  • Joined

  • Last visited

Everything posted by link7722

  1. I have the following tables: Users user_id ------- display_name ------- Groups group_id --------- group_name ------- admin_id ------ superadmin_id I want to populate an html table like this: group_name -------- display_name_of_group_admin --------- display_name_of_group_superadmin My problem is that i can't get these results with one query in order to loop through the results. I can do : SELECT groups.group_name, users.display_name FROM group INNER JOIN users ON groups.admin_id = users.user_id and SELECT users.display_name FROM group INNER JOIN users ON groups.superadmin_id = users.user_id but that doesn't allow me to populate the table the way I want.
  2. I am trying to use a sortable table for data I get for my database. Unfortunately I can't get it to work. When I populate the table manually with static data sorting is working perfectly. I am using HTML Kickstart Framework. The code from HTML Kickstart: Javacript: /*--------------------------------- Table Sort -----------------------------------*/ // init var aAsc = []; $('table.sortable').each(function(){ $(this).find('thead th').each(function(index){$(this).attr('rel', index);}); $(this).find('th,td').each(function(){$(this).attr('value', $(this).text());}); }); // table click $(document).on('click', 'table.sortable thead th', function(e){ // update arrow icon $(this).parents('table.sortable').find('span.arrow').remove(); $(this).append('<span class="arrow"></span>'); // sort direction var nr = $(this).attr('rel'); aAsc[nr] = aAsc[nr]=='asc'?'desc':'asc'; if(aAsc[nr] == 'desc'){ $(this).find('span.arrow').addClass('up'); } // sort rows var rows = $(this).parents('table.sortable').find('tbody tr'); rows.tsort('td:eq('+nr+')',{order:aAsc[nr],attr:'value'}); // fix row classes rows.removeClass('alt first last'); var table = $(this).parents('table.sortable'); table.find('tr:even').addClass('alt'); table.find('tr:first').addClass('first'); table.find('tr:last').addClass('last'); }); CSS: /*--------------------------------- TABLES -----------------------------------*/ table{width:100%;margin:0 0 10px 0;text-align:left;border-collapse: collapse;} thead, tbody{margin:0;padding:0;} th, td{padding:7px 10px;font-size:0.9em;border-bottom:1px dotted #ddd;text-align:left;} thead th{font-size:0.9em;padding:3px 10px;border-bottom:1px solid #ddd;} tbody tr.last th, tbody tr.last td{border-bottom:0;} /* striped */ table.striped{} table.striped tr.alt{background:#f5f5f5;} table.striped thead th{background:#fff;} table.striped tbody th{background:#f5f5f5;text-align:right;padding-right:15px;border-right:1px dotted #e5e5e5;} table.striped tbody tr.alt th{background:#efefef;} /* tight */ table.tight{} table.tight th, .tight td{padding:2px 10px;} /* sortable */ table.sortable{border:1px solid #ddd;} table.sortable thead th{cursor: pointer;position:relative;top:0;left:0;border-right:1px solid #ddd;} table.sortable thead th:hover{background:#efefef;} table.sortable span.arrow{border-style:solid;border-width:5px; display:block;position:absolute;top:50%;right:5px;font-size:0; border-color:#ccc transparent transparent transparent; line-height:0;height:0;width:0;margin-top:-2px;} table.sortable span.arrow.up{border-color:transparent transparent #ccc transparent;margin-top:-7px;} and my php page: <!DOCTYPE html> <html><head> <title>HTML KickStart Elements</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="description" content="" /> <meta name="copyright" content="" /> <link rel="stylesheet" type="text/css" href="css/kickstart.css" media="all" /> <!-- KICKSTART --> <link rel="stylesheet" type="text/css" href="style.css" media="all" /> <!-- CUSTOM STYLES --> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script type="text/javascript" src="js/kickstart.js"></script> <!-- KICKSTART --> </head> <body> <?php include "header.php"; $q_for_group_admin = "SELECT c.name AS 'group_name', u.display_name AS 'display_name', u.username AS 'username' FROM circle c INNER JOIN user u ON c.admin_id = u.user_id"; if (!$result1 = mysqli_query($con, $q_for_group_admin)) { exit($con->error); } ?> <div class="grid"> <div class"col_12"> <table class="sortable" cellspacing="0" cellpadding="0"> <thead> <tr> <th>Username</th> <th>Display Name</th> <th>Group</th> <th>Actions</th> </tr> </thead> <?php while ($row = mysqli_fetch_assoc($result1)): ?> <tbody> <tr> <td><?php echo $row['username']; ?></td> <td><?php echo $row['display_name']; ?></td> <td><?php echo $row['group_name']; ?></td> <td><a href="<?php echo BASE_PATH . '/delete_user.php?user_id=' . $row['user_id']; ?>" >Delete</a></td> </tr> <?php endwhile; ?> </tbody> </table> </div> <div class="col_12"> <table class="sortable" cellspacing="0" cellpadding="0"> <thead><tr> <th>Name</th> <th>Number</th> <th>Color</th> <th>Actions</th> </tr></thead> <tbody><tr> <td>Joshua</td> <td>555-4325</td> <td>Blue</td> <td><a href=""><i class="icon-pencil"></i></a> <a href=""><i class="icon-minus-sign"></i></a></td> </tr><tr> <td>Peter</td> <td>555-5698</td> <td>Gold</td> <td><a href=""><i class="icon-pencil"></i></a> <a href=""><i class="icon-minus-sign"></i></a></td> </tr><tr> <td>Mary</td> <td>666-7654</td> <td>Red</td> <td><a href=""><i class="icon-pencil"></i></a> <a href=""><i class="icon-minus-sign"></i></a></td> </tr><tr> <td>Star</td> <td>555-6732</td> <td>Pink</td> <td><a href=""><i class="icon-pencil"></i></a> <a href=""><i class="icon-minus-sign"></i></a></td> </tr></tbody> </table> </div> </div> </body> </html> The second table in the above code is working OK, but not the first where data comes from the sql query. Thank you
  3. htmlentities. did the jobThank you
  4. Hello I want to display the contents of a file in html like this: <?php $file = file.txt; echo '<code><pre>' . $file . '</pre></code>' ; ?> The problem is that because the file contains sentences which have "<" and ">" characters, for example "Bla bla <6545465465> bla bla " the content <6545465465> is not displayed on the page. Is there a way to display what is inside these speccial characters ? Thank you
  5. OK.You are right.Working now Thank you
  6. Can you please check the following one also.Is that also running OK? (It has the same result as the previous.) shell_exec('sed -i "s/auth_default_realm.*/auth_default_realm = $newdomain/" /etc/dovecot/dovecot.conf');
  7. I want to replace "auth_default_realm = domain1" with "auth_default_realm = domain2". The following command runs OK from the Linux shell: sed -i 's/auth_default_realm = domain1/auth_default_realm = domain2/' /etc/test/test.conf Now from PHP with shell_exec() and replacing domain1 and domain2 with 2 variables, the following command is not OK shell_exec("sed -i 's/auth_default_realm = $olddomain/auth_default_realm = $newdomain/' /etc/test/test.conf"); I see that the 2 variables ($olddomain and $newdomain) are enclosed in quotes and they are not passed correctly with shell_exec. Thank you and sorry for the confusion.
  8. Yes . Your suggestion runs OK if I replace the variables with strings, but with the variables inside the quotes of the sed command it will not recognize them.
  9. That way aren't the 2 variables ($olddomain-$newdomain) treated as strings ?
  10. Thank you for your answer. Yes I mistyped the linux command in the post. Your suggestion throws the following error (in apache error log): sed: -e expression #1, char 31: unterminated `s' command
  11. I run the following command in Linux shell and get the expected result: sed -i 's/domain = example.com/domain = whatever.com/" /etc/test/test.conf The sed command searches the file "etc/test/tect.conf" and finds the string "domain = example.com" which then replaces with "domain = whatever.com". Now I am trying to run the command from php where the string "example.com" is a variable and "whatever.com" is another one.I am using the shell_exec() function but I think that there is something wrong with the syntax-below is the syntax: shell_exec('sed -i ' . $q . 's/auth_default_realm = '. $olddomain . '/domain = '. $newdomain . '/' . $q . '/etc/test/test.conf'); $q = "'" ; (single quote) Thank you
  12. I am trying to pass some commands from my web app to the Linux OS.I am using shell_exec and commands as cat,grep,ls are executed as expected but commands that require root access, do not seem to be executed. I have edit sudoers file and added the following line in order to be able to execute any command as apache user: apache ALL=(ALL) NOPASSWD: ALL (I know this is not secure- it is a test machine accessible only from localhost) When for example I execute shell_exec('/etc/init.d/httpd restart) nothing seem to happen - I don't even get an error (in the apache error.log or when trying to redirect stderror ). Even when I put the command in a bash script the service is not restarted. Any help would be appreciated. Thank you
  13. OK solved. I needed to change the sudoers file for the apache user
  14. Now the error log responds with no tty present and no askpass program . I am using the latest Centos version.
  15. I already tried sudo but I get the following error in apache error.log: sudo can only be run in tty Thanks
  16. Hi, I am trying to use php to pass some commands to my linux box.From my webpage I am using the shell_exec function which is working OK but for some administrative tasks in linux I must have root access. As I am sending the commands from the webpage the apache user is used and so I am not allowed to do several tasks. I have also tried to use a bash script to pass the commands but with no result. Any ideas ?
  17. You are right.It was a permission issue. Thank you very much.
  18. I am usinig exec() function to execute 2 shell commands($command1 and $command2) in my Linux server if ($_POST['database']) { $command = "mysqldump --opt -u root -pgabriel13 teo > /var/www/teo/dbbackup.sql"; exec($command); } else if ($_POST['configuration']) { $command2 = "cp -R /var/www/teo/ /var/www/bck/"; exec($command2); } Although command1 is executed as expected, command2 doesn't seem to do anything and i don't get any error.Of course if I copy and paste cp -R /var/www/teo/ /var/www/bck/ to my Linux shell the command is executed OK.Any help ? Thank you
  19. I am trying to find a way to dynamically create some form fields based on a given number.I have 3 tables, the first stores printers, the second cartridges and the third is for the correspondence of printers to cartridges.In the printers table I have a field where i store the number of cartridges for each printer.To make the matching of printers to cartridges I want to create a form which every time will have the right number of textboxes (or probably dropdown menus) based on the number of cartridges the specific printer uses. Any help would really be appreciated
  20. Thank you for your answers.Problem solved with explode()
  21. Thank you for your answer but it seems that when i put 24/12/2008 (dd/mm/yyyy) in the textbox assign it to a variable like $date4 = 24/12/2008 ,after using date("Y-m-d",strtotime($date4)); i get the date like 2008-24-12(yyyy-dd-mm) and not like 2008-12-24(yyyy-mm-dd) as i would like. Thank you
  22. I am trying to find a way (a function would be preferred) to change the format of a date which is displayed like dd/mm/yyyy to yyyy-mm-dd so i can insert it in mysql date column. Thank you
  23. I have a table with multiple fields (date, username, job...) and i want to make a search form in which i will be able to search based on any field (combining more than one field, but not necesserilly all).My problem is that when i retreive the variables from the form , some of them might be empty and so the query won't return the right reults. Query: SELECT * from table_name WHERE table_username = username_variable AND table_date = date_variable ..... I think that with multiple elseif statements (executing different queries in each case if one variable is null ) i will get the results i want, but i guess there must be a quicker and most proper way to achieve that. Thanks
  24. You are right...I must be more carefull next time thank you
  25. I have a table which contains a DATE, a name, and an id field. I want to display the results of a query in a table but using date_format function to display the date not the way stored in Mysql. the code: $query = "SELECT test1_id, DATE_FORMAT(test1_date, ’%d/%m/%Y’) as date_new, test1_name from test1" $result = mysql_query($query); the above query doesnt return any error And now when i pass the result to an object with $row = mysql_fetch_object($result) ; i get the following error : Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource When i remove the date_format and execute the query getting the date field unformated everything is ok What am i doing wrong ?
×
×
  • 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.