jazzman1
Staff Alumni-
Posts
2,713 -
Joined
-
Last visited
-
Days Won
12
Everything posted by jazzman1
-
Thank you PFMaBiSmAd, I will try this
-
it really doesn't matter!
-
Sorry guys, for EU and BG the result has to be - 28. Yes Christian, I want to take values as the sum of the children's number + its own. Examples: EU - 0+8+5+2+4+9 BG -8+5+2+4+9 Sofia-5+4 (Sofia+Mladost) Varna-2+9 (Varna+Chaika) Mladost and Chaika don't have chindren.
-
Hi friends, I have a database named 'abv' with a table named: category - +-------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+-------------+------+-----+---------+----------------+ | category_id | int(11) | NO | PRI | NULL | auto_increment | | name | varchar(20) | NO | | NULL | | | number | int(11) | NO | | NULL | | | parent | int(11) | YES | | NULL | | +-------------+-------------+------+-----+---------+----------------+ +-------------+----------+--------+--------+ | category_id | name | number | parent | +-------------+----------+--------+--------+ | 1 | Europe | 0 | NULL | | 2 | BG | 8 | 1 | | 3 | Sofia | 5 | 2 | | 4 | Varna | 2 | 2 | | 5 | Mladost | 4 | 3 | | 6 | Chaika | 9 | 4 | +-------------+----------+--------+--------+ I used Barand's code to display its hierarchy: <?php //connect to database $link = mysql_connect('localhost','root',''); mysql_select_db('abv'); $sql = "SELECT category_id, name, parent, number FROM category"; $res = mysql_query($sql); while (list($id, $name, $parent, $number) = mysql_fetch_row($res)) { $data[$parent][] = array('id'=>$id, 'name'=>$name, 'number'=>$number); } // function to print a category then its child categories function displayHierarchy(&$arr, $parent, $indent=0) { $ind = $indent * 30; if (isset($arr[$parent])) foreach($arr[$parent] as $rec) { echo "<div style='width:300px; margin-top:5px; margin-left: {$ind}px; padding:5px; border:1px solid gray;'> {$rec['name']} - {$rec['number']} </div>" ; displayHierarchy($arr, $rec['id'], $indent+1); } } // call the recursive function displayHierarchy($data, null); Results: Europe - 0 BG - 8 Sofia - 5 Mladost - 4 Varna -2 Chaika - 9 My question is, how to get this data displaying a result like this: Europe - 26 BG - 26 Sofia - 9 Mladost - 4 Varna - 11 Chaika - 9 Thanks in advance
-
Better approach of this is to create a nested or multidimensional array that includes the question and the answer. In other words, you have to create a list, where each item in the list is another list, after that you need to compare that responze with the question's actual answer.
-
Wrong html! I've tried that one and it works: <?php $totalPages = 2.8888888888889; $output =""; if($totalPages > 2) { $output .= "<label>Page:</label>"; $output .= "<select id=breadcrumb_page onchange=getNewBreadcrumbPage(this.value)>"; for($i=1; $i<=ceil($totalPages); $i++) { $output .= "<option value='$i'"; if(isset($_REQUEST['breadcrumb']) && $_REQUEST['breadcrumb'] == $i -1) $output.= "selected"; $output .= ">$i</option>\n"; } $output .= "</select>"; echo $output; } ?> <script type="text/javascript"> function getNewBreadcrumbPage(data){ alert(data); } </script> EDIT: I added and your javascript function. Don't use $REQUEST !
-
I don't get it, everything is just fine! What result do you want to output?
-
Display Db Records Of The Current Month Only How?
jazzman1 replied to lovephp's topic in PHP Coding Help
What is wrong with a time field of this query? Does time have a type of datetime or something else in your DB? -
Most likely you got a wrong html output, just echo $output and post the results here.
-
Well, rid all of if statement off from that class and put it a static values, after that just echoing the $output varible!
-
Check that statement again and tell us where the code gets stuck. if($totalPages > 2) { $output .= "<label>Page:</label>"; $output .= "<select id='breadcrumb_page' onchange='getNewBreadcrumbPage(this.value,\""; $output .= "\");'>"; for($i=1; $i<=ceil($totalPages); $i++) { $output .= "<option value='$i'"; if(isset($_REQUEST['breadcrumb']) && $_REQUEST['breadcrumb'] == $i -1) $output.= "selected"; $output .= ">$i</option>\n"; } $output .= "</select>"; echo $output; } } EDIT: also check the type of $totalPage: echo gettype($totalPages)
-
Where did you get this piece of code? You got a wrong result of total pages.
-
What's the result of $totalPages. $totalPages = $this->totalLit / $this->numPerPage;
-
Put this line of code on the top of FormS.php file and show us the results: <?php echo '<pre>'.print_r($_POST, true).'</pre>'; ?>
-
How Do I Get Two Ajax To Load On The Same Page
jazzman1 replied to sungpeng's topic in Javascript Help
Why the name of second function is called - Ajaxa, did you see that? Just create only one function that will have one parameter to get different values comming from GET. Just follow the rule of DRY principle ( Don't Repeat Yourself) -
If you want to grab all data from the data.txt that contents "/11" writing it into a new file named: data.log,it could be something like this: $str = 11; $cmd = shell_exec("cat data.txt | grep -i /$str > /home/jazzman/data.log"); You can also use RegEx to filter out your outputing. $str could be a date php function grabing the name of the current month or what ever you want. It doesn't matter what language you want to use excecuting that script , you must follow the rules of a bash/shell syntax.
-
$cmd = shell_exec('cat data.txt | grep -i'.$year.' -B 1 -A 25'); This syntax of that code is completely wrong in bash! cat file.txt | grep -i "/$variable" That syntax is correct, but do you know what does mean?
-
Grep is an unix shell command. Do you know how to use it? Do you know what does mean this part of code? cat file.txt | grep -i "/$variable"
-
First off, my apology if my English is not good for you. 1. Well, before getting into specifics of the GRANT statement, take a look at the statement that grants all rights on the database named test to user jazzman, jazzman's password is "password" mysql > GRANT ALL ON test.* TO jazzman@localhost IDENTIFIED BY "password"; The first part of the GRANT statement can take the word - ALL. Most often you will be granting rights to use sql staments ( SELECT, CREATE, DELETE, DROP, INDEX, INSERT and UPDATE). The second one (ON test.*) identifies where privileges will be applied. Learn more about them at an address -> http://dev.mysql.com...iv_grant-option The third one (TO jazzman@localhost) indicates the user to be given access. Note, that MySQL needs both a name and a host, separated by the "@" symbol. The last one, IDENTIFIED BY gives the user a password. Here is what the user and db tables would look like for the user - "jazzman" Open a mysql console and go to the mysql table: Example: [jazzman@localhost ~]$ mysql --host=localhost --user=jazzman --password=password --port=3306 mysql> use mysql Database changed mysql> SELECT * FROM user WHERE user='jazzman' \G *************************** 1. row *************************** Host: localhost User: jazzman Password: *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 Select_priv: Y Insert_priv: Y Update_priv: Y Delete_priv: Y Create_priv: Y Drop_priv: Y Reload_priv: Y Shutdown_priv: Y Process_priv: Y File_priv: Y Grant_priv: Y References_priv: Y Index_priv: Y Alter_priv: Y Show_db_priv: Y Super_priv: Y Create_tmp_table_priv: Y Lock_tables_priv: Y Execute_priv: Y Repl_slave_priv: Y Repl_client_priv: Y Create_view_priv: Y Show_view_priv: Y Create_routine_priv: Y Alter_routine_priv: Y Create_user_priv: Y Event_priv: Y Trigger_priv: Y ssl_type: ssl_cipher: x509_issuer: x509_subject: max_questions: 0 max_updates: 0 max_connections: 0 max_user_connections: 0 1 row in set (0.00 sec) mysql> SELECT * FROM db WHERE user='jazzman' \G *************************** 1. row *************************** Host: localhost Db: test User: jazzman Select_priv: Y Insert_priv: Y Update_priv: Y Delete_priv: Y Create_priv: Y Drop_priv: Y Grant_priv: N References_priv: Y Index_priv: Y Alter_priv: Y Create_tmp_table_priv: Y Lock_tables_priv: Y Create_view_priv: Y Show_view_priv: Y Create_routine_priv: Y Alter_routine_priv: Y Execute_priv: Y Event_priv: Y Trigger_priv: Y 3 rows in set (0.00 sec) As you can see from a log, I retrieve all information that I need to know about the user named - "jazzman". For my test database, the permissions granted by the above statement may be ok if jazzman is the administrator of that application. In this particular example jazzman have all rights on the database named - test. What I want to do is creating a table in this database named - product. After that I want to remove some of jazzman's privileges on this table, for this example - DELETE statement, to do this you could use REVOKE statement. mysql > CREATE TABLE `product` ( `id` int(11) NOT NULL, `name` varchar(40) DEFAULT NULL, `purchase_id` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=latin1; mysql > INSERT INTO `test`.`product` VALUES (1,'Lawn Mower',1),(2,'Greenhouse',1),(3,'Paving slab',2),(4,'BBQ',2),(5,'Chainsaw',5), (6,'Power-MP3 5gb',2),(7,'Super-Player 1gb',3),(8,'Porta CD',3),(9,'36\" TV',1),(10,'Family Talk 360',5); RESULTS: mysql> use test; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> SELECT * FROM test.product -> ; +----+------------------+-------------+ | id | name | purchase_id | +----+------------------+-------------+ | 1 | Lawn Mower | 1 | | 2 | Greenhouse | 1 | | 3 | Paving slab | 2 | | 4 | BBQ | 2 | | 5 | Chainsaw | 5 | | 6 | Power-MP3 5gb | 2 | | 7 | Super-Player 1gb | 3 | | 8 | Porta CD | 3 | | 9 | 36" TV | 1 | | 10 | Family Talk 360 | 5 | +----+------------------+-------------+ 10 rows in set (0.00 sec) Granting all rights on that table to jazzman I ran that code: mysql> GRANT ALL ON test.product TO jazzman@localhost IDENTIFIED BY "password"; Query OK, 0 rows affected (0.02 sec) To remove DELETE privileges from jazzman to this particular table you can run the following: mysql> REVOKE DELETE ON test.product FROM jazzman@localhost; Query OK, 0 rows affected (0.00 sec) To see the exact grants available at a given time, all you to know is the username and host: As you can see from the mysql log, there is no delete pivileges to jazzman. mysql> SHOW GRANTS FOR jazzman@localhost Results: GRANT SELECT, INSERT, UPDATE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE VIEW, SHOW VIEW, TRIGGER ON `test`.`product` TO 'jazzman'@'localhost' You need to load the grant table to the MySQL memory to get effect into it. mysql> FLUSH privileges; Query OK, 0 rows affected (0.00 sec) After all of that , you have to log off then log on from mysql console - CTRL + D Now if I try to delete the username with an id 1 from a test.product table, I got denied access. mysql> DELETE FROM test.product WHERE id=1; ERROR 1142 (42000): DELETE command denied to user 'jazzman'@'localhost' for table 'product' I think you could use this one as a sample. You can find much more details about privileges at mysql.com website. Good luck
-
Congrats, Pika
-
If you are administering MySQL, you could create a group of users with very specific permission.
-
Example: --where="name='john'"
-
There is a where clause.
-
@muddy, I've never thought to try, too Actually, this is a question from one bulgarian forum. The guy of that forum doesn't have a web server neither any knowledges of server side languages. He knows only html and a little sql. His question was, is it a way to generate database tables as html document(s) in my browser? I've suggested him to use a mysqldump tool dumping tables as xml document, after that just using javascript to retrieve this data, but he doesn't have any experience in javascript, too. Well, that's the story Anyway, I wrote a simple bash script which get the data from db tables saving it in html document. It works properly. Example: #!/bin/sh CMD="use test;select * from product" /usr/bin/mysql -h 127.0.0.1 -u jazzman --password="password" --html -e "$CMD" > /home/jazzman/index.html Have a good one.
-
Hey friends, Let's say that I have a database named - "test". Inside this database, I have a table, it's called - 'product'. If I try to get an information from the product table produsing as html output, I'm using the code below. Example: [jazzman@localhost ~]$ mysql -h localhost -u jazzman --password='password' --html mysql> use test; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> SELECT * FROM product; <TABLE BORDER=1><TR><TH>id</TH><TH>name</TH><TH>purchase_id</TH></TR><TR><TD>1</TD><TD>Lawn Mower</TD><TD>1</TD></TR><TR><TD>2</TD><TD>Greenhouse</TD><TD>1</TD></TR><TR><TD>3</TD><TD>Paving slab</TD><TD>2</TD></TR><TR><TD>4</TD><TD>BBQ</TD><TD>2</TD></TR><TR><TD>5</TD><TD>Chainsaw</TD><TD>5</TD></TR><TR><TD>6</TD><TD>Power-MP3 5gb</TD><TD>2</TD></TR><TR><TD>7</TD><TD>Super-Player 1gb</TD><TD>3</TD></TR><TR><TD>8</TD><TD>Porta CD</TD><TD>3</TD></TR><TR><TD>9</TD><TD>36" TV</TD><TD>1</TD></TR><TR><TD>10</TD><TD>Family Talk 360</TD><TD>5</TD></TR></TABLE>10 rows in set (0.00 sec) What I want to do is, runing a mysqldump to get only this particular html output. What do you think, is it possible? Thanks in advance.