Jump to content

Zane

Administrators
  • Posts

    4,362
  • Joined

  • Last visited

  • Days Won

    11

Posts posted by Zane

  1. I hate asking for code but what would that look like
    I knew I'd have to use a combination of UPDATE and SELECT but I couldn't get the syntax right

    when I first tried it..I got the error
    that there was more than one row returned.
    a query like this
    UPDATE course2 a SET curr = (SELECT b.id from curriculums b where b.prefix = a.curr)
  2. that's not true
    people do it all the time.

    [quote=From MySQL documentation]
    The index can also be used even if the ORDER BY does not match the index exactly, as long as all of the unused portions of the index and all the extra ORDER BY columns are constants in the WHERE clause. The following queries use the index to resolve the ORDER BY part
    SELECT * FROM t1
      ORDER BY key_part1,key_part2,... ;
       
    SELECT * FROM t1
      WHERE key_part1=constant
      ORDER BY key_part2;
       
    SELECT * FROM t1
      ORDER BY key_part1 DESC, key_part2 DESC;
       
    SELECT * FROM t1
      WHERE key_part1=1
      ORDER BY key_part1 DESC, key_part2 DESC;
    [/quote]
  3. Alright, I use the DUMP feature in phpmyadmin to get a textlist
    and used Dreamweaver's regex feature to do close to what I needed..
    I have it looking like this now
    [code]
    +------+-----------+-------------------------------------+
    | curr | coursenum | name                                |
    +------+-----------+-------------------------------------+
    | aca  | 115      | Success and Study Skills            |
    | aca  | 118      | College Study Skills                |
    | aca  | 120      | Career Assessment                  |
    | aca  | 220      | Professional Transition            |
    | acc  | 115      | College Accounting                  |
    | acc  | 121      | Principles of Managerial Accounting |
    | acc  | 129      | Individual Income Taxes            |
    | acc  | 131      | Federal Income Taxes                |
    | acc  | 150      | Acct Software Appl                  |
    | acc  | 175      | Hotel and Restaurant Accounting    |
    | acc  | 193      | Selected Topics-Forensic Accounting |
    | aca  | 215      | Ethics in Accounting                |
    | acc  | 220      | Intermediate Accounting I          |
    | acc  | 221      | Intermediate Accounting II          |
    | acc  | 225      | Cost Accounting                    |
    | acc  | 269      | Audit and Assurance Services        |
    | acc  | 292      | Selected Topics in Accounting      |
    | ant  | 210      | General Anthropology                |
    | ant  | 220      | Cultural Anthropology              |
    | ant  | 221      | Comparative Cultures                |
    +------+-----------+-------------------------------------+
    [/code]

    Still trying to figure out to convert them to their respective indeces
    any thoughts
  4. I need some help...
    I have a list of around 800 college classes,with the description, course name, the hours, etc
    [color=orange]-created from REGEXing the hell out of these straight HTML pages ... btw (ouch)
    http://www.southwesterncc.edu/acadprog/desc/aca-bus.htm#aca[/color]


    This is the way the courses table looks
    [code]mysql> select id,coursenum, name from courses limit 10;
    +----+-----------+-------------------------------------+
    | id | coursenum | name                                |
    +----+-----------+-------------------------------------+
    |  1 | aca115    | Success and Study Skills            |
    |  2 | aca118    | College Study Skills                |
    |  3 | aca120    | Career Assessment                  |
    |  4 | aca220    | Professional Transition            |
    |  5 | acc115    | College Accounting                  |
    |  6 | acc121    | Principles of Managerial Accounting |
    |  7 | acc129    | Individual Income Taxes            |
    |  8 | acc131    | Federal Income Taxes                |
    |  9 | acc150    | Acct Software Appl                  |
    | 10 | acc175    | Hotel and Restaurant Accounting    |
    +----+-----------+-------------------------------------+[/code]

    If you look at the coursenum field you notice it says the major a lot...
    [quote]acc
    acc
    acc
    acc
    ..
    ..[/quote]

    I also have a table full of these things with their keys
    [code]mysql> select * from curriculums limit 10;
    +----+--------+---------------------+
    | id | prefix | name                |
    +----+--------+---------------------+
    |  1 | aca    | Academic Related    |
    |  2 | acc    | Accounting          |
    |  3 | ant    | Anthropology        |
    |  4 | art    | Art                |
    |  5 | aut    | AUTOMOTIVE          |
    |  6 | baf    | Banking and Finance |
    |  7 | bio    | BIOLOGY            |
    |  8 | bpr    | Blueprint Reading  |
    |  9 | bus    | Busniess            |
    | 10 | car    | Carpentry          |
    +----+--------+---------------------+[/code]

    maybe someone's caught on by now, but I can't figure how I would do this;

    I want to create new field in courses.....easy
    go through every record's coursenum field...add the corresponding curriculum id to the new field leaving just the numbers.....WHAT how..

    I'm clueless here....
    anyone have any advice or suggestions...I know I could make a PHP script to do this, with an array
    but that would take quite a bit of processing power

    My goal is to get it to look like this
    [code]
    +----+------------+-----------+-------------------------------------+
    | id | curriculum | coursenum | name                                |
    +----+------------+-----------+-------------------------------------+
    |  1 |          1|    115    | Success and Study Skills            |
    |  2 |          1|    118    | College Study Skills                |
    |  3 |          1|    120    | Career Assessment                  |
    |  4 |          1|    220    | Professional Transition            |
    |  5 |          2|    115    | College Accounting                  |
    |  6 |          2|    121    | Principles of Managerial Accounting |
    |  7 |          2|    129    | Individual Income Taxes            |
    |  8 |          2|    131    | Federal Income Taxes                |
    |  9 |          2|    150    | Acct Software Appl                  |
    | 10 |          2|    175    | Hotel and Restaurant Accounting    |
    +----+------------+-----------+-------------------------------------+[/code]
  5. I don't know exactly why you're DROP statement fails, but I'm almost sure that users is reserved somewhere in MySQL, maybe if you put backticks around it it would work, but nevermind that way anyway..

    It's better to use the IF EXISTS method...example


    [code]
    DROP TABLE IF EXISTS `my_users`;
    CREATE TABLE IF NOT EXISTS `my_user` (
    ......blah-blah-blah[/code]


    [quote]And what about the fact that mysql_select_db does take 2 arguments?  You only show one in your code.  Is this correct?  Thanks zanus![/quote]

    [quote]Description
    bool mysql_select_db ( string database_name [, resource link_identifier] )
    [color=green]Notice the second argument is in brackets.
    In most all programming syntax manuals, brackets mean optional.[/color]


    Sets the current active database on the server that's associated with the specified link identifier. Every subsequent call to mysql_query() will be made on the active database.
    Parameters

    database_name

        The name of the database that is to be selected.
    link_identifier

        The MySQL connection. [b]If the link identifier is not specified, the last link opened by mysql_connect() is assumed.[/b] If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level warning is generated.[/quote]



    [b]EDIT: I MERGED YOUR TWO TOPICS TOGETHER SINCE THEY HAD TO DO WITH THE SAME QUESTION[/b]
  6. [quote]What purpose does the variable '$connection' serve?[/quote]
    You're right on one note....
    theoretically you don't have to assign the connection to a variable
    once you initialize the function it does it's thing and connects like you want, which is all you want at that point.

    But then you might want to error check.
    when you run mysql_connect();
    it will try to connect and if it does it....for the sake of less explanation..........it doesn't return FALSE.

    that way later you can check your variable to make sure it's not FALSE to make sure you actually connected.



    Also, suppose you had multiple MySQL servers.
    I've never seen anyone do it, but you can assign a connection to a multiple variables....
    that way you can say
    select database A on this Server
    and then select database Y on another Server.
    otherwise, whenever you try to select a database with
    mysql_select_db()
    it just uses the default connection, or the ONLY connection you've made
  7. you STRINGified the rest of your code and exited PHP at the same time, that's why it doesn't work

    look here
    [quote]
    <?php
    //opens a new file and writes the database connection string to it then closes this new file
    $connectfile = fopen("dbconnect.php","w");
    fwrite($connectfile, [size=16pt]"[/size] [b]<-- You forgot to close your quote[/b]
    <?php \$dbh=mysql_connect (\"$serverurl\", \"$nameofuser\", \"$passofuser\")
    or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db (\"$databasename\");?>[size=16pt]"[/size]); <--So it thinks this is the end of the string I.E. your argument for fwrite
    [/quote]

    and also you, for some reason opened another PHP tag (labeled in green above)

    change that snippet to this and you should be fine

    [code=php:0]
    <?php
    //opens a new file and writes the database connection string to it then closes this new file
    $connectfile = fopen("dbconnect.php","w");
    fwrite($connectfile, "");
    $dbh=mysql_connect ($serverurl, $nameofuser, $passofuser)
    or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db ($databasename);
    [/code]
  8. If you're storing your dates as YYYY/MM/DD
    then you can do this

    [code]$fromDatabase = "2006/11/13";
    //Convert it to UNIX timestamp
    $toUNIX = strtotime($fromDatabase);
    //Convert it to your desired date format using the date() function


    //Military Time
    $newDate = date("H:i A", $toUNIX);
    //12-hour Time
    $newDate = date("h:i A", $toUNIX);[/code]
  9. [quote]1. My sql connections are correct, as they work [size=12pt]everywhere else.[/size][/quote]

    by everywhere else do you mean another computer.
    If you're trying to log into your MySQL server from somewhere else
    you must make sure that that MySQL server allows that IP, or at least the range or domain.


    If that's not the case double check your connection anyway, cuz it does say you're not issueing a password
    [code]using password: NO[/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.