Help with PHP/MySQL Left Join? (might be a double left join)
Moderator: General Moderators
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
Re: Help with PHP/MySQL Left Join? (might be a double left join)
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)
You do know when it is the first row so put it in reverse order 
There are 10 types of people in this world, those who understand binary and those who don't
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
Re: Help with PHP/MySQL Left Join? (might be a double left join)
I'm not following...
I could count the returned rows...?
I can set the $count to the following...
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...
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"- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
Re: Help with PHP/MySQL Left Join? (might be a double left join)
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)
Code: Select all
mysql_numrows()Code: Select all
for ($i=0, $comma = ''; $i <10; $i++)
{
echo $comma.$i;
$comma = ', ';
}There are 10 types of people in this world, those who understand binary and those who don't
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
Re: Help with PHP/MySQL Left Join? (might be a double left join)
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 ', ';}}This worked before I added do{} so err...how do I fix this please?syntax error, unexpected '{', expecting ';' on line 6
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
Re: Help with PHP/MySQL Left Join? (might be a double left join)
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)
Jab ... You REALLY need to read some manuals...JAB Creations wrote:how do I fix this please?
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.
Last edited by VladSun on Wed Oct 22, 2008 3:51 pm, edited 1 time in total.
There are 10 types of people in this world, those who understand binary and those who don't
Re: Help with PHP/MySQL Left Join? (might be a double left join)
There are 10 types of people in this world, those who understand binary and those who don't
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
Re: Help with PHP/MySQL Left Join? (might be a double left join)
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
Output
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 ', ';}
}<a href="index.php?Action">Action</a>, <a href="index.php?Adventure">Adventure</a>, <a href="index.php?RPG">RPG</a>
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Help with PHP/MySQL Left Join? (might be a double left join)
Maybe take a look at for() loop and implode().