Jump to content

[SOLVED] mysql and tables.


KingChaos

Recommended Posts

Hi there. First topic here. Proberbly not the last one.

 

I got a php file that imports it's info fram a database. And from that info it creates a table. This is for a game. And if it's more than one game running it creates another table below the first one. Like this:

 

table.jpg

 

What I need is to make the tables like this:

 

table2.jpg

 

 

Here is the php-file:

 

<?

include("html.php");

 

$html = mysql_fetch_array(mysql_query("SELECT description FROM $tab;"));

 

siteheader();

?>

  <table width="100%" height="100%">

    <tr>

    <td width="80%" valign="top"><?=$html[0]?> <br>

 

 

    <b><center>

 

    <font color="orange">Open Rounds:</font>

    <?

      $getgames = mysql_query("SELECT round,ends,starts,name,status FROM $tab[game] WHERE ends>$time ORDER BY round ASC;");

        while ($game = mysql_fetch_array($getgames))

        {

      ?>

      <br>

      </b>

      <small>

      <b>

     

      <font color="orange">Round <?=$game[0]?> - <?=$game[3]?></font>

              </b>

              <center>

              <table width="60%" cellspacing="1" cellpadding="1" bgcolor="202020" align="center">

 

      <tr bgcolor="<?=$rankcolor?>">

          <td width=1><small>Rank</small></td>

          <td height="16" align="center"><small>Pimp Name</small></nobr></td>

          <td align=center><small>Worth</small></td>

<td>

        </tr>

      <?

      $pmpstatus = mysql_fetch_array(mysql_query("SELECT code FROM $tab[user] WHERE status='banned';"));

      $getpimps = mysql_query("SELECT id,pimp,networth,nrank,crew FROM "."r".$game[0]."_".$tab[pimp]." WHERE rank>0 AND code!='$pmpstatus[0]' ORDER BY CAST(networth AS UNSIGNED) DESC LIMIT 10;");

        while ($pimp = mysql_fetch_array($getpimps))

        {

        $crw = mysql_fetch_array(mysql_query("SELECT icon FROM "."r".$game[0]."_".$tab[crew]." WHERE id='$pimp[4]';"));

            if($rankstart==0){$rankcolor="#003366";$rankstart++;}

        elseif($rankstart==1){$rankcolor="#16283B";$rankstart--;}

      ?>

        <tr bgcolor="<?=$rankcolor?>">

          <td width=1><small><?=$pimp[3]?>.</small></td>

          <td height="16"><nobr><?if($crw[0]){?><img src="<?=$crw[0]?>" width="14" height="14" align="absmiddle"><?}?><Small><a href="pimp.php?pid=<?=$pimp[1]?>&rnd=<?=$game[0]?>"><?=$pimp[1]?></a></small></nobr></td>

          <td align=right><small>$<?=commas($pimp[2])?></small></td>

        </tr>

      <?}?>

      </table>

      </center>

 

 

      <font color="orange" size="1"><?if ($game[2] > $time){?>Starts in <?countdown($game[2]);}else{?><?if($game[4] == pause){?>[Round Paused]<?} else {?>Ends in <?countdown($game[1]);}?><? } ?>

      <br>

      <br>

      <?}?>

 

    </div>

    </font>

    </td>

    </tr>

  </table>

 

<?

sitefooter();

?>

 

 

Hope someone got a solution for me.

 

King

 

Link to comment
https://forums.phpfreaks.com/topic/62685-solved-mysql-and-tables/
Share on other sites

One way to do this is through embedded tables...

 

<table>
<tr>
<td>
<table>
<tr>
<td>
Table 1
</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>
Table 2
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td>
Table 3
</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>
Table 4
</td>
</tr>
</table>
</td>
</tr>
</table>

Thx 4 the reply, but that wont work.

 

Becouse then I'll have to edit it all the time. This is for a game site, and some games runs for 30 day and others runs just for 3 days. And I only wanna show the active games.

 

So now the script fetches those games automaticly, and generates a new table for that game.

 

But for all I know it might be another file that tells the site how to split the tables. But since I don't know much about programming, I have no idea!  ;D

But there's only one other file that is running together with this one, and I can't find something there eighter. (not that I know what to look for. lol)

 

But here is the other file.:

 

 

<?

include("funcs.php");

include("banners.php");

$id=cln($id);

$referuser = mysql_fetch_array(mysql_query("SELECT username FROM $tab[user] WHERE id='$id';"));

$refuser = $referuser[0];

 

function secureheader(){

global $id, $tab, $time, $sitename;

  $user = mysql_fetch_array(mysql_query("SELECT online,status,code FROM $tab[user] WHERE id='$id';"));

  $idle=$time-$user[0];

 

      if (!$user){ setcookie("trupimp",NODATA); header("Location: login.php?reason=notlogged"); }

  elseif ($idle > 3600){ setcookie("trupimp",NODATA); header("Location: login.php?reason=idle"); }

  elseif ($user[1] == banned){ setcookie("trupimp",NODATA); header("Location: login.php?reason=banned&code=$user[2]"); }

$time = cln($time);

  mysql_query("UPDATE $tab[user] SET online='$time' WHERE id='$id';");

}

 

function siteheader(){

global $site, $tab, $menu, $time, $id, $id1, $sitename, $showads, $userstatus, $userads, $showblock, $adverts;

 

$block = mysql_fetch_array(mysql_query("SELECT showblock FROM settings;"));

$showblock = $block[0];

 

$user = mysql_fetch_array(mysql_query("SELECT status,ads FROM users WHERE id='$id';"));

$userads = $user[1];

$userstatus = $user[0];

if ($userstatus == admin || $userstatus == supporter){$userstatus = supporter;}

if ($userads == yes || $userstatus != supporter){$showads = "1";}

 

//SHOWING PIMPS ONLINE

$idletime=$time-360;

 

$reg = mysql_fetch_row(mysql_query("SELECT count(username) FROM $tab[user];"));

//pinoywebdev add s

$idletime=cln($idletime);

$time = cln($time);

//pinoywebdev add e

$online=fetch("SELECT COUNT(id) FROM $tab[user] WHERE online>$idletime;");

 

$getgames = mysql_query("SELECT round FROM $tab[game] WHERE starts<$time AND ends>$time ORDER BY round ASC;");

while ($game = mysql_fetch_array($getgames)){

$onlinepimps=fetch("SELECT COUNT(id) FROM r$game[0]_$tab[pimp] WHERE online>$idletime;");

$pimpin=$pimpin+$onlinepimps;

}

 

$getgames = mysql_query("SELECT round FROM $tab[game] WHERE starts<$time AND ends>$time ORDER BY round ASC;");

while ($game = mysql_fetch_array($getgames)){

$pimpshitting=fetch("SELECT COUNT(id) FROM r$game[0]_$tab[pimp] WHERE lastattack>$idletime;");

$attackin=$attackin+$pimpshitting;

}

 

?>

<html>

<head>

<title><?=$sitename?> - Free Web Based Pimps Game</title>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1255">

<link rel="stylesheet" type="text/css" href="style.css">

</head>

<body bgcolor="#333333">

<table id="Table_01" width="800" height="750" border="0" cellpadding="0" cellspacing="0" align="center">

    <tr>

        <td colspan="4">

            <img src="images/mypimpscript_01.gif" width="800" height="1" alt=""></td>

    </tr>

    <tr>

        <td colspan="4">

            <img src="images/mypimpscript_01_01.gif" width="800" height="139" alt=""></td>

    </tr>

    <tr>

        <td width="800" height="26" colspan="4" bgcolor="#000000">

        <?if(!$id){?>

            <p align="center">

            <b>

            <a href="index.php"><font size="2">Home</font></a><font size="2"> |

            </font>

    <a href="login.php"><font size="2">Login</font></a><font size="2"> |

            </font>

    <a href="signup.php"><font size="2">Signup</font></a><font size="2"> |

            </font>

    <a href="guide.php"><font size="2">Guide</font></a><font size="2"> |

            </font>

    <a href="rules.php"><font size="2">Rules</font></a><font size="2"> |

            </font>

    <a href="winners.php"><font size="2">Winners</font></a><font size="2"> 

            </font></b>

    <?}else{?>

            <p align="center" style="margin-top: 0; margin-bottom: 0"><b>

            <a href="index.php"><font size="2">Home</font></a><font size="2"> |

            </font>

    <a href="play.php"><font size="2">Play</font></a><font size="2"> |

            </font>

    <a href="myaccount.php"><font size="2">My Account</font></a><font size="2"> |

            </font>

    <a href="credits.php"><font size="2">Purchase Credits</font></a><font size="2"> |

            </font>

    <a href="winners.php"><font size="2">Winners</font></a><font size="2"> |

            </font>

    <a href="logout.php"><font size="2">Logout</font></a><font size="2">

            </font></b>

    <?}?>

        </td>

    </tr>

    <tr>

        <td colspan="4">

            <img src="images/mypimpscript_04.gif" width="800" height="17" alt=""></td>

    </tr>

    <tr>

        <td width="8" height="567" rowspan="2" bgcolor="#4C4C4C">

             </td>

        <td width="153" height="558" bgcolor="#4C4C4C" valign="top">

    <?if(!$id){?>

    <table width="100%">

      <tr>

      <td align="left" bgcolor="#BBBBBB">

        <p align="center"><font color="#000000"><b>Login</b></font></td>

      </tr>

    </table>

    <form method="post" action="login.php">

    <table align="center">

      <tr>

      <td align="center">

        <p style="margin-top: 0; margin-bottom: 0"><b>Username:</b></p>

        <p style="margin-top: 0; margin-bottom: 0">

        <input type="text" name="username" size="15"></td><td> </td>

      </tr>

      <tr>

      <td align="center">

        <p style="margin-top: 0; margin-bottom: 0"><b>Password:</b></p>

        <p style="margin-top: 0; margin-bottom: 0">

        <input type="password" name="password" size="15"></td><td>

         </td>

      </tr>

      <tr>

      <td align="center" colspan="2">

        <p style="margin-top: 0; margin-bottom: 0"><input type="submit" name="login" value="Login"></td>

      </tr>

    </table>

    <br>Not a pimp? <a href="signup.php">Become One!</a>, its <b>free!</b>

    <br>Lost your password? <a href="lostpass.php">click here</a>.

    </form>

    <?}?>

    <center>

    <table width="100%">

      <tr>

      <td align="left" bgcolor="#BBBBBB">

        <p align="center"><font color="#000000"><b>News</b></font></td>

      </tr>

    </table>

    <?

    $limitnews = mysql_fetch_array(mysql_query("SELECT numbernews FROM settings;"));

    $getnews = mysql_query("SELECT id,news,posted FROM $tab[news] WHERE id>0 ORDER BY posted DESC limit $limitnews[0];");

    while ($news = mysql_fetch_array($getnews)){?>

    <table width="100%">

      <tr>

      <td align="left"><small><b><?=date("M d, Y", $news[2])?></b></small></td>

      </tr>

      <tr>

      <td><small><?=$news[1]?></small></td>

      </tr>

    </table><br>

    <? }

    $result = mysql_query("Select * From settings");

    $row = mysql_fetch_array($result, MYSQL_BOTH);

    $block = $row['block'];

    $showblock = $row['showblock'];

    $blocktitle = $row['blocktitle'];

 

    ?>

    <? if($showblock == yes) { ?>

    <table width="100%">

      <tr>

      <td align="left" bgcolor="#BBBBBB">

        <p align="center"><font color="#000000"><b><small><?= $blocktitle ?></small></b></font></td>

      </tr>

      <tr>

      <td><?= $block ?></td>

      </tr>

    </table>

    <? } ?>

    <br><br><br>

    <u>

    <font color="#FD8B37"><b>Statistics</b></font></u><br>

    <font color="White">Registered:</font><font color="#FFFFFF"> <?=commas($reg[0])?> <br></font>

    <font color="White">Online:</font><font color="#FFFFFF"><?=commas($online)?><br></font>

    <font color="White">Pimping:</font><font color="#FFFFFF">  <?=commas($pimpin)?><br></font>

    <font color="White">Attacking:</font><font color="#FFFFFF"> <?=commas($attackin)?></small>

    </center>

        </td>

        <td width="635" height="558" bgcolor="#4C4C4C" valign="top">

        <?if ($showads == 1 && $adverts != ""){echo ?><center><?= $adverts;?></center><br><?}?>

 

        <?

        }

        function sitefooter(){

        global $site, $tab, $id, $domain, $adminemail, $showads, $showblock, $bottomadverts;

        $user = mysql_fetch_array(mysql_query("SELECT status FROM $tab[user] WHERE id='$id';"));

        ?>

        <?if ($showads == 1 && $bottomadverts != ""){echo ?><center><?= $bottomadverts;?></center><br><?}?>

        </td>

        <td width="4" height="567" rowspan="2" bgcolor="#4C4C4C">

            <img src="images/spacer.gif" width="4" height="567" alt=""></td>

    </tr>

    <tr>

        <td width="788" height="9" colspan="2" bgcolor="#4C4C4C">

        </td>

    </tr>

</table>

<p align="center">

<font color="#FFFFFF">Script from:

</font>

<font color="black">

<a href="http://www.mypimpscript.com"><font color="#FBAA6E">MyPimpScript.com</font></a></font><font color="#FFFFFF">, Copyright 2006 <?=$domain?> </font>

 

</body>

</html>

<?

}

?>

 

 

 

King

 

the way to do it is check for a active game then print the resulting tables.

 


<table>
<tr>
<td>

<?php
If ($activegames>=1){

echo "<table>"
. "<tr>"
. "<td>"
. "Table 1"
. "</td>"
. "</tr>"
. "</table>"
. "</td>";

} 

If ($activegames>=2){

echo "<td>"
. "<table>"
. "<tr>"
. "<td>"
. "Table 2"
. "</td>"
. "</tr>"
. "</table>"
. "</td>"
. "</tr>";

}

</table>
?>

 

ect...ect...ect...

  • 3 weeks later...

I got a code that generates rows in a table from a mysql fetch. It works almost as it should, but it generates them verticaly and I need them to be horizontaly..

 

Code for verticaly generated rows

 

<table width="100%" height="100%" border="0">
    <tr>
     <td align="center" height="12"><FONT SIZE=3><STRONG><b>Heading text. Appears only once!</FONT></b></td>
    </tr><p><br>
    <tr>	
    </tr>

     <td align="center" valign="top">
     <?
          if($msg == disabled){?><br><font color="#FF9900"><b>Some text goes here</b></font><br><?}
          if($msg == select){?><br><font color="#FF9900"><b>Some text goes here</b></font><br><?}
      elseif($msg){?><br><font color="#FF9900"><b><?=$msg?></b></font><br><?}?>
     <?
// pinoywebdev add s
$time = cln($time);
// pinoywebdev add e
     $get = mysql_query("SELECT 1,2 FROM $tab[game] WHERE ends>'$time' ORDER BY round ASC;");
     while ($game = mysql_fetch_array($get)){ output($game[0],$game[1]); }
     ?>
     </td>
    </tr>
   </table>

 

How can I make this code generates new table coloms instead of rows  ???

 

Plz help

 

 

 

King

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.