1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Please help a MYSQL newbie!

Discussion in 'MySQL' started by Roze, May 19, 2005.

  1. #1
    Hello, I know this will be really simple for most of you, if you have a second I'd appreciate some help.

    I'm working hard to take my site out of Nuke, because it's SLOW...but I'm having a hard time talking to the database. I programmed some basic modules for my site, learning all the way, but I can only talk to the db using "nuke" language. In the example below, I'm trying to print out a simple list, can anyone tell me why it isn't working? Sorry if this is so basic..do I need to define more functions before i can use this syntax?

    Username and password changed.

    $username = "user";
    $password = "password";
    $hostname = "localhost";
    $dbh = mysql_connect($hostname, $username, $password)
    or die("Unable to connect to MySQL");
    print "Connected to MySQL<br>";
    $selected = mysql_select_db("nuke1",$dbh)
    or die("Could not select nuke1");

    $result = mysql_query("SELECT gid, groupname FROM nuke_catalog_groups order by description");
    while (list ($gid, $groupname) = mysql_fetch_row($result, $dbh)) {
    echo "<a href=\"modules.php?name=Archives&op=group&gid=$gid\">$groupname</a><br>";

    }
     
    Roze, May 19, 2005 IP
  2. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #2
    noppid, May 19, 2005 IP
  3. Roze

    Roze Guest

    Messages:
    403
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you for the help! That link was exactly what I was looking for, i was having a hard time earlier trying to figure out what I should read! I managed to combine the mysql_fetch_row with the while (list...) construct to make it easiest to convert my previous code to a new system. It's working nicely now, any reasons I shouldn't use the following system?

    $username = "username";
    $password = "password";
    $hostname = "localhost";
    $dbh = mysql_connect($hostname, $username, $password)
    or die("Unable to connect to MySQL");
    print "Connected to MySQL<br>";
    $selected = mysql_select_db("nuke1",$dbh)
    or die("Could not select nuke1");

    $result = mysql_query("SELECT gid, groupname FROM nuke_catalog_groups order by description");
    if (!$result) {
    echo 'Could not run query: ' . mysql_error();
    exit;
    }

    while (list($gid, $groupname) = mysql_fetch_row($result)) {
    echo "$gid $groupname<br>";
    }

    Thanks again :)
     
    Roze, May 19, 2005 IP
  4. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #4
    You may be able to if you force the mysql select to return numeric indexes. However, it's really redundant and unnecessary to grab the two fields that are already being nice and neatly plucked out of the select as arrays.
     
    noppid, May 19, 2005 IP
  5. Roze

    Roze Guest

    Messages:
    403
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Ok I understand, but does this effect server response time and things like that? I'll only be making a few queries per page, it's just a simple article archive system... Also, the reason I might stick with this syntax is that I have alot of things written that way, and I want to switch over ASAP.
     
    Roze, May 19, 2005 IP
  6. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #6
    Well I reread the code and see what you are doing. It's not a big deal really, I just don't see the point of converting the array to two single vars in all cases.

    Does it use more power, yes. Will you feel it, I doubt it even with huge traffic.

    If the select return is a single record, the single variables could be useful later. Multiple records would only leave the last record selected in those vars and be kinda useless except for a specific task.

    Cheers
     
    noppid, May 19, 2005 IP