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.

Previous comment Return to entry

# (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

Previous comment Return to entry

# (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?

Previous comment Return to entry

# (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.

Previous comment Return to entry

# (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.

Previous comment Return to entry

# (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.

Previous comment Return to entry

# (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;

Previous comment Return to entry

# (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?

Previous comment Return to entry

# (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.

Previous comment Return to entry

RSS feed for comments on this post

Leave feedback

Feedback

Input format: The editor controls below will assist with Markdown syntax.

Status

Sub-status

Your info

Return to entry.

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?

Read more...