Jump to content

Gaoshan

Members
  • Posts

    25
  • Joined

  • Last visited

    Never

Everything posted by Gaoshan

  1. OK, thanks guys. I'll fix their relations as the tables do need to be reconfigured in a few places. Especially since they really aren't truly, totally, unrelated. Much appreciated.
  2. I have a few questions before I can help you out. 1. What is an example of a specific value for $mailstamp? 2. Why do you use $now = date("j, m, Y - H:i.s", strtotime("now")); rather than something simpler like $now = time(); ? You don't need the double quotes around your variables. You have: if( $now < "$MailStamp" ) just use: f( $now < $MailStamp ). You have if Mailimit, elseif Mailtime and then nothing. You need to return some sort of value at the end in case the previous if statements are not met. Last, you start off with if isset, elseif isset. Try a simpler: [code]if(!isset($_POST[username]) || !isset($_POST[msg])) { echo "missing"; return false; }[/code]
  3. [code]mysql_query("INSERT INTO thetable (thecolumn) values ($_POST['foo'])");[/code] Of course, this assumes you are getting the login data via $_POST.
  4. [url=http://www.intranetjournal.com/php-cms/]http://www.intranetjournal.com/php-cms/[/url] [url=http://www.adobe.com/devnet/dreamweaver/articles/php_blog1.html]http://www.adobe.com/devnet/dreamweaver/articles/php_blog1.html[/url] These will both get you started. Note that the second one uses Dreamweaver and kind of ends at a point where you would need to purchase a commercial product to continue with their tutorial. That said you can still glean some useful beginner info from it. Also, these are very basic "applications" you will build. Don't rely on this for anything serious or important as they need much better security, more options and the ability to handle unexpected results or input.
  5. I didn't think I needed to use a JOIN here. I am using the data separately in two unrelated areas. Do I need a JOIN anyway? The grades table is as such: [code]-- -- Table structure for table `grades` -- CREATE TABLE `grades` (   `id` smallint(6) NOT NULL auto_increment,   `studentid` smallint(6) NOT NULL,   `assignmentid` smallint(6) NOT NULL,   `earned` decimal(3,1) NOT NULL,   `comment` text NOT NULL,   PRIMARY KEY  (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; [/code] The sort of data I'm inserting: [code]INSERT INTO `grades` VALUES (7, 1, 1, 9.0, 'Nice solution to a difficult...etc. etc.'); [/code] @fenway: Why would the query return so many results? I thought that that query would get me the sum of the one column and the average of the other and they would be unrelated to to each other. Where is the connection between them that is causing the problem?
  6. You need to first create a user named pma, define it in config.inc.php (controluser/controlpass) and then run the file: create_tables_mysql_4_1_2+.sql (assuming your version of MySQL is 4.1.2 or higher, of course) It is in the phpmyadmin scripts folder. That should take care of your problem.
  7. This code (the one you last posted which now has the correct number of brackets) should work fine assuming you have the values for your various variables properly defined somewhere and assuming you put something in the currently empty if...else statement. I tested it (cut and past and then changed variables and selects to match my setup) and it returned data no problem.
  8. looks like: "Failed to connect to 72.246.73.242: Host is down" To see this yourself try adding: [code]if (curl_errno($ch)) {   print curl_error($ch); } else {   curl_close($ch); }[/code]
  9. It is the last " causing you trouble (the one right before the closing parenthesis). Lose it and you should be ok. Just curious but why use print_r for this? I think a faster solution would be something like: [code]echo '<tr><td><p><img src="../art/' . $myrow[photoname] . '"></p></td></tr>';[/code]
  10. You are missing a closing bracket. The if statement is never closed in the code you posted.
  11. For 1: Create a basic template that can draw the data it needs (or in the case of files it can draw on the location of the files), based on userid and password, from your database and populate it. Do this rather than creating a directory for each user. For 2: Not unless you take pains to enforce unique IDs. To link various profiles you could, as one of many possible ways, pass variables to your profile page using GET  as part of a link [code]<a href="profile.php?id=' . $theid . '">[/code]and have the database use the GET info to pull data for the page.[code]SELECT * FROM users WHERE userid = $theid[/code]
  12. By "jump pass the form" do you mean you want the form to load some other page and it doesn't or do you want the form to reload the same page and it doesn't? Not clear what you want to do.  ???
  13. [code]<?php $result = mysql_query('SELECT * WHERE 1=1'); if (!$result) {     die('Invalid query: ' . mysql_error()); } ?>[/code]
  14. I get 2 different results from a query that I thought would return the same result. The reason I want to use the first example (which returns an incorrect value for SUM) is that I also need the AVG value and don't want to make 2 queries if at all possible. If I set up my query this way, I get an incorrect result (with maxgrade = 630): [code]SELECT SUM(a.maxgradepoints) AS maxgrade, AVG(g.earned) AS avgrade FROM assignmentdata a, grades g[/code] If I set it up this way, I get a correct result with (maxgrade = 30): [code]SELECT SUM(maxgradepoints) AS maxgrade FROM assignmentdata[/code] My table looks like this: [code]TABLE `assignmentdata` (   `id` smallint(6) NOT NULL auto_increment,   `assignmentnum` tinyint(20) NOT NULL,   `assignmentname` varchar(100) NOT NULL,   `maxgradepoints` tinyint(100) NOT NULL,   PRIMARY KEY  (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `assignmentdata` -- INSERT INTO `assignmentdata` VALUES (1, 1, 'Photograph Something Meaningful', 10); INSERT INTO `assignmentdata` VALUES (2, 2, 'Portraits (1 straight, 1 environmental)', 10); INSERT INTO `assignmentdata` VALUES (3, 3, 'Sports (Action)', 10);[/code] I'm using MySQL 5.0.18.
  15. You either have to create the table and populate it with the data you need or you have to figure out which table the script is supposed to be pointing at and change the name to that table. As for how to do that, I recommend reading this: [url=http://dev.mysql.com/doc/refman/4.1/en/index.html]http://dev.mysql.com/doc/refman/4.1/en/index.html[/url]
  16. The table you are trying to query simply doesn't exist.
  17. My solution to this problem was as follows: First the sql: [code]$mysqldb->query("SELECT s.firstname, COUNT(DISTINCT g.assignmentid) AS totalstu, GROUP_CONCAT( g.earned ) AS grouped FROM studentdata s, grades g, assignmentdata a WHERE g.assignmentid = a.assignmentnum AND s.studentid = g.studentid GROUP BY s.studentid");[/code] And now the PHP to loop through the results and put what I want where I want it: [code] while ($row = $mysqldb->fetchObject()) { echo '<tr><td>' . $row->firstname . '</td>'; for ($i = 0; $i < $row->totalstu; $i++){ $bustedout = explode(',', $row->grouped); echo '<td>' . $bustedout[$i] . '</td>'; } echo '</tr>'; }[/code] Thanks to fenway for pointing out the piece of the puzzle that I was missing... GROUP_CONCAT
  18. True. I'll see what works best with my setup and give that a try.
  19. Yes. I figured I could use the default comma separator and then use explode in PHP to get the various values. I just wish I knew how to do everything with one SQL statement here rather than resort to doing part of it in PHP.
  20. Do what fenway said. Anyway, just for your information the reason you are having that problem is that you are mixing a GROUP column (in your case COUNT) with non-group columns and not using a GROUP BY clause.
  21. Have you tried "flush tables" or "flush privileges"?
  22. The array is created automatically by mysql_fetch_array. To step through that array just use: [code]while ($row = mysql_fetch_array($result)) {     echo $row[0], $row[1], $row[2];  }[/code]
  23. OK. I was not familiar with GROUP_CONCAT. I used the following query: [code]SELECT s.firstname, GROUP_CONCAT( g.earned ) AS grouped FROM studentdata s, grades g, assignmentdata a WHERE g.assignmentid = a.assignmentnum AND s.studentid = g.studentid GROUP BY s.studentid[/code] and got: [table] [tr][td]Jim[/td][td]9,9.1[/td][/tr] [tr][td]Mary[/td][td]8[/td][/tr] [tr][td]Ann[/td][td]6[/td][/tr] [/table] Which is better than I had been able to get before. I'll play with that and see if it solves the problem. Thanks for the tip!
  24. Hi all, my problem is this: I want to be able to list students and then list their grades for each assignment after them (in a traditional gradebook pattern). I only want the students listed once and some students will not yet have been graded on all assignments. Also, not all assignments will have been created. I suppose I could do the work in PHP but it seems this MUST be doable in SQL. Any help is greatly appreciated (I'm a teacher, BTW) I can get a list that restricts the students by student id and lists their first assignment but my problem is getting second, third, etc. assignments to go after that (it is easy to get them to appear UNDER that but then it lists the student's name again). I would assume the main issue here is how to extract the different assignment numbers from the single column that they share.  ??? >:( What I get: [table] [tr][td]John[/td][td]9[/td][/tr] [tr][td]Mary[/td][td]7[/td][/tr] [tr][td]Ann[/td][td]8[/td][/tr] [tr][td]John[/td][td]5[/td][/tr] [tr][td]Mary[/td][td]4[/td][/tr] [tr][td]Ann[/td][td]9[/td][/tr] [tr][td]John[/td][td]6[/td][/tr] [/table] ;D What I want: [table] [tr][td]John[/td][td]9[/td][td]5[/td][td]6[/td][/tr] [tr][td]Mary[/td][td]7[/td][td]4[/td][td]-[/td][/tr] [tr][td]Ann[/td][td]8[/td][td]9[/td][td]-[/td][/tr] [/table] Here is an overview of the database as it stands now: -- Table structure for table `assignmentdata` -- TABLE `assignmentdata` (   `id` smallint(6) NOT NULL auto_increment,   `assignmentnum` tinyint(20) NOT NULL,   `assignmentname` varchar(100) NOT NULL,   `maxgradepoints` tinyint(100) NOT NULL,   PRIMARY KEY  (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -------------------------------------------------------- -- -- Table structure for table `grades` -- TABLE `grades` (   `id` smallint(6) NOT NULL auto_increment,   `studentid` smallint(6) NOT NULL,   `assignmentid` smallint(6) NOT NULL,   `earned` decimal(3,1) NOT NULL,   `comment` text NOT NULL,   PRIMARY KEY  (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; -- -------------------------------------------------------- -- -- Table structure for table `studentdata` -- TABLE `studentdata` (   `id` smallint(6) NOT NULL auto_increment,   `studentid` smallint(6) NOT NULL,   `firstname` varchar(30) NOT NULL,   `lastname` varchar(30) NOT NULL,   `attendance` varchar(10) NOT NULL,   PRIMARY KEY  (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
×
×
  • 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.