-
Posts
2,134 -
Joined
-
Last visited
-
Days Won
42
Everything posted by benanamen
-
Well, no. The task was to sum two cards.
-
Ok, really confused now. There are unique id's, the note_id. The page I am on is where I asked you about mentioning the date-time and you started talking about unique ids.
-
Forum DO NOT's 10. Do not post your homework to be done. Forum Guidelines 3. Users will not post their homework questions expecting to get their homework coded for them. If you have a question about part of the assignment that you do not understand, please post asking for an explanation rather than the code.
-
I think the ingredient your missing is something like Jcrop. You just drag over the image for the coordinates. There are many, many sources for this kind of functionality. Many options for cropping the image. Simple to use. Why re-invent the wheel? http://deepliquid.com/projects/Jcrop/demos.php
-
@my2cents: For noobies, allow me to introduce array_sum. Yet another way to get the same result. $cards = array ( 1 => 'Red', 2 => 'Yellow', 3 => 'Green', 4 => 'Red', 5 => 'Yellow', 6 => 'Blue', 7 => 'Yellow', 8 => 'Red', 9 => 'Yellow', 10 => 'Blue', 11 => 'Yellow', 12 => 'Green', 13 => 'Blue', 14 => 'Red', 15 => 'Blue', 16 => 'Green' ); $values = array_rand($cards, 2); ; echo "The two card picked are:<br />"; echo $cards[$values[0]] . " value is $values[0]<br />"; echo $cards[$values[1]] . " value is $values[1]<br />"; echo "The sum of the two cards picked is:" .array_sum($values); If you do not need to know the individual values being summed you could just do: $values = array_rand($cards, 2); echo $cards[$values[0]] . " value is $values[0]<br />"; echo $cards[$values[1]] . " value is $values[1]<br />"; echo "The sum of the two cards picked is:" .array_sum(array_rand($cards, 2));
-
Ok, confused again. I agree with the unique id's, but we were not talking about unique id's. (Where we?)
-
Yes barand, the default setting is 1024 and it will truncate at that point. But, it is a setting and it can be changed. Much like the default upload size in PHP is two meg but you usually want to always change that. Just a part of performance tuning. I don't expect newbies to know about it let alone how do it. I am sure you would agree to avoid sub queries when possible. A bit confused why you point out about the original database having a datetime column. The db that you and I both used also has a datetime. The only difference is I didnt use date time to find the last record which as I pointed out will not work if there are two records with the same date time for a given prospect.
-
Sub-query's can take a toll on your database. One thing to point out about @Barands solution is that since it is based on datetime rather than the actual last record inserted per prospect, if there are two records with the same exact date-time for a given prospect, you are going to get more than one result for that prospect. Per your specs, you just wanted one result per prospect only and that being the LAST record. Here is an example how to do it that will not take a sub-query toll on the DB and will give you the actual last record inserted per prospect and is a lot less code. * I didn't see that you were trying to get the staff_id or the comment date so I left it out. SELECT p.*, Substring_index(Group_concat(n.`comment` ORDER BY n.note_id DESC), ',', 1 ) AS last_comment FROM database_prospects AS p INNER JOIN database_prospect_notes AS n ON p.prospect_id = n.prospect_id WHERE p.active = 1 GROUP BY p.prospect_id
-
@hansford, not sure what your post has to do with the limited info the OP provided, but there would need to be four more tables needed for your example for a properly normalized DB. Another one for address, another one phones along with a phones type table, another one email/electronic communications, and another one note, all of which has nothing to do with "Person" data. Person data would be first, middle and last name, sex, birthdate, hair color, eye color, height and weight, ethnicity, active/inactive, marital status (unless you are tracking those over time, then separate tables for those)
-
Perhaps you should detail exactly what you have and exactly what you are trying to accomplish. I for one don't understand. It would greatly help if you posted an SQL dump of your "Normalized Master Database" along with sample data and details of what you want to do with it. "Analyze" doesn't tell us anything, neither does time series. Regardless of what your doing, creating all those tables is just wrong. Doing the wrong thing never saves time.
-
NO, NO, NO!! You are forbidden to do that! You need to study database normalization.
-
Here is the MySQL version to get you up and running. You should always use lowercase column names. You have some all lower, some upper and lower SQL SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for database_prospect_notes -- ---------------------------- DROP TABLE IF EXISTS `database_prospect_notes`; CREATE TABLE `database_prospect_notes` ( `note_id` int(11) NOT NULL AUTO_INCREMENT, `prospect_id` int(11) NOT NULL, `staff_id` int(11) NOT NULL, `comment` mediumtext NOT NULL, `date` datetime NOT NULL, PRIMARY KEY (`note_id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; -- ---------------------------- -- Records of database_prospect_notes -- ---------------------------- INSERT INTO `database_prospect_notes` VALUES ('1', '1', '1', 'Police check uncovered issues?', '2015-10-15 12:02:33'); INSERT INTO `database_prospect_notes` VALUES ('2', '1', '236', 'Appointed', '2015-10-15 14:29:27'); -- ---------------------------- -- Table structure for database_prospects -- ---------------------------- DROP TABLE IF EXISTS `database_prospects`; CREATE TABLE `database_prospects` ( `prospect_id` int(11) NOT NULL AUTO_INCREMENT, `FirstName` varchar(20) NOT NULL, `LastName` varchar(20) NOT NULL, `State` varchar(3) NOT NULL, `Active` int(1) NOT NULL, `Email` varchar(100) NOT NULL, `UserType` varchar( NOT NULL DEFAULT 'Prospect', `dlr_group` varchar(10) NOT NULL, `middlename` varchar(30) NOT NULL, `carname` varchar(80) NOT NULL, `tradingname` varchar(80) NOT NULL, `arn` int(6) NOT NULL, `carn` int(6) NOT NULL, `authorisations` varchar(20) NOT NULL, `phonehome` varchar(15) NOT NULL, `phonework` varchar(15) NOT NULL, `phonemobile` varchar(15) NOT NULL, `faxwork` varchar(15) NOT NULL, `website` varchar(80) NOT NULL, `paddress` varchar(50) NOT NULL, `psuburb` varchar(30) NOT NULL, `pstate` varchar(3) NOT NULL, `ppostcode` varchar(4) NOT NULL, `haddress` varchar(50) NOT NULL, `hsuburb` varchar(30) NOT NULL, `hstate` varchar(3) NOT NULL, `hpostcode` varchar(4) NOT NULL, `baddress` varchar(50) NOT NULL, `bsuburb` varchar(30) NOT NULL, `bstate` varchar(3) NOT NULL, `bpostcode` varchar(4) NOT NULL, `raddress` varchar(50) NOT NULL, `rsuburb` varchar(30) NOT NULL, `rstate` varchar(3) NOT NULL, `rpostcode` varchar(4) NOT NULL, `dob` date DEFAULT NULL, `placeofbirth` varchar(50) NOT NULL, `split` varchar(20) NOT NULL, `abn` varchar(15) NOT NULL, `exdealer` varchar(40) NOT NULL, `software` varchar(30) NOT NULL, `softwaremodules` varchar(30) NOT NULL, `research` varchar(30) NOT NULL, `Income` varchar(20) NOT NULL, `Probability` varchar(4) NOT NULL, `Cashflow` varchar(20) NOT NULL, `added` date NOT NULL, PRIMARY KEY (`prospect_id`), KEY `id_2` (`prospect_id`), KEY `id` (`prospect_id`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; -- ---------------------------- -- Records of database_prospects -- ---------------------------- INSERT INTO `database_prospects` VALUES ('1', 'Smith', 'John', 'NSW', '1', '', 'Prospect', '--', '', 'John Smith', '', '0', '0', '--', '', '', '', '', '', '', '', '--', '', '', '', '--', '', '', '', '--', '', '', '', '--', '', '0000-00-00', '', '', '', '', '', '', '', '$15,000', '100%', '15,000', '2015-10-15'); Query to get some data SELECT d.firstname, d.lastname, d.state, d.active, d.prospect_id, d.dlr_group, d.income, d.probability, d.added, n.comment AS LastOfcomment FROM database_prospect_notes AS n LEFT JOIN database_prospects AS d ON n.prospect_id= d.prospect_id WHERE d.active=1 ORDER BY n.note_id DESC LIMIT 1
-
Some Formatting would make it much more readable. Post an sql dump of your tables and data for us to test on. Mysql doesnt not have a "Last" function SELECT database_prospects.firstname, database_prospects.lastname, database_prospects.state, database_prospects.active, database_prospects.prospect_id, database_prospects.dlr_group, database_prospects.income, database_prospects.probability, database_prospects.added, Last(database_prospect_notes.comment) AS LastOfcomment FROM database_prospect_notes RIGHT JOIN database_prospects ON database_prospect_notes.prospect_id = database_prospects.prospect_id GROUP BY database_prospects.firstname, database_prospects.lastname, database_prospects.state, database_prospects.active, database_prospects.prospect_id, database_prospects.dlr_group, database_prospects.income, database_prospects.probability, database_prospects.added HAVING (( ( database_prospects.active ) = 1 ))
-
Que Jaw drop . That script has nothing whatsoever to do with what you just posted about.. That script is also vulnerable to SQL Injection.
-
You are using obsolete MySQL code that will not work at all in the latest version Php. You need to use PDO with prepared statements.
-
Here is a page that shows you some of the various formatting standards http://www.terminally-incoherent.com/blog/2009/04/10/the-only-correct-indent-style/
-
The t1, t2 etc are specifically ALIASES. Say your name is mike(table_name) but your wife calls you bigdaddy(alias). It is a shortcut so you dont have repeatedly type out the whole table name. Example: SELECT shortname.id, shortname.firstname FROM mysuperlongtable AS shortname Instead of SELECT mysuperlongtable.id, mysuperlongtable.firstname FROM mysuperlongtable And in practice SELECT s.id, s.firstname FROM mysuperlongtable AS s The ALIAS can be anything you want it to be and is generally only one or two characters I have always found the t1, t2 way to generic and undescript. If the table is users, I would use the ALIAS u, if the table is books. I would use the ALIAS b Alias used to confuse me too, especially because of t1, t2
-
You did get help. We hopefully stopped you from using bad code. That was step 1.
-
Where are the API docs? That would be a good start as to what can easily be done. Post a link to the API.
-
I assume $results is from an SQL query so you would do ORDER BY RAND()
-
By the powers vested in my by no one, I command all knowledgeable coders to not help get this code "working". As @Jacques1 so wisely said, this is evil dirty, bad, nasty code. If I was a mod, this thread would be locked after @Jacques1 answered.
-
Randomize $results
-
So much to say, but a bit short on time at the moment. The biggest thing is that you are using obsolete MySQL code. You need to use Pdo with prepared statements. Your database structure could use improvement as well. You are also storing the timestamp data incorrectly. MySQL has a time stamp data type. You should be using that. Your code is also vulnerable to SQL injection. You never ever send user-supplied data directly to the database.
-
HTML select and option work with PHP database
benanamen replied to sigmahokies's topic in PHP Coding Help
If you're storing the month name in the database. Your storing the data wrong -
Yeah, that is the simplest way, just create the file with the header, pretty redundant to keep checking if the file exists since after the first run, it will always exist.