Jump to content

Recommended Posts

Hi all,

 

Just learning PHP and have a problem understanding how to display an image based on a value, below is the script I used to display an image based on another number within the table. The problem I have is, I am attempting to view the whole team and get an image for each player within the loop... any help would be appreciated.

 

$player_query  = "SELECT * FROM se_player WHERE player_id=$id";
$player_result = mysql_query($player_query);
while($row = mysql_fetch_array($player_result)){

if (($row[5] > 0 and $row[5] <= 9)){$stats = "0.gif";}
if (($row[5] > 9 and $row[5] <= 19)){$stats = "1.gif";}
if (($row[5] > 19 and $row[5] <= 29)){$stats = "2.gif";}
if (($row[5] > 29 and $row[5] <= 39)){$stats = "3.gif";}
if (($row[5] > 39 and $row[5] <= 49)){$stats = "4.gif";}
if (($row[5] > 49 and $row[5] <= 59)){$stats = "5.gif";}
if (($row[5] > 59 and $row[5] <= 69)){$stats = "6.gif";}
if (($row[5] > 69 and $row[5] <= 79)){$stats = "7.gif";}
if (($row[5] > 79 and $row[5] <= 89)){$stats = "8.gif";}
if (($row[5] > 89 and $row[5] <= 99)){$stats = "9.gif";}
if (($row[5] == 100)){$stats = "10.gif";}
}

Link to comment
https://forums.phpfreaks.com/topic/133461-new-to-all-this-but-need-help/
Share on other sites

for($id = 1; $id <= MAX_PLAYERS; $id++) {
   $res = mysql_query("SELECT * FROM se_player WHERE player_id=$id");
   while($row = mysql_fetch_assoc($res)) {
       // generate the image
   }
}

 

I *think* that's what you're after.  If you need to format a playing field or something, use the modulus operator against $id... something like

 

   if($id % 3 == 0) { echo "<br>"; }

 

 

 

As you can see below, I need to display an image from the value within the database. I am using smarty as well. Im still not able to get it working.

 

problem.gif

 

This is the script for the table, have worked for ages to try to get it working and banging my head against the wall now....:

 

<?
$page = "user_squad";
include "header.php";
include "./lang/lang_english_manager.php";

// SET VAR //
$id = $_GET['id'];

$sql = "SELECT * FROM se_player WHERE player_team='".$user->user_info[user_id]."'";
$res = mysql_query($sql); 
$results = array();
$i=0;
while ($r=mysql_fetch_array($res)) { 
            $tmp = array( 
                'player_id' => $r['player_id'], 
                'player_fname'=> $r['player_fname'],
			'player_lname'=> $r['player_lname'],
			'player_int'=> $r['player_int'],
			'player_rating'=> $r['player_rating'],
			'player_number'=> $r['player_number'],
			'player_pos'=> $r['player_pos'],
			'player_value'=> $r['player_value'],
            ); 
            $results[$i++] = $tmp; 
} 

//GET CLUB INFORMATION
$club_query = "SELECT team_name FROM se_team WHERE team_manager='".$user->user_info[user_id]."'";
$club_res = mysql_query($club_query);
while($row = mysql_fetch_row($club_res)) $club_name = $row[0];

// THIS UPDATES THE PALYER RATING IMAGE (NOT WORKING)
$imagequery = "SELECT * FROM se_player";
$resimage = mysql_query($imagequery);
while ($row = mysql_fetch_row($resimage)) {

if (($row[5] > 0 and $row[5] <= 9)){$stats = "0.gif";}
if (($row[5] > 9 and $row[5] <= 19)){$stats = "1.gif";}
if (($row[5] > 19 and $row[5] <= 29)){$stats = "2.gif";}
if (($row[5] > 29 and $row[5] <= 39)){$stats = "3.gif";}
if (($row[5] > 39 and $row[5] <= 49)){$stats = "4.gif";}
if (($row[5] > 49 and $row[5] <= 59)){$stats = "5.gif";}
if (($row[5] > 59 and $row[5] <= 69)){$stats = "6.gif";}
if (($row[5] > 69 and $row[5] <= 79)){$stats = "7.gif";}
if (($row[5] > 79 and $row[5] <= 89)){$stats = "8.gif";}
if (($row[5] > 89 and $row[5] <= 99)){$stats = "9.gif";}
if (($row[5] == 100)){$stats = "10.gif";}

}

$smarty->assign('results', $results);
$smarty->assign('stats', $stats);
include "footer.php";
?>

Are you sure that 10.gif is in the right directory? Maybe try adding the site url to the beginning of each image. Like so:

 

$img_url = "http://www.yoursite.com/path/to/image/";

$smarty->assign('results', $results);
$smarty->assign('stats', $img_url . $stats);

 

If the picture is not in the directory where the file is being called from that will not work. Unless the template has already taken account for that. Since there is no template I am throwing this up as an option.

Oh I thought that is how you wanted it...given the code.

 

You would want to store each image in an array like the results, infact attached onto the results array would be ideal, then you could just use that in your smarty to display the image.

 

How you have it currently coded, only the last image is returned because $stats is not an array and gets overwritten with each loop.

 

Hope that helps you get moving.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.