Query management software? Apr21 '05
Feedback
# (2 of 10): Timothy » veryraw.com
7 hours, 15 minutes after the fact. (Thu 21 Apr 2005, 8:52 PM CST)
Try it again
$row = mysql_fetch_object($result);
echo "<a href=\"$row->column_name\" ... >\n";
If you use mysql_fetch_object instead you will have an easier time managing the information. Then you are referencing the column name instead of its position. It's visually easier too.
# (3 of 10): Dale » bluetrait.com
7 hours, 37 minutes after the fact. (Thu 21 Apr 2005, 9:14 PM CST)
With mysql_fetch_array you can just use the column name.
For example
while($array = mysql_fetch_array($result)) {
echo $array['facssn'];
echo $array['facfirstname'];
}
Much easier
# (4 of 10): Matthom
18 hours, 27 minutes after the fact. (Fri 22 Apr 2005, 8:04 AM CST)
Timothy, Dale... what happens when you are issuing an INNER JOIN (or equi-join), and you have two columns with the same name?
# (5 of 10): Timothy » veryraw.com
22 hours, 58 minutes after the fact. (Fri 22 Apr 2005, 12:34 PM CST)
I suppose you would have to alias the fields that have the same name. I know there are some issues with aliasing and joins in mysql because of the order that the information is aquired but I can't put my finger on it exactly. I believe it works sometimes. It's all in how you design the queries.
The biggest benefit that I see to mysql_fetch_object is that it's two less characters to type. Other than that there is really no significant difference. It all comes down to preference. I had confused mysql_fetch_row with mysql_fetch_array.
# (6 of 10): Timothy » veryraw.com
23 hours, 14 minutes after the fact. (Fri 22 Apr 2005, 12:51 PM CST)
I have thought about this myself. When I get to about the thousandth line of code it becomes hard to remember which queries I have written already and if they are already there than why should I write them again. Most of my applications at work are relatively simple, but in the larger applications its important to maintain that information. I have thought about seperating them into a queries.inc.php file (or whatever) and them just including it in the other files. Then I can call the same query everytime.
Ideally I think the best solution though would be to build an object. Then you wouldn't have to worry about it. I slept through my OOP class though. Woah is me. I'll have to teach myself again.
I think separating your comments from your code is a step in the wrong direction. It adds a layer of extraction that really does nothing more than make your code look more streamline when in fact it will be harder to figure out what is going on when you revisit it later. Furthermore, when you leave your job and someone else comes in they are going to have to read your code. The more layers they have to deal with the more difficult its going to be for them to pickup where you left off.
# (7 of 10): Matthom
23 hours, 25 minutes after the fact. (Fri 22 Apr 2005, 1:02 PM CST)
Timothy, I'm not too familiar with OOP, either (although I should be)... It might help this situation.
I think separating your comments from your code is a step in the wrong direction.
I'm sure it is... but nothing is stopping me from trying new things. This is one of those things that I can never really be "settled" with, so I'm always going to fight it, until I find a better way.
Your mention of mysql_fetch_object is interesting. I'll have to check that out.
# (8 of 10): Dale » bluetrait.com
1 day, 2 hours after the fact. (Fri 22 Apr 2005, 4:28 PM CST)
If you have two of the same name you do this:
tablename.columnname
so
SELECT post.id, comment.id FROM post, comment WHERE post.id = 1;
# (9 of 10): Matthom
1 day, 4 hours after the fact. (Fri 22 Apr 2005, 5:40 PM CST)
Dale, will "dot syntax" work when referencing a column via mysql_fetch_array?
Using your original comment example:
while($array = mysql_fetch_array($result)) {
echo $array['tablename.facssn'];
echo $array['tablename.facfirstname'];
}
Would that work?
# (10 of 10): Dale » bluetrait.com
1 day, 4 hours after the fact. (Fri 22 Apr 2005, 6:12 PM CST)
Yes I think so.
RSS feed for comments on this post
Leave feedback
I’d appreciate a piece of software that helps manage SQL queries, for development purposes.
You are at the feedback permalink page for: Query management software?
# (1 of 10): Timothy » veryraw.com
7 hours, 13 minutes after the fact. (Thu 21 Apr 2005, 8:50 PM CST)
$row = mysql_fetch_object($result);
echo "column_name\" ... >\n";
If you use mysql_fetch_object instead you will have an easier time managing the information. Then you are referencing the column name instead of its position. It's visually easier too.