1 img or the other

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ruffsta
Forum Newbie
Posts: 6
Joined: Mon Oct 12, 2009 12:10 pm

1 img or the other

Post by Ruffsta »

hi, i own: http://www.thecartelproject.com

and i need some help with a small piece of php (i am not a php coder, i know nothing of it really) - kinda lost my coder.. anyways

in a td tag.. i would like to show 1 pic or another

ex:

Code: Select all

 
$vault['success'] = mysql_result(mysql_query('SELECT count(0) FROM `logs_vault` WHERE `uID` = '.$uID.' AND `vResult` = 1'), 0);
 
 
<td>if the users successful count is 3 or higher, then show oc2.png otherwise show oc1.png</td>

also... where would i put the top piece of info? thanks everyone

-Ruffsta
AlanG
Forum Contributor
Posts: 136
Joined: Wed Jun 10, 2009 1:03 am

Re: 1 img or the other

Post by AlanG »

You can place the mysql query anywhere you like, as long as it's after the database connection and before the database disconnection.

Code: Select all

 
<?php
    echo '<td>';
    echo ($vault['success'] >= 3) ? 'oc2.png' : 'oc1.png';
    echo '</td>';
?>
 
Last edited by AlanG on Tue Oct 13, 2009 4:37 am, edited 1 time in total.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: 1 img or the other

Post by superdezign »

The ternary operator was used incorrectly. You forgot the question mark.

Code: Select all

echo ($vault['success'] >= 3) ? 'oc2.png' : 'oc1.png';
Ruffsta
Forum Newbie
Posts: 6
Joined: Mon Oct 12, 2009 12:10 pm

Re: 1 img or the other

Post by Ruffsta »

Parse error: syntax error, unexpected $end in /home/thecart/public_html/viewprofile.php on line 442 - the error i get..


i put this way up at the top after it connects...

Code: Select all

$vault['success'] = mysql_result(mysql_query('SELECT count(0) FROM `logs_vault` WHERE `uID` = '.$uID.' AND `vResult` = 1'), 0);
i put this the table where i wanted it

Code: Select all

<tr>
<td colspan="3">echo ($vault['success'] >= 3) ? 'oc2.png' : 'oc1.png';
</td>
</tr>
AlanG
Forum Contributor
Posts: 136
Joined: Wed Jun 10, 2009 1:03 am

Re: 1 img or the other

Post by AlanG »

Thanks superdezign. I may test code before I post. I'm a disaster when it comes to simple syntax errors.

Ruffsta you need to use php tags to tell the web server that the code is PHP. Also your going to need a html img tag.

Code: Select all

 
<tr>
    <td colspan="3"><img src="<?php echo ($vault['success'] >= 3) ? 'oc2.png' : 'oc1.png'; ?>"/></td>
</tr>
 
Ruffsta
Forum Newbie
Posts: 6
Joined: Mon Oct 12, 2009 12:10 pm

Re: 1 img or the other

Post by Ruffsta »

this works... and had no errors :)

Code: Select all

<tr>
<td colspan="3" class="th">My Achievements - (<font color="lime">0</font>/3)</td>
</tr>
<tr>
<td colspan="3"><img src="<?php echo ($player['vResult'] >= 1) ? 'oc2.png' : 'oc1.png'; ?>"/></td>
</tr>
 

but now my main issue is which one of these or a totally different 1 altogether???

Code: Select all

$player['vResult'] = mysql_result(mysql_query('SELECT count(0) FROM `logs_vault` WHERE `uID` = '.$_GET['id']), 0);
 
OR
 
$player['vResult'] = mysql_result(mysql_query('SELECT count(0) FROM `logs_vault` WHERE `uID` = '.$uID.' AND `vResult` = 1'), 0);
but neither work properly tho...
i want it to count how many 1's each player has... if over 3 then change the image... right now i dunno what it's doing.. some players it shows correctly - other players it doesn't - in the database there is only 3 entries in logs_vault with vResult being 1

me
another player (2x)

so nobody should have oc2.png atm...:( *depressed* but i do appreciate the help everyone
AlanG
Forum Contributor
Posts: 136
Joined: Wed Jun 10, 2009 1:03 am

Re: 1 img or the other

Post by AlanG »

Could you post the create table statement for the logs_vault table so I can get a clearer picture. :) thanks.
Ruffsta
Forum Newbie
Posts: 6
Joined: Mon Oct 12, 2009 12:10 pm

Re: 1 img or the other

Post by Ruffsta »

found this on another page - dunno if it will help any...

Code: Select all

 
$vault['success'] = mysql_result(mysql_query('SELECT count(0) FROM `logs_vault` WHERE `uID` = '.$uID.' AND `vResult` = 1'), 0);
 
 
 
<tr>
<td><?= number_format($vault['success']); ?></td>
</tr>
 



logs_vault table:

uID vTime vResult 1 Success, 0 Failure vGuess vCash vBullets


database success entries - you'll see the same person has 2 success and 1 has only 1 - but both have alot of unsuccess 0's:

uID vTime vResult 1 Success, 0 Failure vGuess vCash vBullets

Edit Delete 502 1229740592 1 2:9:8 37823313 13957
Edit Delete 2 1252207331 [color=#0BF00]1[/color] 4:1:5 63622499 14065
Edit Delete 502 1252268995 [color=#0BF00]1[/color] 7:3:6 33578541 21683
AlanG
Forum Contributor
Posts: 136
Joined: Wed Jun 10, 2009 1:03 am

Re: 1 img or the other

Post by AlanG »

If you could post the create table statement of the table in your database and a description of the query you want created. :) Just keeping it simple. :)
Ruffsta
Forum Newbie
Posts: 6
Joined: Mon Oct 12, 2009 12:10 pm

Re: 1 img or the other

Post by Ruffsta »

i don't know what you mean by "create table" - i posted the fields....

Field Type Collation Attributes Null Default Extra Action
uID int(11) UNSIGNED No Browse distinct values Change Drop Primary Unique Index Fulltext
vTime int(11) UNSIGNED No Browse distinct values Change Drop Primary Unique Index Fulltext
vResult tinyint(1) UNSIGNED No Browse distinct values Change Drop Primary Unique Index Fulltext
vGuess char(5) latin1_swedish_ci No Browse distinct values Change Drop Primary Unique Index Fulltext
vCash int(10) UNSIGNED No Browse distinct values Change Drop Primary Unique Index Fulltext
vBullets int(10) UNSIGNED No Browse distinct values Change Drop Primary Unique Index Fulltext


what i would like to do is query FROM `logs_vault` WHERE `uID` has 1's in the vResult - if uID has 3 or more 1's then change the pic from oc1.png to oc2.png
Ruffsta
Forum Newbie
Posts: 6
Joined: Mon Oct 12, 2009 12:10 pm

Re: 1 img or the other

Post by Ruffsta »

also...

Code: Select all

# <tr>
<td colspan="3" class="th">My Achievements - (<font color="lime">0</font>/3)</td>
</tr>
<tr>
<td colspan="3"><img src="<?php echo ($player['vResult'] >= 1) ? 'oc2.png' : 'oc1.png'; ?>"/></td>
</tr>

how would i go about doing more pictures in the same td.. like 5 or more with different instances? the td is very wide and a few 32x32 images will fit.. it's like award pics for various successes in the game.

wouldn't the php tags be sorta like this?

Code: Select all

<?
<tr>
<td colspan="3" class="th">My Achievements - (<font color="lime">0</font>/3)</td>
</tr>
<tr>
<td colspan="3"><img src="cho ($player['vResult'] >= 1) ? 'vault2.png' : 'vault1.png'; "/> 
<img src="cho ($player['success'] >= 1) ? 'oc2.png' : 'oc1.png'; "/> 
<img src="cho ($player['missions'] >= 1) ? 'missions2.png' : 'missions1.png'; "/>
</td>
</tr>
?>
you can view what i mean here:
http://img260.imageshack.us/img260/811/48544097.jpg
Post Reply