Jump to content

mbeals

Members
  • Posts

    247
  • Joined

  • Last visited

    Never

Everything posted by mbeals

  1. that's basically what placing an index on employee ID is doing...... An index is a second table containing references to common things, So the employeeID index looks something like: EmployeeID | Location ------------------------------ 1 1,3,4,5 2 9, 23 4 12 So when you search on an index, you really are just searching on a smaller table...but you don't have to go through the pains of manually reorganizing the data.
  2. array's don't persist from page to page and you can only transmit serialized data (text) through a get or post request. You can't pass an array like you can with a function call, so header("location:checking1.php?item=$check_item"); Isn't doing what you think it is. Ideally, this is performed with a database, which stores the user's entry on every submit... or by allowing the user to input all info at once. If you insist on this format, I supposed you could try to serialize() the array first, pass it through $_GET and then unserialize() it on the other side, but that would get messy in a hurry
  3. thought about it, but the 'data' array can be quite long (contains html) and clarity-wise that gets ugly in a hurry. It's also not that flexible if I need to add more keys later on. I haven't found documentation yet, but I think using the [] shortcut is just an alias for array_push(), so when I add something with that syntax, it is getting pushed onto the stack, but the pointer is left unchanged. I ended up just calling end() to advance the pointer and it seems to be working. ie: $rows[]['data'] = array('cell 1', 'cell 2', 'cell 3', 'cell 4'); end($rows); $rows[key($rows)]['opts'] = 'center'; $rows[key($rows)]['color'] = ''; not sure if there is an easier way to handle it though....so I'll leave the thread 'unsolved'
  4. a join is fairly easy to think about when you look close at the syntax. First when working with joins, we have to explicitly tell mysql which table to deal with. So our select statement needs to be: Select news.*, news_categories.* ..... or since we don't really care to use the id's: Select news.`news article`, news_categories.name, news_categories.description .... This says our result 'table' will have those three columns (news, article. name and description). Now we need to join the tables together. Since news.category_id will (or should) always correspond to a entry in news_categories, we will just use a generic join: Select news.`news article`, news_categories.name, news_categories.description FROM news, news_categories WHERE news.category_id = news_categories.id Now we just need to limit the search to a particular category: Select news.`news article`, news_categories.name, news_categories.description FROM news, news_categories WHERE news.category_id = news_categories.id AND news.category_id = '$category' Since you want to rename stuff, we need to use the AS statement. You want the news_categories.name column to be called 'category' Select news.`news article`, news_categories.name AS category, news_categories.description FROM news, news_categories WHERE news.category_id = news_categories.id AND news.category_id = '$category'
  5. can you show and example of what you want? You can make just use joins to do this and it will return a 1:1 mapping (contact -> url), but each pair will be a single row. and it's 1,2,3-trimethylbenzene and you owe me for the years of therapy that just ruined
  6. I have a function that builds a table row by row, using logic to determine whether a row should be added or not. To simplify the task, I built a function that accepts an array of 'cells' and returns the html for the table. It's structure is: buildRow(array $cells, string $alignment, string $cellColor) What I need to do is generate an array of hashes, where each hash contains the three elements for a row. Something like: Array ( [0] => Array ( [data] => Array ( [0] => cell 1 [1] => cell 2 [2] => cell 3 [3] => cell 4 ) [opts] => center [color] => #CCFFFF ) [1] => Array ( [data] => Array ( [0] => cell 1 [1] => cell 2 [2] => cell 3 [3] => cell 4 ) [opts] => right [color] => #CCFFFF ) ) Traditionally I would build the top level array like: $rows = array(); $rows[] = array('cell 1', 'cell 2', 'cell 3', 'cell 4'); $rows[] = ..... and just allow the array pointer to auto advance. However....when I add the associative hash in, it doesn't work: <?php $rows = array(); $rows[]['data'] = array('cell 1', 'cell 2', 'cell 3', 'cell 4'); $rows[]['opts'] = 'center'; $rows[]['color'] = '#CCFFFF'; ?> Doesn't produce the desired affect The closest I came was with this: <?php $rows[]['data'] = array('cell 1', 'cell 2', 'cell 3', 'cell 4'); $rows[key($rows)]['opts'] = 'center'; $rows[key($rows)]['color'] = ''; $rows[]['data'] = array('cell 1', 'cell 2', 'cell 3', 'cell 4'); $rows[key($rows)]['opts'] = 'center'; $rows[key($rows)]['color'] = '#CCFFFF'; ?> but it fails as well because for some reason key perpetually returns 0 as the array position. Am I missing something obvious? I did look at using a temp variable, but would like to avoid it if possible.
  7. first you need to count the number of comments per image: Assuming that each comment has a reference back to the image table (imageID) Select imageID, count(imageID) as number from Comments group by imageID Creates a table consisting of the image ID and number of comments with that ID. Now join it to the comments table: Select images.*, commentInfo.* from (Select imageID, count(imageID) as number from Comments group by imageID) as commentInfo join images on commentinfo.imageID = images.index order by commentInfo.number Sit 2 Select pic_rating / pic_votes as rating from images order by rating
  8. you never know...and besides it's really not wise to use the root account as a normal user.
  9. Your query is breaking, thus not returning a result resource. Add echo mysql_error(); after your mysql_query(); and see what error mysql_query is throwing.
  10. I see nothing wrong with your structure, except you will want to add an expenseID reference in the Detail table Using your syntax: ExpenseID = 1 ExpenseDate = 7/19/08 MerchantName = "Target" ExpenseID = 2 ExpenseDate = 7/20/08 MerchantName = "SuperCuts" --------------------------- Description = "CD" UnitPrice = $10 Quantity = 1 ExtendedPrice = $10 ExpenseID = 1 ... Description = "Scotch Tape" UnitPrice = $2 Quantity = 1 ExtendedPrice = $2 ExpenseID = 1 ... Description = "Toothpaste" UnitPrice = $4 Quantity = 1 ExtendedPrice = $4 ExpenseID = 1 ... Description = "T-Shirt" UnitPrice = $6 Quantity = 5 ExtendedPrice = $30 ExpenseID = 1 ... Description = "Haircut" UnitPrice = $20 Quantity = 1 ExtendedPrice = $20 ExpenseID = 2 --------------------------- Yes you may have a single "detail" entry for a single "expense", but that's okay.
  11. first off, PUT A PASSWORD ON YOUR ROOT ACCOUNT Secondly, log into the remote server and add a user with remote connection privileges: CREATE USER 'test'@ '192.168.3.198' ...... where the IP or hostname is the ip or hostname of the computer that will be connecting to the server. If you wish to allow any computer to connect, use %. Finish the CREATE statement with the required privileges and database restrictions. DO NOT: 1. grant root remote connections (especially with no password) 2. grant the remote user more privileges then he needs (if he doesn't need to be able to alter or drop tables, don't let him) 3. give the remote user admin rights (create users, grant permissions, lock tables, etc...) 4. give the remote user a null or weak password This query string should do what you want and be reasonably secure: CREATE USER '<user>'@'<host>' IDENTIFIED BY '<passwd>'; GRANT SELECT , INSERT , UPDATE , DELETE ON `<database>` . * TO '<user>'@'<host>'; change the stuff identified by < > tags
  12. your query string in php is delimited by double quotes, so php is puking when it hits them. You need to escape them with a \. The slash will vanish once php parses the string so they shouldn't wind up in the database.
  13. the mysql_query() shouldn't be part of the string. change $data = "mysql_query(\"SELECT * FROM music WHERE"; to $data = "SELECT * FROM music WHERE"; then after the last if: $query_result = mysql_query($data) or die(mysql_error()); and change while($result = mysql_fetch_array( $data )) to while($result = mysql_fetch_array( $query_result ))
  14. I'm designing a database to hold IP assignment data. It will hold information about the circuit, NAT translation mappings (public -> private address) and info about the attached device. I have three main classes of device: CMTS, provisioning server and others. The CMTS and Provisioning Servers have unique attributes that make it worthwhile tracking them in their own tables. The structure is as follows CREATE TABLE `circuits` ( `index` int(11) NOT NULL auto_increment, `prop` varchar(30) NOT NULL, `priority` int(2) NOT NULL, `type` varchar(20) NOT NULL, `up` varchar(10) NOT NULL, `down` varchar(10) NOT NULL, `dns1` varchar(20) NOT NULL, `dns2` varchar(20) NOT NULL, `lanIP` varchar(20) NOT NULL, `maskbits` int(2) NOT NULL, `gateway` varchar(20) NOT NULL, `CID` varchar(20) NOT NULL, `serial` varchar(20) NOT NULL, `smask` varchar(20) NOT NULL, `comments` longtext NOT NULL, PRIMARY KEY (`index`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; CREATE TABLE `CMTS` ( `index` int(11) NOT NULL auto_increment, `publicIP` varchar(20) NOT NULL, `localIP` varchar(20) NOT NULL, `snmp` int(11) NOT NULL, `circuitID` int(11) NOT NULL, `group` int(11) NOT NULL, `webadmin` int(11) NOT NULL, `remote_storage` int(11) NOT NULL, `pass` varchar(20) NOT NULL, PRIMARY KEY (`index`), UNIQUE KEY `publicIP` (`publicIP`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; CREATE TABLE `Provservers` ( `index` int(11) NOT NULL auto_increment, `publicIP` varchar(20) NOT NULL, `localIP` varchar(20) NOT NULL, `circuitID` int(11) NOT NULL, `pass` varchar(20) NOT NULL, PRIMARY KEY (`index`), UNIQUE KEY `publicIP` (`publicIP`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; CREATE TABLE `netdevices` ( `index` int(5) NOT NULL auto_increment, `circuitID` varchar(30) NOT NULL, `publicIP` varchar(20) NOT NULL, `localIP` varchar(40) NOT NULL, `admin` varchar(10) NOT NULL, `test` tinyint(1) NOT NULL default '0', `status` varchar(20) NOT NULL, `use` longtext NOT NULL, `group` int(2) NOT NULL default '2', `pass` varchar(20) NOT NULL, `comments` longtext NOT NULL, PRIMARY KEY (`index`), KEY `prop` (`circuitID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; I need to to keep this modular, such that I can add devices later that may have specialized attributes. My problem in handling it this way is that I now have no common index for all devices. When I build a table of all devices on a circuit (using Unions ), I cannot identify each record uniquely by a single index value (making updating a PITA). Any thoughts on how to proceeded?
  15. what are the permissions on the keygen program? php system() commands are run as the apache user, which is locked down and may not have the permissions to run the file (or even wine). As root, switch into the user www-data (su www-data). Do it as root to avoid entering a password for www-data. Once you are in www-data's shell, try executing the command again and see if you get an error.
  16. Yea I read that... And it seems to say that specifying a randmax (like I did) higher then 32768 would work (like it did)
  17. He was asking for knowledge sake, so I thought I'd expand his knowledge by pointing him toward some more advanced functions. But yes, use explode if you can and save the regex for special cases.
  18. Look up preg_match, Preg_match_all and preg_split for even more ways of hacking strings apart
  19. If I remember correctly, mysql cannot be running during a dump. Try stopping the service before dumping and see if that fixes it. I actually run master slave replication on my master sql server and have a bash script that shuts down the slave, dumps it, restarts mysql then tars the dumped file. It requires a second machine, but it means zero downtime to backup the db and I have a live realtime mirror of the db in case the entire server drops.
  20. You can skip all of the html. Get the data from the db and process it. Then instead of echoing html, just generate you update sql statements with the data and execute them. Does that make sense?
  21. Is the second database (the one being updated) on the same computer as the first?
  22. Move the method=post to the form tag (its in the select now)
  23. I see the prob now. A php shell script doesn't use the html wrapper. It does stuff and echos plain text. What exactly are you attempting to do with this script? If you are moving data to a differeny server you would place a web page on the receiving server that would process incoming get data, then call that url with the needed get data on the sending server with cURL or some other method. Although I will say this isn't the best way to handle the transaction.
  24. <?php $query = "Select `attribute` from Table where `attribute` = 'value' "; $result = mysql_query($query); if(mysql_num_rows($result)){ value exists }else{ it doesn't } ?> beat me to it....and with near exact code too. There is no boolean query that I'm aware of. Besides, if you think about it, just a yes or a no wouldn't really save anything in terms of speed or efficiency.
  25. sorry about that, I guess root does only have write permissions to /var/log. you can as root or sudo: touch /var/log/ranking1.log chmod a+rw ranking1.log or just change the path to your home dir (change 'me'): /usr/bin/php -q /home/public_html/ranking1.php >> /home/me/ranking1.log but anyway, I have to go and I'm probably not going to be around until monday so I'll leave these parting words: 1. Double check that you can run the script (successfully) from the command line as the user who's crontab you are setting using the exact command you are setting in cron 2. Check that cron is actually running by scheduling /bin/echo "Cron is working" >> /home/mydir/crontest.log to run every minute then see if it is writing to the file The terminal is you BASH (or CSH or xterm) shell. This is Linux right? It should be somewhere in your accessories. If you're not sure look up the documentation for your distro.
×
×
  • 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.