Jump to content

Display result side by side


rogerteixeira

Recommended Posts

Hi, i'm trying to show the crimes side by side in two column (its a game)

like:

Crime1 Crime2

in the engine show:

Crime1
Crime2

the code is:

 

TableHeader("Crimes");

echo "<table class='plainTable'>";
$result = $db->Execute("select crime_id,name,description,condition_code,success_r  ate,stat_cost,jail_time,crime_pic from crimes order by crime_id");
foreach ($result as $row)
{
    echo "<tr valign='top'>";
    $res = true;
    if ($row[3] != null && $row[3] != "")
        $res = NWEval("return {$row[3]};");
    if ($row[5] > $userStats[GetConfigValue("CrimeStatCost", "crime")]->value)
        $res = false;
    echo "<td width='1%'>";
    echo "<img src='$row[7]'/>";
    echo "</td>";
    $perc = 100;
    if ($row[4] != null && $row[4] != "")
        $perc = round(NWEval("return {$row[4]};") * 100.0, 0);
    if ($perc > 100)
        $perc = 100;
    echo "<td><b>" . Translate($row[1]) . ":</b>" . Translate($row[2]) . "";
    echo Translate("<font color='green'><b>Success rate") . ": $perc%</b></font>" . Translate("<font color='red'><b>Cost") . ": {$row[5]}</b></font>";
    LinkButton('Do it', 'index.php?p=crime&id={$row[0]}', null, null, false, $res);
    echo "</td>";
    echo "</tr>";
}
$result->Close();
echo "</table>";

how to do this?

thx guys

Link to comment
Share on other sites

here's an example using floating divs

$db = new mysqli(HOST, USERNAME, PASSWORD, DATABASE);

$sql = "SELECT name, score FROM score";
$res = $db->query($sql);
$i = 0;
while ($row = $res->fetch_assoc()) {
    echo <<<TXT
    <div style='float:left; width:200px; height:50px; padding:10px'>
    {$row['name']}
    <br>
    <span style='font-size:20pt; font-weight: 600'>{$row['score']}</span>
    </div>
TXT;
    if (++$i%2==0) echo "<div style='clear:both'></div>";
}

Result attached

post-3105-0-19030500-1383432463_thumb.png

Link to comment
Share on other sites

We enclose the output from each record in a <div>,,</div> which is defined as float:left. This means each div will be placed next to the previous one instead of underneath (default behaviour).

 

To ensure that we start a new row every other record (when our counter $i has a remainder of zero when divided by 2) we output a <div> to clear the floating behaviour then start again on the next row of two

Link to comment
Share on other sites

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.