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>"; }
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
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.
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.
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