Jump to content


  • Posts

  • Joined

  • Last visited


Profile Information

  • Gender
    Not Telling

wickning1's Achievements


Newbie (1/5)



  1. PHP doesn't have anything special for this. Use mysql_fetch_row() and get the results numerically. For instance: SELECT col1, col2, col3, col1 FROM table ... $row = mysql_fetch_row() ... $col1_firsttime = $row[0]; $col2 = $row[1]; $col3 = $row[2]; $col1_secondtime = $row[3];
  2. Add an auto_increment column called `id` (or whatever you want), then you can do: "UPDATE table SET column='value' ORDER BY id DESC LIMIT 1"
  3. It's just "ORDER BY x ASC, y DESC"
  4. Put it in the WHERE clause: [code]//makes sure that the code is only executed when the option variable is present if (isset($_GET['cat_num'])) {    $query = 'SELECT cat_name FROM admin_cat WHERE cat_num="' . $_GET['cat_num'] . '"';    $results = mysql_query ($query);    $row = mysql_fetch_array ($results);    echo '<div class="title">' . $row['cat_name'] . '</div>'; } else {    echo '<div class="title">No category selected.</div>'; }[/code]
  5. I've never seen a problem that requires me to add tables dynamically, and I've seen a lot of problems. If you post some more details, we might be able to help you design something a little more stable. However, you can always use SHOW commands to get whatever you need. SHOW DATABASES, SHOW TABLES, SHOW COLUMNS, etc.
  6. Make sure the array you want to sort on is listed first, and be careful to choose numeric sort or string sort. String sort is the default. [code]$plancost = array(2,3,1); $supplier = array('sa','sb','sc'); $plan_name = array('pa','pb','pc'); $add_on = array('aa','ab','ac'); $hosp_cover = array('ha','hb','hc'); $excess = array('xa','xb','xc'); $plans = array('ca','cb','cc'); array_multisort ($plancost, SORT_NUMERIC, SORT_ASC, $supplier, $plan_name, $add_on, $hosp_cover, $excess, $plans); echo '<pre>', print_r ($plans, true), '</pre>'; echo '<pre>', print_r ($supplier, true), '</pre>'; echo '<pre>', print_r ($plan_name, true), '</pre>'; echo '<pre>', print_r ($add_on, true), '</pre>'; echo '<pre>', print_r ($hosp_cover, true), '</pre>'; echo '<pre>', print_r ($excess, true), '</pre>'; echo '<pre>', print_r ($plancost, true), '</pre>';[/code]
  7. Reducing storage cost is not just about hard drive space! First, on indexed columns saving space is very important because you want to keep as many indexes in main memory as possible. As your database grows, more and more indexes will be forced to reside on the disk during run time, which can severely hamper performance. Second, disk reads are the most time consuming operation in a database system. If you optimize for storage and reduce your static row length by 50%, operations on that table will happen twice as fast. Sure, lots of little systems will never reach any kind of performance limitation, but that's no reason to ignore performance completely. Now, for the topic - if your application is checking $var == "yes" in 5 million places then it's not reasonable to change the column to char(1) or bit or tinyint. What is reasonable is enum. You get the performance of tinyint without having to change code. The column acts exactly as if it were varchar, but you can only put in "yes" or "no". If you ever need to add another value, you alter the column so that it supports it. Personally when I store booleans I use tinyint 0 or 1.
  8. Yeah, I like Perl quite a bit too. That's why when I started with PHP I rolled out my own database class that works like DBI. I parse out the placeholders myself.
  9. It is a scoping thing. You need to figure out a way to have access to it all through your program, a way that seems elegant to you. You can use global $mysqli at the top of every function, that's pretty easy. What I did was build a class around mysqli that handles everything, and it stashes the link in a global variable, so that when you instantiate again, it can just check for the global variable and skip connecting.
  10. Just change two lines: $exp_date=$_db->f('exp_date'); $sec_left=$exp_date - $now;
  11. You can't use new when you're just declaring class variables. Put it in the constructor instead (PHP5 code): [code]class Test {    private $user;    function __construct() {       $this->user = new User("geneanthony", "hea9671");    } }[/code]
  12. If I needed a table to persist across page loads, I would just create the table and drop it with a real DROP TABLE command. You can always add some cleanup somewhere to make sure you delete old temp tables that are accidentally still around. A persistent connection could indeed extend the life of the table, but I'm not sure if any other thread has permission to access it, and you can't be sure which connection the new page load will get from the persistent pool. You also can't be sure when or if the connection will be regenerated, dropping the table. Not solid enough to depend on.
  13. He'll probably be fine, most web hosts have magic quotes turned on (to help cover their butts from a security standpoint). Magic quotes are so evil. If you don't know already, do yourself a favor, google a bit, learn what magic quotes are, and learn how to deal with/without them. Maybe I'll write a tutorial I can link to.
  14. Yes, both queries I wrote for you will do the exact same thing, have the exact same performance. They are just two ways to write the same thing. FULL-TEXT searches will automatically be ordered by relevance, so the more times each word matches (plus some other stuff), the higher it is in the return set. I'm not sure how well it will behave when you're searching two tables, but it probably handles it fine. It does take quite a bit of work to try and implement your own relevance rules. You basically need to create your own index and forget FULL-TEXT searching.
  15. Looks like homework, so instead of one solution, I'll give you plenty to think about. I'm only going to answer Question 1 for now though. This is probably the first one somebody would come up with. It has a subquery in the WHERE: [code]SELECT CONCAT(o.forename, ' ', o.surname) AS name FROM owner o INNER JOIN pet p ON p.ownerID=o.ownerID INNER JOIN pettype t ON t.pettypeID=p.pettypeID WHERE t.pettypename = 'Cat' AND o.ownerID NOT IN (     SELECT DISTINCT p1.ownerID FROM pet p1     INNER JOIN pettype t1 ON t1.pettypeID=p1.pettypeID     WHERE t1.pettypename = 'Dog' )[/code] This is another version, with the subquery in the FROM. It more closely resembles set subtraction: [code]SELECT CONCAT(o.forename, ' ', o.surname) AS name FROM owner o INNER JOIN (     SELECT DISTINCT p.ownerID FROM pet p     INNER JOIN pettype t ON t.pettypeID=p.pettypeID     WHERE t.pettypename = 'Cat' ) c ON c.ownerID=o.ownerID LEFT JOIN (     SELECT DISTINCT p.ownerID FROM pet p     INNER JOIN pettype t ON t.pettypeID=p.pettypeID     WHERE t.pettypename = 'Dog' ) d ON d.ownerID=o.ownerID WHERE d.ownerID IS NULL[/code] The two solutions above are MySQL solutions, here's an Oracle solution (since it looks like the homework calls for Oracle). The syntax may still be incorrect, my Oracle is rusty: [code]SELECT o.forename||' '||o.surname AS name FROM owner o INNER JOIN (     SELECT p.ownerID FROM pet p     INNER JOIN pettype t ON t.pettypeID=p.pettypeID     WHERE t.pettypename = 'Cat' MINUS     SELECT p.ownerID FROM pet p     INNER JOIN pettype t ON t.pettypeID=p.pettypeID     WHERE t.pettypename = 'Dog' ) c ON c.ownerID=o.ownerID[/code]
  • 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.