Page 2 of 2

Re: Help with PHP/MySQL Left Join? (might be a double left join)

Posted: Wed Oct 22, 2008 1:58 pm
by JAB Creations
Perhaps a do while? I'm not sure what we'd use to determine if there is another row of data however?

Re: Help with PHP/MySQL Left Join? (might be a double left join)

Posted: Wed Oct 22, 2008 2:00 pm
by VladSun
You do know when it is the first row so put it in reverse order ;)

Re: Help with PHP/MySQL Left Join? (might be a double left join)

Posted: Wed Oct 22, 2008 2:45 pm
by JAB Creations
I'm not following...

I could count the returned rows...?

I can set the $count to the following...

Code: Select all

$count = database_check("game_category", "game_id", $row1['id']);//"2"
I have two records...I'm trying to get the logic working in my head with something...is do while what I want? There are always multiple ways to approach something...

Re: Help with PHP/MySQL Left Join? (might be a double left join)

Posted: Wed Oct 22, 2008 2:48 pm
by JAB Creations
Here is something I'm messing with...

Code: Select all

$i = 2;
do {echo $i;} while ($a = $i-1 && $a > 0);

Re: Help with PHP/MySQL Left Join? (might be a double left join)

Posted: Wed Oct 22, 2008 2:54 pm
by VladSun

Code: Select all

mysql_numrows()
By using my suggestion you don't need to count rows or even checking positions... you could do something like

Code: Select all

for ($i=0, $comma = ''; $i <10; $i++)
{
   echo $comma.$i;
   $comma = ', ';
}

Re: Help with PHP/MySQL Left Join? (might be a double left join)

Posted: Wed Oct 22, 2008 3:36 pm
by JAB Creations
Here is what I have...

Code: Select all

$join2 = "SELECT * FROM game_category INNER JOIN category ON game_category.category_id=category.id WHERE game_category.game_id='".$row1['id']."'";
$result = mysql_query($join2, $db);//"2"
 
$count = mysql_num_rows($result);
do {$count = $count - 1;}
while ($record = mysql_fetch_assoc ($result)) {echo '<a href="index.php?">'.$record['name'].'</a>'.$count; if ($count != 0) {echo ', ';}}
syntax error, unexpected '{', expecting ';' on line 6
This worked before I added do{} so err...how do I fix this please? :|

Re: Help with PHP/MySQL Left Join? (might be a double left join)

Posted: Wed Oct 22, 2008 3:42 pm
by JAB Creations
Also I'm not sure how (and if) I could mix for and while loops.

Re: Help with PHP/MySQL Left Join? (might be a double left join)

Posted: Wed Oct 22, 2008 3:47 pm
by VladSun
JAB Creations wrote:how do I fix this please? :|
Jab ... You REALLY need to read some manuals...
I will be honest with you - you miss the basics of any hi-level programming language (like PHP). I was surprised that you don't know how to work with arrays. Now... you don't know how to work with basic flow control operators like do-while ...
You really, really, really need to read some articles (even not manuals)...

You know it's not the first time to tell you things like this, so... think about it.

Re: Help with PHP/MySQL Left Join? (might be a double left join)

Posted: Wed Oct 22, 2008 3:50 pm
by VladSun

Re: Help with PHP/MySQL Left Join? (might be a double left join)

Posted: Wed Oct 22, 2008 9:57 pm
by JAB Creations
I did it! I always get confused with which is greater than and less than! Trust me I've got a book on my bed and numerous tabs open including half a dozen from php.net as well as tutorial sites including the one you posted a link to. This is my first time doing a while and that's my goal for this week and weekend: to maximize my first time encounters to help prepare myself for the internship. I do know how to work with arrays reasonably well, the issue for me is that I'm not always aware of the best ways to approach some challenges.

I also had to throw in an !empty argument as the last key was empty, thankfully this (at least in this example) did not interfere with preventing an ending comma. However if it did I suppose an easy fix would be to adjust the default value of $i. If that wouldn't work I'd probably create a second variable, set it to equal $i plus one (or minus one). Thankfully this works as is right now. I'm going to work on a tag display page that does the reverse...finds the id of the requested tag and then determines the games associated...so displaying the games listed for the page's tag.

PHP

Code: Select all

$i=0;
while($i<=$count)
{
 $record = mysql_fetch_assoc ($result);
 if (!empty($record['name'])) {echo '<a href="index.php?'.$record['name'].'">'.$record['name'].'</a>';}
 
 $i++;
 if ($i < $count) {echo ', ';}
}
Output
<a href="index.php?Action">Action</a>, <a href="index.php?Adventure">Adventure</a>, <a href="index.php?RPG">RPG</a>

Re: Help with PHP/MySQL Left Join? (might be a double left join)

Posted: Thu Oct 23, 2008 2:34 am
by aceconcepts
Maybe take a look at for() loop and implode().