Jump to content

Echo multiple value


Tato123

Recommended Posts

?>

</br>

<table id="tabledlist" class="tablevar">

<td>Spilla</td>

<td>Nome</td>

<td>Piloti</td>

</tr>

<?php

$query="SELECT * FROM vawards_awards f

LEFT JOIN vawards_grants p ON p.grt_awdid = f.awd_id

WHERE f.typ_id = '1'";

$list=DB::get_results($query);

foreach ( $list as $ist)

{

?>

<tr>

<th><img src="<?php echo $ist->awd_image ?>"</th>

<th><div align="left"><?php echo $ist->awd_name ?> </div></th>

<th><?php echo $ist->grt_pilotid ?></th>

</tr>

<?php

}

?>

</table>

<br />

Hallo Guy,

i have a little problem.

When i use the echo function : <th><?php echo $ist->grt_pilotid ?></th> the system dublicate any row for each record.

Is possible have a column with multiple value separated from ; or ,

Example:

the quaery sort all awards in dbase splitted for category.

I need for all award the pilots list.

Category

Airline

Image Award - Description, And the pilots VAR901, VAR902, VAR 505

Now i see a row for pilots

http://www.virtualir...x.php/allawards

I need only one row for award and the column Piloti multiple value

  • Like 1
Link to comment
Share on other sites

You can use the MySQL GROUP_CONCAT function to create the list you're looking for along with some grouping.

Don't know what the field names are so I'm just guessing:

$query = "SELECT *, GROUP_CONCAT(grt_pilotid) as pilots_list FROM vawards_awards f
LEFT JOIN vawards_grants p ON p.grt_awdid = f.awd_id
WHERE f.typ_id = '1'
GROUP BY f.awd_id";

(Not tested)

Link to comment
Share on other sites

Thanks Tom for you repley.

I put the query

$query = "SELECT *, GROUP_CONCAT(grt_pilotid) as pilots_list FROM vawards_awards f

LEFT JOIN vawards_grants p ON p.grt_awdid = f.awd_id

WHERE f.typ_id = '1'

GROUP BY f.awd_id";

$list=DB::get_results($query);

foreach ( $list as $ist)

{

?>

<tr>

<th><img src="<?php echo $ist->awd_image ?>"</th>

<th><div align="left"><?php echo $ist->awd_name ?> </div></th>

<th><?php echo $ist->grt_pilotid ?></th>

</tr>

<?php

}

?>

</table>

<br />

But i show only 1 grt_pilot id and not the all pilots.

If you wont see here:

http://www.virtualir...x.php/allawards

Is correct no change the line <th><?php echo $ist->grt_pilotid ?></th> ???

I need to show in the same column all the pilots id for that award

Link to comment
Share on other sites

I would add the suffix VAR pilot in front of the id. (VAR901)

I can not use the code because the pilot is in another table.

Second thing, I wish id pilot was seen in three digits. Now I show 1 instead of 001

I find this way but I do not know how to apply it to my query

{

# Make sure values ​​are Entered

if (Config :: Get ('PILOTID_LENGTH') =='')

Config :: Set ('PILOTID_LENGTH', 4);

if (Config :: Get ('PILOTID_OFFSET') =='')

Config :: Set ('PILOTID_OFFSET', 0);

$ pilotid pilotid + = $ Config :: Get ('PILOTID_OFFSET');

return $ code. str_pad ($ pilotid, Config :: Get ('PILOTID_LENGTH'), '0 ', STR_PAD_LEFT);

}

Do you have any suggestions?

Thanks

Link to comment
Share on other sites

Find:

<th><?php echo $ist->pilots_list ?></th>

Replace:

<td>
<?php
$codes = array();
foreach(explode(',', $ist->pilots_list) as $pilotcode){
$codes[] = PilotData::getPilotCode("VAR", $pilotcode);
}
echo implode(', ', $codes);
?>
</td>

Side note: You appear to have your <th> and <td> mixed up.

Link to comment
Share on other sites

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.

Loading...
×
×
  • Create New...