Autor Zpráva
table
Profil *
Ahoj,
jsem tu zase s trochu blbým dotazem.
Lze nějakým způsobem než v dotazu do db zobrazit druhý řádek z tabulky?
V selectu je to snadné pomocí OFFSET
Ale potřeboval bych to posunout přímo v zobrazení řádku, tedy např. v tomto:
<?php print $results['points']; ?>
Toto mi vypíše první řádek v tabulce lze nějak vypsat druhý řádek aniž bych musel použít OFFSET v selectu?
Děkuji za radu.
juriad
Profil
Ukaž víc kódu.
Nejspíš používáš nějakou funkci mysql(i)_fetch_*. Tu funkci můžeš jednou zavolat, to sežere první řádek a pak normálně vypsat zbytek.

Moc nechápu situaci, kdy by to bylo užitečné. Zamysli se nad tím, zda máš správně logiku a zda neexistuje lepší dotaz.
Tori
Profil
Co přesně chcete:
a) vypisovat 1. řádek dat, zobrazit něco i z druhého řádku, a pokračovat dál ve výpisu prvního řádku, anebo
b) zobrazit data z 1.řádku, zobrazit něco z druhého řádku, a pak skončit
?
table
Profil *
Zde je kod, nyní jsem si nastavil limit na 3 řádky ale vypisuje to 3 stejné řádky.
<?php
if ($team > 0) {
    // We need the conference ID too
    if ($confid < 1) {
        die ('Not enough information supplied');
    }
    
    print '<p><a href="?conf=' . $confid . '">Back to the conference standings</a></p>' . "\n";
    print '<h3>' . get_team_name($team). ': full schedule and scores</h3>' . "\n";
    print '<p><a href="?history=1&team=' . $team . '&conf=' . $confid . '">Team history</a></p>' . "\n";
    sls_team_schedule($team);
}

elseif ($confid > 0) {

// Different winning percentage calculations
switch ($winning_pct_calc) {
    case 2: // Treating a tie as a half win
    $winning_pct_formula = '((teamwins + (teamties / 2)) / (teamwins + teamties + teamlosses + teamforfeits))';
    break;

    case 3: // Treating winning percentage as number of points relative to total possible points
    $winning_pct_formula = '((teamwins * ' . $points_win . ' + teamforfeits * ' . $points_forfeit . ' + teamties * ' . $points_tie . ') / ((teamwins + teamties + teamlosses + teamforfeits) * ' . $points_win . '))';
    break;
    
    default: // Ignoring ties
    $winning_pct_formula = '(teamwins / (teamwins + teamlosses + teamforfeits))';
}

// print the conference name
$resultconf = mysql_query("SELECT sportsdb_conferences.confname, sportsdb_seasons.seasonid, sportsdb_seasons.seasonname FROM sportsdb_conferences, sportsdb_seasons WHERE sportsdb_conferences.confid = $confid AND sportsdb_conferences.season = sportsdb_seasons.seasonid LIMIT 1");
$confname = @mysql_result($resultconf, 0, 'confname') or die ('No such conference');
$seasonid = mysql_result($resultconf, 0, 'seasonid');
$seasonname = mysql_result($resultconf, 0, 'seasonname');
$seasonname = htmlspecialchars($seasonname, ENT_QUOTES);

?>
 <?php
$query = MySQL_Query("SELECT * FROM `sportsdb_divs` Where conference=$confid order by divid") or die (mysql_error());
while($zobraz = mysql_fetch_array($query)) 
{
$teamdiv_1 = $zobraz['divid'];
}
$query2 = MySQL_Query("SELECT * FROM `sportsdb_divs` Where conference=$confid order by divid DESC") or die (mysql_error());
while($zobraz2 = mysql_fetch_array($query2)) 
{
$teamdiv_2 = $zobraz2['divid'];
}
$query = "SELECT COUNT(*) FROM sportsdb_teams WHERE teamdiv = $teamdiv_1 or teamdiv = $teamdiv_2";
$result = mysql_query($query);
$result_exist = mysql_result($result,0);

if ($result_exist) {
    $query = "SELECT teamid, teamname, teamwins, teamties, teamlosses, teamforfeits, teamrf, teamra, 
    (teamwins + teamties + teamlosses + teamforfeits) AS gamesplayed, 
    (teamwins * $points_win + teamforfeits * $points_forfeit + teamties * $points_tie) AS points, 
    $winning_pct_formula AS winningpct, 
    (teamwins - teamlosses - teamforfeits) AS leadervalue 
    FROM sportsdb_teams 
    WHERE teamdiv = $teamdiv_1 or teamdiv = $teamdiv_2 
    ORDER BY leadervalue DESC, teamties DESC LIMIT 3";
    
    $result = mysql_query($query) or die ("Error in query: $query");
    $results = mysql_fetch_array($result, MYSQL_ASSOC);
    $winningpct = number_format($results['winningpct'], 3);
}

// Show the leader at the top for default sorting (games behind)

if ($standings_sort == 9) {
?>
<?php }

if ($result_exist) {
        $query="SELECT nick,teamid, teamname, teamwins, teamties, teamlosses, teamforfeits, teamrf, teamra, 
        (teamwins + teamties + teamlosses + teamforfeits) AS gamesplayed, 
        (teamwins * $points_win + teamforfeits * $points_forfeit + teamties * $points_tie) AS points, 
        $winning_pct_formula AS winningpct, 
        ((({$results['leadervalue']}) - (teamwins - teamlosses - teamforfeits)) / 2) AS gamesbehind 
        FROM sportsdb_teams 
        WHERE teamdiv = $teamdiv_1 or teamdiv = $teamdiv_2 ";

        if ($standings_sort == 9) {
            $query .= " AND teamid != {$results['teamid']}";
        }
        $query .= " AND active = 1" . $division_sort . " ORDER BY $sort_order LIMIT 3";

        $result=mysql_query($query);
                        
?>
 <div id="text3" style="position:absolute; overflow:hidden; left:100px; top:159px; width:205px; height:19px; z-index:38">
<div class="wpmd">
<div><font class="ws11" color="#C0C0C0" face="Tahoma"><b>Points</b></font></div>
</div></div>
<div id="html26" style="position:absolute; overflow:hidden; left:15px; top:176px; width:319px; height:100px; z-index:36">

<table>
<tr>
</tr>

<tr>

<td align='center'><?php print "\t\t" . '<img width="160" src="http://www.michales.eu/img/star_teams/' . $results['teamname'] .'.png">' . "\n"; ?></td>
<td align='center'><font face='Tahoma' size='2' color='#ffffff'><b><?php print $results['points']; ?></b> PTS</font></td>
</tr>
<tr>

<td align='center'><?php print "\t\t" . '<img width="160" src="http://www.michales.eu/img/star_teams/' . $results['teamname'] .'.png">' . "\n"; ?></td>
<td align='center'><font face='Tahoma' size='2' color='#ffffff'><b><?php print $results['points']; ?></b> PTS</font></td>
</tr>
<tr>

<td align='center'><?php print "\t\t" . '<img width="160" src="http://www.michales.eu/img/star_teams/' . $results['teamname'] .'.png">' . "\n"; ?></td>
<td align='center'><font face='Tahoma' size='2' color='#ffffff'><b><?php print $results['points']; ?></b> PTS</font></td>
</tr>


</table></div>
<?php } }
  

  ?>



Oprava:
<?php
if ($team > 0) {
    // We need the conference ID too
    if ($confid < 1) {
        die ('Not enough information supplied');
    }
    
    print '<p><a href="?conf=' . $confid . '">Back to the conference standings</a></p>' . "\n";
    print '<h3>' . get_team_name($team). ': full schedule and scores</h3>' . "\n";
    print '<p><a href="?history=1&team=' . $team . '&conf=' . $confid . '">Team history</a></p>' . "\n";
    sls_team_schedule($team);
}

elseif ($confid > 0) {

// Different winning percentage calculations
switch ($winning_pct_calc) {
    case 2: // Treating a tie as a half win
    $winning_pct_formula = '((teamwins + (teamties / 2)) / (teamwins + teamties + teamlosses + teamforfeits))';
    break;

    case 3: // Treating winning percentage as number of points relative to total possible points
    $winning_pct_formula = '((teamwins * ' . $points_win . ' + teamforfeits * ' . $points_forfeit . ' + teamties * ' . $points_tie . ') / ((teamwins + teamties + teamlosses + teamforfeits) * ' . $points_win . '))';
    break;
    
    default: // Ignoring ties
    $winning_pct_formula = '(teamwins / (teamwins + teamlosses + teamforfeits))';
}

// print the conference name
$resultconf = mysql_query("SELECT sportsdb_conferences.confname, sportsdb_seasons.seasonid, sportsdb_seasons.seasonname FROM sportsdb_conferences, sportsdb_seasons WHERE sportsdb_conferences.confid = $confid AND sportsdb_conferences.season = sportsdb_seasons.seasonid LIMIT 1");
$confname = @mysql_result($resultconf, 0, 'confname') or die ('No such conference');
$seasonid = mysql_result($resultconf, 0, 'seasonid');
$seasonname = mysql_result($resultconf, 0, 'seasonname');
$seasonname = htmlspecialchars($seasonname, ENT_QUOTES);

?>
 <?php
$query = MySQL_Query("SELECT * FROM `sportsdb_divs` Where conference=$confid order by divid") or die (mysql_error());
while($zobraz = mysql_fetch_array($query)) 
{
$teamdiv_1 = $zobraz['divid'];
}
$query2 = MySQL_Query("SELECT * FROM `sportsdb_divs` Where conference=$confid order by divid DESC") or die (mysql_error());
while($zobraz2 = mysql_fetch_array($query2)) 
{
$teamdiv_2 = $zobraz2['divid'];
}
$query = "SELECT COUNT(*) FROM sportsdb_teams WHERE teamdiv = $teamdiv_1 or teamdiv = $teamdiv_2";
$result = mysql_query($query);
$result_exist = mysql_result($result,0);

if ($result_exist) {
    $query = "SELECT teamid, teamname, teamwins, teamties, teamlosses, teamforfeits, teamrf, teamra, 
    (teamwins + teamties + teamlosses + teamforfeits) AS gamesplayed, 
    (teamwins * $points_win + teamforfeits * $points_forfeit + teamties * $points_tie) AS points, 
    $winning_pct_formula AS winningpct, 
    (teamwins - teamlosses - teamforfeits) AS leadervalue 
    FROM sportsdb_teams 
    WHERE teamdiv = $teamdiv_1 or teamdiv = $teamdiv_2 
    ORDER BY leadervalue DESC, teamties DESC LIMIT 3";
    
    $result = mysql_query($query) or die ("Error in query: $query");
    $results = mysql_fetch_array($result, MYSQL_ASSOC);
    $winningpct = number_format($results['winningpct'], 3);
}

// Show the leader at the top for default sorting (games behind)

if ($standings_sort == 9) {
?>
<?php }


                        
?>
 <div id="text3" style="position:absolute; overflow:hidden; left:100px; top:159px; width:205px; height:19px; z-index:38">
<div class="wpmd">
<div><font class="ws11" color="#C0C0C0" face="Tahoma"><b>Points</b></font></div>
</div></div>
<div id="html26" style="position:absolute; overflow:hidden; left:15px; top:176px; width:319px; height:100px; z-index:36">

<table>
<tr>
</tr>

<tr>

<td align='center'><?php print "\t\t" . '<img width="160" src="http://www.michales.eu/img/star_teams/' . $results['teamname'] .'.png">' . "\n"; ?></td>
<td align='center'><font face='Tahoma' size='2' color='#ffffff'><b><?php print $results['points']; ?></b> PTS</font></td>
</tr>
<tr>

<td align='center'><?php print "\t\t" . '<img width="160" src="http://www.michales.eu/img/star_teams/' . $results['teamname'] .'.png">' . "\n"; ?></td>
<td align='center'><font face='Tahoma' size='2' color='#ffffff'><b><?php print $results['points']; ?></b> PTS</font></td>
</tr>
<tr>

<td align='center'><?php print "\t\t" . '<img width="160" src="http://www.michales.eu/img/star_teams/' . $results['teamname'] .'.png">' . "\n"; ?></td>
<td align='center'><font face='Tahoma' size='2' color='#ffffff'><b><?php print $results['points']; ?></b> PTS</font></td>
</tr>


</table></div>
<?php } 
  

  ?> 
quatzael
Profil
table:
Všechno se dá v cyklech vyřešit podmínkama, případně dalším dotazem do databáze.
Pořádně popiš o co Ti jde. Hlavně se přesně vyjádři jestli Ti jde opravdu jen o dva řádky, nebo aby se chovalo více řádků nějakým systémem, tak že v jednom řádku použiješ i něco z druhého..
table
Profil *
http://michales.eu/staty_kola.php?confid=72&sort=12
Jde o ty zobrazení týmů s body vlevo nahoře, Měli by tam být 3 týmy s největším počtem bodů, nyní se zobrazuje 3x jeden tým s největším počtem bodů.
juriad
Profil
64. řádek musíš provést pokaždé před zobrazením řádku výsledku.
Přesuň ho před 89., 94. a 99. řádek. Samozřejmě ho obalíš <?php ?>

Proměnnou nastavenou v 65. řádku nikde nepoužíváš.
Tori
Profil
table:
Máte sice LIMIT 3, ale na řádku 64 čtete jen první řádek z výsledku. Načtěte si všechny řádky do pole, a řádky 87-101 můžete z tohoto pole vypsat cyklem foreach. Anebo podle [#7], to je jedno.

Btw ty dva dotazy na ř.39-48 jsou nešikovné, ve výsledku dostanete zřejmě přesně opačné hodnoty, než čekáte. Např. si seřadíte data od nejmenšího k největšímu, pak projdete všechny řádky a přepisujete si stále tutéž proměnnou. Výsledkem je tedy nejvyšší hodnota (poslední řádek), nikoli nejnižší (= první řádek). Přidejte tam LIMIT 1.
table
Profil *
Děkuji vyřešeno.

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0