Page 1 of 1

Re: looping rows

Posted: Sat Feb 18, 2012 6:43 am
by Jackolantern
I see you have a query inside of a WHILE loop. How many times do you think that loop is running each time the script runs? If it is like 3 or 4, you are probably fine, but too much more than that, and you would probably be putting a lot of stress on the DB to support a decent community.

Without comments in the code and a more clear image of what you need your code to do, I really can't break it down on how I would do it. All I can really do is scan for queries in loops, which is what I did, because those can get out of hand quick.

Without knowing more about exactly how your traveling system works, I would say working out a system to figure out what travel options are available from within PHP and then querying for them all at once may be a better system. But don't trash this since you have it working. Having a huge community is a dream for many of us, so just having something working and moving on can be more valuable than spending weeks tinkering with getting it "just right". You could always update it later if you build it modularly enough that you could just lift it out and drop in a different system then.

Re: looping rows

Posted: Sun Feb 19, 2012 2:15 pm
by Torniquet
I think i understand what your doing here.

Give this ago.

Code: Select all

$query = "SELECT `bh_loc_travel`.`loc_travel_to`,
`bh_loc_travel`.`loc_direction`,
`bh_loc_travel`.`loc_direction_short`,
`bh_location`.`loc_name`
FROM `bh_loc_travel`, `bh_location`
WHERE `bh_loc_travel`.`loc_is_id`='{$cloc}' AND
`bh_location`.`loc_id`=`bh_loc_travel`.`loc_travel_to`";
$locto_result = mysql_query($query);
while ($row = mysql_fetch_array($locto_result, MYSQL_BOTH))
{
.........
 
Joining tables is much more effective

Re: looping rows

Posted: Mon Feb 20, 2012 1:42 am
by Torniquet
Glad it worked :)

That method of joining, I too not long ago learnt lol (huge bonus working as a web dev).

It is basically a short hand version of using JOIN, RIGHT JOIN and LEFT JOIN.

When you dont need to conditionalise (is that a word? lol) the query, it is much easier to string them all together that way.

HOWEVER!
Do NOT mix the short hand and long hand. it doesnt work lol.