Author Topic: [SOLVED] help needed.  (Read 987 times)

0 Members and 1 Guest are viewing this topic.

Offline seany123Topic starter

  • Devotee
  • Posts: 969
    • View Profile
Re: help needed.
« Reply #15 on: July 02, 2009, 10:11:20 PM »
Yes that worked a treat thanks...

just one more thing..

is there a way to work it so, if a query finds say $item['id'] more than once it will only echo the db details one time but echo something like the amount of records it found.
WatchTVportal - watch all your favourite shows including; Dexter, house, two and a half men, 24, lost, prison break, glee AND MORE!


Offline seany123Topic starter

  • Devotee
  • Posts: 969
    • View Profile
Re: help needed.
« Reply #16 on: July 03, 2009, 01:17:21 PM »
does anyone know how to make the if statement check for multiple entries?
WatchTVportal - watch all your favourite shows including; Dexter, house, two and a half men, 24, lost, prison break, glee AND MORE!


Offline Psycho

  • Guru
  • Freak!
  • *
  • Posts: 7,755
    • View Profile
Re: help needed.
« Reply #17 on: July 03, 2009, 02:16:14 PM »
You can do that in PHP, but that would be stupid when you are using a database which does this naturally.

You know it would have been helpful had you responded appropriately to my previous comment
Quote
Are those values for Player ID and Item ID really arrays or is that just how the functions work?

Since you did not provide the information up front I went the extra step to at least tell you what my assumptions were. But, then you failed to correct my false assumption. Had you done so we would have solved this earlier. Now that I know those values really are arrays, I'm pretty sure this will work to 1) use a single query and 2) add the ability to group the records.

<div id="left_c"><div class="g_content"><h3>&nbsp;&nbsp;Your Points</h3><div class="g_text">
<
table width="100%" align="center" cellspacing="10">
<?
php

$current_col 
1;
$max_col 4;

$query "SELECT b.item_id, b.name, b.img, COUNT(b.item_id) as item_count
          FROM items i
          LEFT JOIN `blueprint_items` b
            ON items.item_id = blueprint_items.item_id
          WHERE i.player_id IN ('" 
implode("', '", array($player->id)) . "')";

$result $db->execute($query);

while(
$record $result->fetchrow())
{
    
//Open new row if first column
    
if($current_col==1)
    {
        echo 
"<tr>\n";
    }
	


    
//Display current record
    
echo "<td>";
    echo 
"<a href=\"../item.php?id={$result['item_id']}\">{$result['name']} ({$result['item_count']})</a><br>";
    echo 
"<img src=\"{$result['img']}\" width=\"100\" height=\"100\" style=\"border: 1px solid #cccccc\">";
    echo 
"</td>\n";

    
//Close row if last column
    
if($current_col==$max_col)
    {
        echo 
"<tr>\n";
        
$current_col 1;
    }
    
$current_col++;
}

//Close last row if needed
if ($current_col!=1)
{
    for(; 
$current_col<=$max_col$current_col++)
    {
        echo 
"<td>&nbsp;</td>\n";
    }
}


?>
</table>
</div></div></div>


I give no guarantees this will work. but if it doesn't at least provide soe information of what didn't work right and do some simple debugging in order to help you further. For example, echo out the query so we can ensure it is being created properly
The quality of the responses received is directly proportional to the quality of the question asked.

I do not always test the code I provide, so there may be some syntax errors. In 99% of all cases I found the solution to your problem here: http://www.php.net

Offline seany123Topic starter

  • Devotee
  • Posts: 969
    • View Profile
Re: help needed.
« Reply #18 on: July 03, 2009, 02:52:47 PM »
You can do that in PHP, but that would be stupid when you are using a database which does this naturally.

You know it would have been helpful had you responded appropriately to my previous comment
Quote
Are those values for Player ID and Item ID really arrays or is that just how the functions work?

Since you did not provide the information up front I went the extra step to at least tell you what my assumptions were. But, then you failed to correct my false assumption. Had you done so we would have solved this earlier. Now that I know those values really are arrays, I'm pretty sure this will work to 1) use a single query and 2) add the ability to group the records.

<div id="left_c"><div class="g_content"><h3>&nbsp;&nbsp;Your Points</h3><div class="g_text">
<
table width="100%" align="center" cellspacing="10">
<?
php

$current_col 
1;
$max_col 4;

$query "SELECT b.item_id, b.name, b.img, COUNT(b.item_id) as item_count
          FROM items i
          LEFT JOIN `blueprint_items` b
            ON items.item_id = blueprint_items.item_id
          WHERE i.player_id IN ('" 
implode("', '", array($player->id)) . "')";

$result $db->execute($query);

while(
$record $result->fetchrow())
{
    
//Open new row if first column
    
if($current_col==1)
    {
        echo 
"<tr>\n";
    }
	


    
//Display current record
    
echo "<td>";
    echo 
"<a href=\"../item.php?id={$result['item_id']}\">{$result['name']} ({$result['item_count']})</a><br>";
    echo 
"<img src=\"{$result['img']}\" width=\"100\" height=\"100\" style=\"border: 1px solid #cccccc\">";
    echo 
"</td>\n";

    
//Close row if last column
    
if($current_col==$max_col)
    {
        echo 
"<tr>\n";
        
$current_col 1;
    }
    
$current_col++;
}

//Close last row if needed
if ($current_col!=1)
{
    for(; 
$current_col<=$max_col$current_col++)
    {
        echo 
"<td>&nbsp;</td>\n";
    }
}


?>
</table>
</div></div></div>


I give no guarantees this will work. but if it doesn't at least provide soe information of what didn't work right and do some simple debugging in order to help you further. For example, echo out the query so we can ensure it is being created properly

to be honest, im just not that confident using that LEFT JOIN query thing.... ive never wrote queries in that way and i dont understand how they work.

im sorry if i was being shit at explaining what i was doing... but i would like to compliment you for your persistence and general help.
WatchTVportal - watch all your favourite shows including; Dexter, house, two and a half men, 24, lost, prison break, glee AND MORE!


Offline Psycho

  • Guru
  • Freak!
  • *
  • Posts: 7,755
    • View Profile
Re: [SOLVED] help needed.
« Reply #19 on: July 03, 2009, 04:04:57 PM »
If you are not using JOINS then you are not using your database to it's full potential. It's like buying a $3,000 gaming computer just to use the calculator! Take alook at this small tutorial on the subject.

http://www.tizag.com/mysqlTutorial/mysqljoins.php
The quality of the responses received is directly proportional to the quality of the question asked.

I do not always test the code I provide, so there may be some syntax errors. In 99% of all cases I found the solution to your problem here: http://www.php.net