Passing php variable to javascript (cant get it working) - php
I'm have a problem getting a php variable to my .js file and make it work.
This is my php function where I'm trying to pass the variable:
function java_scr_preview ($foto)
{
echo '<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>';
echo '<script type="text/javascript">';
echo 'var pass_this_variable = "'.$foto.'"';
echo '</script>';
echo '<script type="text/javascript" src="ddimgtooltip.js">';
echo '<SCRIPT LANGUAGE="JavaScript">';
echo 'function Preview(url)';
echo '{';
echo "window.open(url,'_blank','location=no,scrollbars=yes,toolbar=no,width=500,height=700')";
echo '}';
echo '</SCRIPT>';
}
This is my whole php script (if needed)
<?php
require ("auth.php");
if (isset($_GET['cmd']))
$cmd = $_GET['cmd'];
else
$cmd = "";
switch ($cmd) {
case "":
html_open_std ();
ingave_artikel ("", "", "", "");
html_close ();
break;
case "search":
html_open_std ();
ingave_artikel ("", "", "", "");
toon_banden ();
html_close ();
break;
case "preview":
$foto = $_GET['foto'];
toon_preview ($foto);
break;
}
#------------------------------------------------------------
function ingave_artikel ($art1, $art2, $art3, $errormelding)
{
global $urlphp;
global $urlcgi;
global $ad;
echo "<div id=\"invoeren\">";
echo "<h1>Ingave bandenmaat</h1>\n";
echo "<form method=\"POST\" action=\"?cmd=search\">\n";
echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\">\n";
echo "<tr>\n";
echo "<td>Breedte</td>\n";
echo "<td> </td>\n";
echo "<td>Hoogte</td>\n";
echo "<td> </td>\n";
echo "<td>Diameter</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type=\"text\" name=\"art1\" value=\"" . $art1 .
"\" size=\"5\"></td>\n";
echo "<td>/</td>\n";
echo "<td><input type=\"text\" name=\"art2\" value=\"" . $art2 .
"\" size=\"5\"></td>\n";
echo "<td>x</td>\n";
echo "<td><input type=\"text\" name=\"art3\" value=\"" . $art3 .
"\" size=\"5\"></td>\n";
echo "</tr>\n";
if (! empty ($errormelding))
echo "<tr><td colspan=\"5\"><font color=\"red\">" .
$errormelding . "</td></tr>\n";
echo "<tr>\n";
echo "<td colspan=\"3\">\n";
echo "<input type=\"submit\" value=\"Verwerk\">\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</form>\n";
echo "</div>\n";
}
#------------------------------------------------------------
function toon_banden ()
{
global $urlphp;
global $urlcgi;
global $gateway;
java_scr_preview ();
$art1 = trim($_POST["art1"]);
$art2 = trim($_POST["art2"]);
$art3 = trim($_POST["art3"]);
if (empty ($art1) || empty ($art3)) {
ingave_artikel ($art1, $art2, $art3,
"Alle velden ingeven s.v.p.");
return (-1);
}
$f = open_url ($gateway . "?3," . $art1 . $art2 . "R" . $art3);
if ($f == NULL)
return (-1);
$t = 0;
$ncol = 4;
$ar = explode (PHP_EOL, $f);
if (substr($ar[0],0,7) == "*ERROR*") {
echo "<p>";
echo "<h1>";
echo "Gateway functions are disabled !" . "<br>";
echo "</p>";
return (-1);
}
foreach ($ar as $rec) {
if ($rec == 0) {
continue;
}
list ($sysnr,
$artikel,
$merk,
$rubriek,
$omschrijving,
$valuta,
$netto,
$bruto,
$beschikbaar,
$foto,
$draagvrm,
$levid,
$garpr,
$altpr,
$eancode) = explode ("\t", $rec);
if ($sysnr == "*END*")
break;
if ($t == 0) {
echo "<table border=0 cellspacing=0 cellpadding=0>";
echo "<tr><td align=center>";
echo "<div id=\"uitkomst\">";
echo "<h1>Overzicht beschikbare voorraad</h1>\n";
echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"5\">\n";
echo "<td><b>Merk</td>\n";
echo "<td><b>Omschrijving</td>\n";
echo "<td><b>LI/SI</td>\n";
echo "<td align=\"right\"><b>Bruto</td>\n";
echo "<td align=\"right\"><b>Netto " . $valuta . "</td>\n";
echo "<td align=\"right\"><b>Beschikbaar</td>\n";
echo "<td></td>\n";
}
### klantprijs opslag 25 %
$klantpr = $netto * 1.25;
$klantpr_str = sprintf ("%7.2f", $klantpr);
echo "<tr>\n";
echo "<td>" . $merk . "</td>\n";
echo "<td>" . $omschrijving . "</td>\n";
echo "<td>" . $draagvrm . "</td>\n";
echo "<td align=\"right\">" . $bruto . "</td>\n";
echo "<td align=\"right\">" . $klantpr_str . "</td>\n";
echo "<td align=\"right\">" . $beschikbaar . "</td>\n";
if (empty ($foto))
echo "<td></td>\n";
else {
echo "<td>";
echo '<a rel="imgtip[2]" href="javascript:Preview';
echo "('?cmd=preview&foto=$foto')";
echo '">';
echo "Foto";
echo '</a>';
echo "</td>\n";
}
echo "</tr>\n";
$t++;
}
if ($t == 0)
ingave_artikel ($art1, $art2, $art3,
"Geen artikelen gevonden !");
else {
echo '</table>';
echo '</div>';
}
}
#------------------------------------------------------------
function toon_preview ($fotonr)
{
global $imglarge;
html_open_std ();
echo '<center>';
echo '<br>';
echo '<img border="0" src="' . $imglarge . '/' . $fotonr . '">';
html_close ();
}
#------------------------------------------------------------
function toon_selektie ($merk, $model, $type, $diameter)
{
echo '<table border="0" cellspacing="0" cellpadding="0">';
echo '<tr><td width="70">Merk</td><td><b>' . $merk . '</td></tr>';
echo '<tr><td>Model</td><td><b>' . $model . '</td></tr>';
echo '<tr><td>Type</td><td><b>' . $type . '</td></tr>';
echo '<tr><td>Diameter</td><td><b>' . $diameter . '</td></tr>';
echo '</table>';
echo '<hr>';
}
#------------------------------------------------------------
function open_url ($url)
{
global $login;
global $passwd;
$ch = curl_init("http://$url");
curl_setopt($ch, CURLOPT_USERPWD, "$login:$passwd");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$file = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$errno = curl_errno($ch);
$error = curl_error($ch);
if ($status == 200) {
return ($file);
}
else {
echo "<p>";
echo "<h1>";
if ($status == 401) {
echo "Authentication failed !";
}
else {
echo "Errno: " . $errno . "<br>";
echo "Error: " . $error . "<br>";
echo "HTTP status : " . $status . "<br>";
}
echo "</p>";
return (NULL);
}
}
#------------------------------------------------------------
function html_open_std ()
{
echo '<html>';
echo '<head>';
echo '<title>Banden uit voorraad leverbaar</title>';
echo '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">';
echo '<meta name="robots" content="noinclude, nofollow">';
echo '<link rel="stylesheet" href="tyre.css" type="text/css">';
echo '</head>';
echo '<body>';
}
#------------------------------------------------------------
function html_close ()
{
echo "</body>";
echo "</html>";
}
#------------------------------------------------------------
function java_scr_preview ($foto)
{
echo '<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>';
echo '<script type="text/javascript">';
echo 'var pass_this_variable = "'.$foto.'"';
echo '</script>';
echo '<script type="text/javascript" src="ddimgtooltip.js">';
echo '<SCRIPT LANGUAGE="JavaScript">';
echo 'function Preview(url)';
echo '{';
echo "window.open(url,'_blank','location=no,scrollbars=yes,toolbar=no,width=500,height=700')";
echo '}';
echo '</SCRIPT>';
}
?>
And this is my whole .js file:
It is a tooltip script and I want to show my images dynamicly:
/* Image w/ description tooltip v2.0
* Created: April 23rd, 2010. This notice must stay intact for usage
* Author: Dynamic Drive at http://www.dynamicdrive.com/
* Visit http://www.dynamicdrive.com/ for full source code
*/
var ddimgtooltip={
tiparray:function(){
var tooltips=[]
//define each tooltip below: tooltip[inc]=['path_to_image', 'optional desc', optional_CSS_object]
//For desc parameter, backslash any special characters inside your text such as apotrophes ('). Example: "I\'m the king of the world"
//For CSS object, follow the syntax: {property1:"cssvalue1", property2:"cssvalue2", etc}
tooltips[0]=["red_balloon.gif", "Here is a red balloon<br /> on a white background", {background:"#FFFFFF", color:"black", border:"5px ridge darkblue"}]
tooltips[1]=["duck2.gif", "Here is a duck on a light blue background.", {background:"#DDECFF", width:"200px"}]
tooltips[2]=["http://www.website.net/preview/test/pass_this_variable"]
tooltips[3]=["../dynamicindex17/bridge.gif", "Bridge to somewhere.", {background:"white", font:"bold 12px Arial"}]
return tooltips //do not remove/change this line
}(),
tooltipoffsets: [20, -30], //additional x and y offset from mouse cursor for tooltips
//***** NO NEED TO EDIT BEYOND HERE
tipprefix: 'imgtip', //tooltip ID prefixes
createtip:function($, tipid, tipinfo){
if ($('#'+tipid).length==0){ //if this tooltip doesn't exist yet
return $('<div id="' + tipid + '" class="ddimgtooltip" />').html(
'<div style="text-align:center"><img src="' + tipinfo[0] + '" /></div>'
+ ((tipinfo[1])? '<div style="text-align:left; margin-top:5px">'+tipinfo[1]+'</div>' : '')
)
.css(tipinfo[2] || {})
.appendTo(document.body)
}
return null
},
positiontooltip:function($, $tooltip, e){
var x=e.pageX+this.tooltipoffsets[0], y=e.pageY+this.tooltipoffsets[1]
var tipw=$tooltip.outerWidth(), tiph=$tooltip.outerHeight(),
x=(x+tipw>$(document).scrollLeft()+$(window).width())? x-tipw-(ddimgtooltip.tooltipoffsets[0]*2) : x
y=(y+tiph>$(document).scrollTop()+$(window).height())? $(document).scrollTop()+$(window).height()-tiph-10 : y
$tooltip.css({left:x, top:y})
},
showbox:function($, $tooltip, e){
$tooltip.show()
this.positiontooltip($, $tooltip, e)
},
hidebox:function($, $tooltip){
$tooltip.hide()
},
init:function(targetselector){
jQuery(document).ready(function($){
var tiparray=ddimgtooltip.tiparray
var $targets=$(targetselector)
if ($targets.length==0)
return
var tipids=[]
$targets.each(function(){
var $target=$(this)
$target.attr('rel').match(/\[(\d+)\]/) //match d of attribute rel="imgtip[d]"
var tipsuffix=parseInt(RegExp.$1) //get d as integer
var tipid=this._tipid=ddimgtooltip.tipprefix+tipsuffix //construct this tip's ID value and remember it
var $tooltip=ddimgtooltip.createtip($, tipid, tiparray[tipsuffix])
$target.mouseenter(function(e){
var $tooltip=$("#"+this._tipid)
ddimgtooltip.showbox($, $tooltip, e)
})
$target.mouseleave(function(e){
var $tooltip=$("#"+this._tipid)
ddimgtooltip.hidebox($, $tooltip)
})
$target.mousemove(function(e){
var $tooltip=$("#"+this._tipid)
ddimgtooltip.positiontooltip($, $tooltip, e)
})
if ($tooltip){ //add mouseenter to this tooltip (only if event hasn't already been added)
$tooltip.mouseenter(function(){
ddimgtooltip.hidebox($, $(this))
})
}
})
}) //end dom ready
}
}
//ddimgtooltip.init("targetElementSelector")
ddimgtooltip.init("*[rel^=imgtip]")
And this rule:
tooltips[2]=["http://www.website.net/preview/test/pass_this_variable"]
Should show the variable $foto...
Anyone can help me to fix this? Working 2 days on it now and cant figure it out...
Update
I've tried some things and I manage to get some info to my javascript like this:
.php file
function java_scr_preview ()
{
echo '<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>';
?>
<?php
$foto = "image.jpg";
?>
<script type="text/javascript">
var foto = "<?= $foto ?>";
</script>
<?php
echo '<script type="text/javascript" src="ddimgtooltip.js">';
echo '<SCRIPT LANGUAGE="JavaScript">';
echo 'function Preview(url)';
echo '{';
echo "window.open(url,'_blank','location=no,scrollbars=yes,toolbar=no,width=500,height=700')";
echo '}';
echo '</SCRIPT>';
}
?>
.js file
tooltips[2]=["http://www.website.net/preview/test/"+ foto];
alert(tooltips[2]);
This is showing http://www.website.net/preview/test/image.jpg in my alert...
But when I'm doing it like this:
$foto = $_GET["foto"];
I'm getting an error :
Notice: Undefined index: foto in /var/www/html/website.nl/test/test.php on line 291
And in my alert only http://www.website.net/preview/test/...
How should I pass my dynamic variable?
Change
tooltips[2]=["http://www.website.net/preview/test/pass_this_variable"]
to
tooltips[2]=["http://www.website.net/preview/test/" + pass_this_variable]
You were not using the variable you were just passing text.
Simplified example here
In function toon_banden() you call java_scr_preview() and you are not passing the expected arg.
Related
PHP For Loop jQuery UI Tabs
I am trying to display a list of Links in a table according to Distance and Category. I would like each distance to be a Tab and have the appropriate Links in each Tab. I am trying to accomplish this with A PHP Foreach loop and jQuery-UI Tabs. Here is the code which gets the data and displays it in the table in each Tab. The index function in the controller for the View and the function that gets the table data: public function index() { $data = array(); $db_name = $this->uri->segment(2); $this->db->db_select($db_name); $tables = $this->db->get('tableinfo'); $data['distances'] = array(); $data['tables'] = array( 'men' => array(), 'women' => array() ); foreach($tables->result() as $row) { if(!in_array($row->distance, $data['distances'])) { array_push($data['distances'], $row->distance); } if(substr($row->displayname, 0, 4) == "Male") { array_push($data["tables"]['men'], $row->displayname); } else { array_push($data["tables"]['women'], $row->displayname); } } $data['dbname'] = $db_name; $this->parser->parse('templates/header', $data); $this->parser->parse('select/index', $data); $this->parser->parse('templates/footer', $data); } public function gettable($table) { $db_name = "championchipco_sowetomarathon2019"; $this->db->db_select($db_name); redirect("results/index/" . $db_name . "/" . $table); } And the View: <?php $i = 1; echo "<div class='row'>"; echo "<div class='col' id='tabs'>"; echo "<ul>"; foreach($distances as $distance) { echo "<li><a href='#tabs-" . $i . "'>" . $distance . "</a></li>"; } echo "</ul>"; foreach($distances as $distance) { echo "<div id='tabs-" . $i . "'>"; echo "<table class='table' cellspacing='10' cellpadding='10'>"; echo "<tr><th style='font-size: 20px;'>Men</th><th style='font-size: 20px;'>Women</th><th style='font-size: 20px;'></tr>"; foreach($tables['men'] as $table) { if(substr($table, -4) == $distance) { echo "<tr>"; echo '<td>' . $tables['men'][$i] . '</td>'; echo '<td>' . $tables['women'][$i] . '</td>'; echo "</tr>"; } } echo "</table>"; echo "</div>"; $i++; } echo "</div>"; echo "</div>"; ?> At the moment, all of the data is being displayed in every Tab, instead of only display the Links for the particular category in a different tab. I can see that the 2nd table of Men and Women is slightly to the left of the top one so I think the loop is causing something to go wrong. I have tried re-arranging the way the loops display the data in the View but cannot seem to get only the 10KM in the 10KM Tab, 21KM in 21KM Tab, etc.
Get the data of your second foreach by Ajax it will made your need simple I mentioned to remove below foreach foreach($distances as $distance) { echo "<div id='tabs-" . $i . "'>"; echo "<table class='table' cellspacing='10' cellpadding='10'>"; echo "<tr><th style='font-size: 20px;'>Men</th><th style='font-size: 20px;'>Women</th><th style='font-size: 20px;'></tr>"; foreach($tables['men'] as $table) { if(substr($table, -4) == $distance) { echo "<tr>"; echo '<td>' . $tables['men'][$i] . '</td>'; echo '<td>' . $tables['women'][$i] . '</td>'; echo "</tr>"; } } echo "</table>"; echo "</div>"; $i++; }
Trying to generate a html file from PHP code [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 6 years ago. Improve this question I have a PHP program from OpenEMR that prints context to the console in HTML format. I wanted to save whatever it prints to another html file. I am not very familiar with PHP and front end technologies. Does anyone know a simple way to make it work? Thanks a lot. Below is the code detail: foreach($newpatient as $patient){ /* $inclookupres = sqlStatement("select distinct formdir from forms where pid='".$pids[$iCounter]."'"); while($result = sqlFetchArray($inclookupres)) { include_once("{$GLOBALS['incdir']}/forms/" . $result{"formdir"} . "/report.php"); } */ print "<div id='superbill_patientdata'>"; print "<h1>".xlt('Patient Data').":</h1>"; printRecDataOne($patient_data_array, getRecPatientData ($pids[$iCounter]), $N); print "</div>"; print "<div id='superbill_insurancedata'>"; print "<h1>".xlt('Insurance Data').":</h1>"; print "<h2>".xlt('Primary').":</h2>"; printRecDataOne($insurance_data_array, getRecInsuranceData ($pids[$iCounter],"primary"), $N); print "<h2>".xlt('Secondary').":</h2>"; printRecDataOne($insurance_data_array, getRecInsuranceData ($pids[$iCounter],"secondary"), $N); print "<h2>".xlt('Tertiary').":</h2>"; printRecDataOne($insurance_data_array, getRecInsuranceData ($pids[$iCounter],"tertiary"), $N); print "</div>"; print "<div id='superbill_billingdata'>"; print "<h1>".xlt('Billing Information').":</h1>"; if (count($patient) > 0) { $billings = array(); echo "<table width='100%'>"; echo "<tr>"; echo "<td class='bold' width='10%'>".xlt('Date')."</td>"; echo "<td class='bold' width='20%'>".xlt('Provider')."</td>"; echo "<td class='bold' width='40%'>".xlt('Code')."</td>"; echo "<td class='bold' width='10%'>".xlt('Fee')."</td></tr>\n"; $total = 0.00; $copays = 0.00; //foreach ($patient as $be) { $ta = split(":",$patient); $billing = getPatientBillingEncounter($pids[$iCounter],$ta[1]); $billings[] = $billing; foreach ($billing as $b) { // grab the date to reformat it in the output $bdate = strtotime($b['date']); echo "<tr>\n"; echo "<td class='text' style='font-size: 0.8em'>" . oeFormatShortDate(date("Y-m-d",$bdate)) . "<BR>" . date("h:i a", $bdate) . "</td>"; echo "<td class='text'>" . text($b['provider_name']) . "</td>"; echo "<td class='text'>"; echo text($b['code_type']) . ":\t" . text($b['code']) . " ". text($b['modifier']) . " " . text($b['code_text']) . " "; echo "</td>\n"; echo "<td class='text'>"; echo oeFormatMoney($b['fee']); echo "</td>\n"; echo "</tr>\n"; $total += $b['fee']; } // Calculate the copay for the encounter $copays = getPatientCopay($pids[$iCounter],$ta[1]); //} echo "<tr><td> </td></tr>"; echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xlt('Sub-Total')."</td><td class='text'>" . oeFormatMoney($total + abs($copays)) . "</td></tr>"; echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xlt('Copay Paid')."</td><td class='text'>" . oeFormatMoney(abs($copays)) . "</td></tr>"; echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xlt('Total')."</td><td class='text'>" . oeFormatMoney($total) . "</td></tr>"; echo "</table>"; echo "<pre>"; //print_r($billings); echo "</pre>"; } echo "</div>";
<?php ob_start(); /* YOUR CODE */ $page= ob_get_contents(); if ($fp = fopen('../page.htm', 'w+')) { fwrite ($fp, $page); fclose($fp); } ob_end_flush(); ?>
Reading Line by Line Using PHP Via JSON String
I am trying to create a PHP function which will allow me to read selected lines from a text file using a JSON string. The JSON string consists of two numbers separated by a comma. The first number is the line I want to seek, and the second is the number of lines to read going downward. For example, I have this sentence in a separate text file: A diving spiral attack in which Pikachu head butts downward while being surrounded by electricity. (If you're wondering, this is part of my upcoming fan site, still under construction). The sentence starts at line 6, and uses up 2 lines. So in my JSON file, I would write "6,2". The explode() command is ran using the comma as the delimiter, allowing me to store these number into two individual variables, $start and $length. $result = explode(",", $sample); // In JSON string, $sample is $i["desc"] $start = $result[0]; $length = $result[1]; With the variables now in place, the following lines will then be called to perform the actual line-by-line extraction. $file = new SplFileObject("pikachu/pikachu.txt"); for ($i = $start; $i <= ($start+$length); $i++) { $file->seek($i-1); echo "$file"; } I did a test of my script using a direct call instead of through JSON parsing. That worked. But when I tried to use the JSON string, I ended up with both a Runtime and a Fatal Error. How do I fix the scripts so that I can use the JSON string as markers for seeking lines from an external text to print while avoiding the Runtime and Fatal Errors? (EDIT: The problem became too difficult for me to fix, so I've decided to ditch the line-by-line seek feature for now. I will revisit this on a later date. I will leave the code below for archival purposes.) character.php <?php $name = $_GET['name']; // Step 1: Get the name from the previous page and store it. $file = file_get_contents("characters/$name/$name.json"); // Step 2: Use the name to find a JSON file for the character (We'll do the moves list later). $json = json_decode($file, true); // Step 3: Decode the JSON file $character = $json["character"][0]["name"]; $group = $json["character"][0]["group"]; $series = $json["character"][0]["series"]; $story = $json["character"][0]["story"]; $snapback = $json["character"][0]["snapback"]; $interrupt = $json["character"][0]["interrupt"]; $hiddenpow = $json["character"][0]["hiddenpow"]; $disrupt = $json["character"][0]["disrupt"]; $assist1 = $json["character"][0]["assist1"]; $assist2 = $json["character"][0]["assist2"]; $assist3 = $json["character"][0]["assist3"]; $counter = $json["character"][0]["counter"]; $bros = $json["character"][0]["bros"]; $party = $json["character"][0]["party"]; $ground = $json["character"][0]["ground"]; $jump = $json["character"][0]["jump"]; $superjump = $json["character"][0]["superjump"]; $launcher = $json["character"][0]["launcher"]; $altlaunch = $json["character"][0]["altlaunch"]; $acfinisher = $json["character"][0]["acfinisher"]; // Step 4: Retrieve variables and store them for use echo "<HTML>\n"; echo "<HEAD>\n"; echo "<TITLE>Marvel & Capcom vs. Pokemon: $character</TITLE>\n\n"; echo "<LINK rel=\"stylesheet\" type=\"text/css\" href=\"http://fonts.googleapis.com/css?family=Roboto\">\n"; echo "<LINK rel=\"stylesheet\" type=\"text/css\" href=\"http://fonts.googleapis.com/css?family=Open+Sans\">\n"; echo "<LINK rel=\"stylesheet\" type=\"text/css\" href=\"media/style.css\">\n"; echo "<SCRIPT type=\"text/javascript\" src=\"media/tabs.js\"></SCRIPT>\n"; echo "<SCRIPT type=\"text/javascript\">\n"; echo "function toggle_visibility(id) {\n"; echo " var movename = id.nextSibling.nextSibling;\n"; echo " if(movename.style.display == \"block\")\n"; echo " movename.style.display = \"none\";\n"; echo " else\n"; echo " movename.style.display = \"block\";\n"; echo "}\n"; echo "</SCRIPT>"; echo "</HEAD>\n\n"; echo "<BODY onload=\"init()\">\n\n"; // Step 5: The HTML stuff begins echo "<TABLE id=\"Character\">\n"; echo " <TR>\n"; echo " <TD class=\"Name\">" . strtoupper($character) . "</TD>\n"; echo " <TD class=\"Image\" rowspan=\"4\"><IMG src=\"characters/$name/$name.jpg\"></TD></TR>\n"; echo " <TR>\n"; echo " <TD class=\"Series\">Series: $series</TD></TR>\n"; echo " <TR>\n"; echo " <TD class=\"Story\">$story</TD></TR>\n"; // Step 6: Write the variables to the file echo " <TR>\n"; echo " <TD style=\"vertical-align: top\">\n"; echo " <TABLE id=\"$group\">\n"; function moverw ($move) { $subfollow = "FOLLOW>>"; $follow = "FOLLOW>"; if (strpos($move,$subfollow) !== false) $move .= " (followup)"; else if (strpos($move,$follow) !== false) $move .= " (followup)"; $move = str_replace("FOLLOW>>", "<IMG class=\"Followup\" src=\"images/follow.png\" style=\"text-indent: 5px\"> ", $move); $move = str_replace("FOLLOW>", "<IMG class=\"Followup\" src=\"images/follow.png\"> ", $move); return ($move); } function descrw ($desc,$name) { $result = explode(",", $desc); $start = $result[0]; $length = $result[1]; $file = new SplFileObject("characters/$name/$name.txt"); $result = ""; for ($i = $start; $i <= ($start+$length); $i++) { $file->seek($i-1); $result .= $file; } return($result); } function commrw ($command) { $command = str_replace("AM,", "<IMG title=\"Assist Mode\" src=\"images/assist.gif\"> ", $command); $command = str_replace("SM,", "<IMG title=\"Single Mode\" src=\"images/single.gif\"> ", $command); $command = str_replace("BRAWL,", "<IMG title=\"Super Smash Brawl\" src=\"images/brawl.png\"> ", $command); $command = str_replace("uf,", "<IMG class=\"Arrow\" src=\"images/uf.png\">", $command); $command = str_replace("df,", "<IMG class=\"Arrow\" src=\"images/df.png\">", $command); $command = str_replace("ub,", "<IMG class=\"Arrow\" src=\"images/ub.png\">", $command); $command = str_replace("db,", "<IMG class=\"Arrow\" src=\"images/db.png\">", $command); $command = str_replace("u,", "<IMG class=\"Arrow\" src=\"images/u.png\">", $command); $command = str_replace("f,", "<IMG class=\"Arrow\" src=\"images/f.png\">", $command); $command = str_replace("d,", "<IMG class=\"Arrow\" src=\"images/d.png\">", $command); $command = str_replace("b,", "<IMG class=\"Arrow\" src=\"images/b.png\">", $command); $command = str_replace("+", "<IMG class=\"Plus\" src=\"images/plus.png\">", $command); $command = str_replace("AP", "<IMG class=\"Button\" src=\"images/punch.png\">", $command); $command = str_replace("AK", "<IMG class=\"Button\" src=\"images/kick.png\">", $command); $command = str_replace("A1", "<IMG class=\"Button\" title=\"Assist 1\" src=\"images/assist1.png\">", $command); $command = str_replace("A2", "<IMG class=\"Button\" title=\"Assist 2\" src=\"images/assist2.png\">", $command); $command = str_replace("AB", "<IMG class=\"Button\" title=\"Assist\" src=\"images/assist.png\">", $command); $command = str_replace("LP", "<IMG class=\"Button\" title=\"Jab\" src=\"images/jab.png\">", $command); $command = str_replace("LK", "<IMG class=\"Button\" title=\"Short\" src=\"images/short.png\">", $command); $command = str_replace("MP", "<IMG class=\"Button\" title=\"Strong\" src=\"images/strong.png\">", $command); $command = str_replace("MK", "<IMG class=\"Button\" title=\"Forward\" src=\"images/forward.png\">", $command); $command = str_replace("HP", "<IMG class=\"Button\" title=\"Fierce\" src=\"images/fierce.png\">", $command); $command = str_replace("HK", "<IMG class=\"Button\" title=\"Roundhouse\" src=\"images/roundhouse.png\">", $command); $command = str_replace("FOLLOW>>", "<IMG class=\"Followup\" src=\"images/follow.png\" style=\"text-indent: 5px\"> ", $command); $command = str_replace("FOLLOW>", "<IMG class=\"Followup\" src=\"images/follow.png\"> ", $command); $command = str_replace("degrees", "°", $command); return ($command); } function typerw ($type) { $type = str_replace("BUG.", "<IMG src=\"images/bug.png\">", $type); $type = str_replace("CYBER.", "<IMG src=\"images/cyber.png\">", $type); $type = str_replace("DARK.", "<IMG src=\"images/dark.png\">", $type); $type = str_replace("DRAGON.", "<IMG src=\"images/dragon.png\">", $type); $type = str_replace("ELECTRIC.", "<IMG src=\"images/electric.png\">", $type); $type = str_replace("FAIRY.", "<IMG src=\"images/fairy.png\">", $type); $type = str_replace("FIGHTING.", "<IMG src=\"images/fighting.png\">", $type); $type = str_replace("FIRE.", "<IMG src=\"images/fire.png\">", $type); $type = str_replace("FLYING.", "<IMG src=\"images/flying.png\">", $type); $type = str_replace("GHOST.", "<IMG src=\"images/ghost.png\">", $type); $type = str_replace("GRASS.", "<IMG src=\"images/grass.png\">", $type); $type = str_replace("GROUND.", "<IMG src=\"images/ground.png\">", $type); $type = str_replace("ICE.", "<IMG src=\"images/ice.png\">", $type); $type = str_replace("LIGHT.", "<IMG src=\"images/light.png\">", $type); $type = str_replace("NORMAL.", "<IMG src=\"images/normal.png\">", $type); $type = str_replace("PSYCHIC.", "<IMG src=\"images/psychic.png\">", $type); $type = str_replace("STEEL.", "<IMG src=\"images/steel.png\">", $type); $type = str_replace("WATER.", "<IMG src=\"images/water.png\">", $type); return ($type); } function noterw ($note) { $note = str_replace(".AM.", "<IMG title=\"Assist Mode\" src=\"images/assist.gif\"> ", $note); $note = str_replace(".SM.", "<IMG title=\"Single Mode\" src=\"images/single.gif\"> ", $note); $note = str_replace(".HP.", "<IMG class=\"HiddenPower\" title=\"Hidden Power\"src=\"images/hiddenpower.png\">", $note); return ($note); } foreach ($json["character"][0]["moves"] as $i) { if ($i["flag"] == "normal") { $move = strtoupper($i["move"]); $desc = $i["desc"]; $command = $i["comm"]; $type = $i["type"]; $note = $i["note"]; echo " <TR>\n"; echo " <TD class=\"MoveName Normal\">" . moverw($move) . "\n"; echo " <DIV class=\"Details\">" . descrw($desc,$name) . "</DIV></TD>\n"; echo " <TD class=\"Command\">" . commrw($command) . "</TD>\n"; echo " <TD class=\"Type\">" . typerw($type) . "</TD>\n"; echo " <TD class=\"Note\">" . noterw($note) . "</TD></TR>\n"; } if ($i["flag"] == "special") { $move = strtoupper($i["move"]); $command = $i["comm"]; $type = $i["type"]; $note = $i["note"]; echo " <TR>\n"; echo " <TD class=\"MoveName Special\">" . moverw($move) . "\n"; echo " <DIV class=\"Details\">" . $i["desc"] . "</DIV></TD>\n"; echo " <TD class=\"Command\">" . commrw($command) . "</TD>\n"; echo " <TD class=\"Type\">" . typerw($type) . "</TD>\n"; echo " <TD class=\"Note\">" . noterw($note) . "</TD></TR>\n"; } if ($i["flag"] == "hyper") { $move = strtoupper($i["move"]); $command = $i["comm"]; $type = $i["type"]; $note = $i["note"]; echo " <TR>\n"; echo " <TD class=\"MoveName Hyper\">" . moverw($move) . "\n"; echo " <DIV class=\"Details\">" . $i["desc"] . "</DIV></TD>\n"; echo " <TD class=\"Command\">" . commrw($command) . "</TD>\n"; echo " <TD class=\"Type\">" . typerw($type) . "</TD>\n"; echo " <TD class=\"Note\">" . noterw($note) . "</TD></TR>\n"; } if ($i["flag"] == "final") { $move = strtoupper($i["move"]); $command = $i["comm"]; $type = $i["type"]; $note = $i["note"]; echo " <TR>\n"; echo " <TD class=\"MoveName Final\">" . moverw($move) . "\n"; echo " <DIV id=\"Final\" class=\"Details\">" . $i["desc"] . "</DIV></TD>\n"; echo " <TD class=\"Command\">" . commrw($command) . "</TD>\n"; echo " <TD class=\"Type\">" . typerw($type) . "</TD>\n"; echo " <TD class=\"Note\">" . noterw($note) . "</TD></TR>\n"; } } // Step 7: Write the moves. When Command and Type are parsed, execute respective rewriters. Saves me from typing lots, hun ;) echo " </TABLE></TD></TR>\n"; echo " <TR>\n"; echo " <TD colspan=\"2\">\n"; echo " <UL id=\"tabs\">\n"; echo " <LI>SINGLE MODE</LI>\n"; echo " <LI>ASSIST MODE</LI>\n"; echo " <LI>COMBO PROFILE</LI>\n"; echo " <LI>ATTACK PROFILE</LI></UL>\n"; echo " <DIV class=\"tabContent\" id=\"Single\">\n"; echo " <TABLE id=\"Single\" border=1>\n"; echo " <TR>\n"; echo " <TH>Snapback:</TH>\n"; echo " <TD>$snapback</TD></TR>\n"; echo " <TR>\n"; echo " <TH>Interrupt:</TH>\n"; echo " <TD>$interrupt</TD></TR>\n"; echo " <TR>\n"; echo " <TH>Hidden Power:</TH>\n"; echo " <TD>$hiddenpow</TD></TR>\n"; echo " <TR>\n"; echo " <TH class=\"Header Rumble\"colspan=\"2\">RUMBLE CHART</TH></TR>\n"; echo " <TR>\n"; echo " <TD colspan=\"2\"></TH></TR></TABLE></DIV>\n"; echo " <DIV class=\"tabContent\" id=\"Assist\">\n"; echo " <TABLE id=\"Assist\" border=1>\n"; echo " <TR>\n"; echo " <TH>Disrupt:</TH>\n"; echo " <TD>$disrupt</TD></TR>\n"; echo " <TR>\n"; echo " <TH colspan=2>Assist Attacks</TH></TR>\n"; echo " <TR>\n"; echo " <TH><IMG class=\"Button\" title=\"Assist\" src=\"images/assist.png\"></TH>\n"; echo " <TD>$assist1</TD></TR>\n"; echo " <TR>\n"; echo " <TH><IMG class=\"Button\" title=\"Assist\" src=\"images/assist.png\"><IMG class=\"Plus\" src=\"images/plus.png\"><IMG class=\"Button\" title=\"Fierce\" src=\"images/fierce.png\"></TH>\n"; echo " <TD>$assist2</TD></TR>\n"; echo " <TR>\n"; echo " <TH><IMG class=\"Button\" title=\"Assist\" src=\"images/assist.png\"><IMG class=\"Plus\" src=\"images/plus.png\"><IMG class=\"Button\" title=\"Roundhouse\" src=\"images/roundhouse.png\"></TH>\n"; echo " <TD>$assist3</TD></TR>\n"; echo " <TR>\n"; echo " <TH>Cross-Over Counter:</TH>\n"; echo " <TD>$counter</TD></TR>\n"; echo " <TR>\n"; echo " <TH colspan=2>Super Smash Melee</TH></TR>\n"; echo " <TR>\n"; echo " <TH>Bros. Attack:</TH>\n"; echo " <TD>$bros</TD></TR>\n"; echo " <TR>\n"; echo " <TH>Party Attack:</TH>\n"; echo " <TD>$party</TD></TR></TABLE></DIV>\n"; echo " <DIV class=\"tabContent\" id=\"Combo\">\n"; echo " <TABLE id=\"Combo\" border=1>\n"; echo " <TR>\n"; echo " <TH colspan=2>???</TH></TR>\n"; echo " <TR>\n"; echo " <TH>Ground:</TH>\n"; echo " <TD>$ground</TD></TR>\n"; echo " <TR>\n"; echo " <TH>Jump:</TH>\n"; echo " <TD>$jump</TD></TR>\n"; echo " <TR>\n"; echo " <TH>Super Jump:</TH>\n"; echo " <TD>$superjump</TD></TR>\n"; echo " <TR>\n"; echo " <TH colspan=2></TH></TR>\n"; echo " <TR>\n"; echo " <TH>Launcher:</TH>\n"; echo " <TD>$launcher</TD></TR>\n"; if ($altlaunch != null) { echo " <TR>\n"; echo " <TH>Alternate Launch:</TH>\n"; echo " <TD>$altlaunch</TD></TR>\n"; } echo " <TR>\n"; echo " <TH>AC Finishers:</TH>\n"; echo " <TD>$acfinisher</TD></TR></TABLE></DIV>\n"; echo " <DIV class=\"tabContent\" id=\"Attack\">\n"; echo " $test 4\n"; echo " </DIV>\n"; echo " </TD></TR></TABLE></TD></TR></TABLE>\n\n"; echo "</BODY></HTML>"; ?> $name.json, where $name is the name of the character (using pikachu as demo): {"character":[ { "name":"Pikachu", "group":"Pokemon", "series":"Pokemon", "story":"To-do...", "moves":[ { "flag":"normal", "move":"Discharge", "desc":"3,2", "comm":"Press HP (crouch) (air)", "type":"ELECTRIC.", "note":"Notes" }, { "flag":"normal", "move":"Electric Screw", "desc":"6,2", "comm":"Tilt d,+HP [air]", "type":"ELECTRIC.", "note":"Notes" }, { "flag":"normal", "move":"Tackle", "desc":"9,1", "comm":"Tap f, , f,", "type":"NORMAL.", "note":"Notes" }, { "flag":"special", "move":"Quick Attack", "desc":"11,2", "comm":"Tap any direction and Press AP (air)", "type":"ELECTRIC.FIGHTING.", "note":"Notes" }, { "flag":"special", "move":"Thunder Jolt", "desc":"14", "comm":"Motion d,df,f,+AP", "type":"ELECTRIC.", "note":"Notes" }, { "flag":"special", "move":"Electro Ball", "desc":"16,2", "comm":"Motion d,df,f,+AP [air]", "type":"ELECTRIC.", "note":"Notes" }, { "flag":"special", "move":"Thunder", "desc":"19,2", "comm":"Motion f,d,df,+AP (air)", "type":"ELECTRIC.", "note":"Notes" }, { "flag":"special", "move":"Electric Chair", "desc":"22,2", "comm":"Motion f,df,d,db,b,+AP", "type":"ELECTRIC.", "note":"Notes" }, { "flag":"hyper", "move":"Thunder Shock", "desc":"25,2", "comm":"Motion d,df,f,+APAP (air)", "type":"ELECTRIC.", "note":"Notes" }, { "flag":"hyper", "move":"Thunder Bolt", "desc":"28,1", "comm":"Motion d,df,f,+AKAK (air)", "type":"ELECTRIC.", "note":"Notes" }, { "flag":"hyper", "move":"Skull Bash", "desc":"30,2", "comm":"Motion d,db,b,+APAP (air)", "type":"ELECTRIC.FIGHTING.", "note":"Notes" }, { "flag":"final", "move":"Volt Tackle", "desc":"33,2", "comm":"Motion d,df,f,d,df,f,+APAP (air)", "type":"ELECTRIC.", "note":"Notes" }], "snapback":"Crouching Forward", "interrupt":"Thunder Jolt, Thunder", "hiddenpow":"Hidden Power Enhancements (Line per line lookup)", "disrupt":"Thunder", "assist1":"Thunder Jolt", "assist2":"Thunder", "assist3":"Quick Attack", "counter":"Thunder", "bros":"Skull Bash", "party":"Thunder Bolt", "ground":"Punch to Kick", "jump":"Punch to Kick", "superjump":"Zig Zag", "launcher":"Standing Roundhouse", "altlaunch":"Crouching Strong", "acfinisher":"Discharge, Electric Screw, Quick Attack, Electro Ball, Thunder, Thunder Shock, Thunder Bolt, Skull Bash" } ]}
The problem is in this function, and has nothing to do with your use of JSON. It's just a simple variable scope issue. function descrw ($desc) { $result = explode(",", $desc); $start = $result[0]; $length = $result[1]; $file = new SplFileObject("$name/$name.txt"); for ($i = $start; $i <= ($start+$length); $i++) { $file->seek($i-1); echo "$file"; } return(0); } The variable $name is not defined, so it's trying to open the file /.txt. You need to change the function so it takes $name as an argument. And since the caller of descrw expects it to return a string so that it can be concatenated, descrw shouldn't do its own echo. function descrw ($desc, $name) { $result = explode(",", $desc); $start = $result[0]; $length = $result[1]; $file = new SplFileObject("$name/$name.txt"); $result = ''; for ($i = $start; $i <= ($start+$length); $i++) { $file->seek($i-1); $result .= $file; } return($result); } Then change the place where it's called to pass the argument: echo " <DIV class=\"Details\">" . descrw($desc, $name) . "</DIV></TD>\n";
Split table in php
i got this script. it looks into a file and read all the lines and put it nicely in a table.. what i need to do now is to take all the table data and split it into two tables .. eg. if their is 100 rows.. then instead of one long list, i will get 50 data in one table and the other 50 in the other table... enter code here<?php if(isset ($_GET['type'])) { $otype = $_GET['type']; } else { $otype = 'm'; } $statusFile = "d:\\CLIENTS\\status.txt"; $file_handler = fopen($statusFile, "r"); // read the contents $contents = fread($file_handler, filesize($statusFile)); // close the file fclose($file_handler); if (strcasecmp($otype, "m") == 0) { echo $contents; } else { $lines = explode("\n",$contents); $frow = explode(",", $lines[0]); if (strcmp($frow[1],"1") == 0) { echo "Update Status: <b>Complete</b>"; //to count total lines in txt file $statusFile = "d:\\CLIENTS\\status.txt"; $line = count(file($statusFile)); echo "There are".$line."lines in"; } else { echo "Update Status: <b>Incomplete</b>"; } echo "<table border=\"1\">"; for ($count = 1; $count < sizeof($lines); $count++) { $fields = explode(",",$lines[$count]); $sz = sizeof($fields); if ($sz > 1) { $str = "OK"; echo "<tr>"; echo "<td>" . $fields[0] . "</td>"; echo "<td>" . $fields[1] . "</td>"; //echo "<td>" . $fields[2] . "</td>"; if (strpos($fields[2],'OK') !== false) { echo "<td><font color='green'>". $fields[2] ."</font></td>"; //echo "<td style='background-color: #00FF00;'>". $fields[2] ."</td>"; } else { //echo "<td><font color='red'>". $fields[2] ."</font></td>"; echo "<td style='background-color: #FF0000;'>". $fields[2] ."</td>"; } echo "</tr>"; } } echo "</table>"; } ?>
Use a foreach instead of a for and $count to calculate if it is needed to echo a table tag. $count is only incremented when a row was inserted. <style> div.container { width: 100%; /* Change the width to the desired width */ padding: 0; } div.container table { width: 50%; /* Change the width to half of the width of the div */ margin: 0; float: left; } </style> <?php if(isset ($_GET['type'])) { $otype = $_GET['type']; } else { $otype = 'm'; } $statusFile = "d:\\CLIENTS\\status.txt"; $file_handler = fopen($statusFile, "r"); // read the contents $contents = fread($file_handler, filesize($statusFile)); // close the file fclose($file_handler); if (strcasecmp($otype, "m") == 0) { echo $contents; } else { $lines = explode("\n",$contents); $frow = explode(",", $lines[0]); if (strcmp($frow[1],"1") == 0) { echo "Update Status: <b>Complete</b>"; //to count total lines in txt file $statusFile = "d:\\CLIENTS\\status.txt"; $line = count(file($statusFile)); echo "There are".$line."lines in"; } else { echo "Update Status: <b>Incomplete</b>"; } echo '<div class="conatiner">'; $count = 0; foreach ($lines as $currLine) { $fields = explode(",",$currLine); $sz = sizeof($fields); if ($sz > 1) { if ($count == 0) { echo "<table border=\"1\">"; } elseif ($count % 50 == 0) { echo "</table>"; echo "<table border=\"1\">"; } $str = "OK"; echo "<tr>"; echo "<td>" . $fields[0] . "</td>"; echo "<td>" . $fields[1] . "</td>"; //echo "<td>" . $fields[2] . "</td>"; if (strpos($fields[2],'OK') !== false) { echo "<td><font color='green'>". $fields[2] ."</font></td>"; //echo "<td style='background-color: #00FF00;'>". $fields[2] ."</td>"; } else { //echo "<td><font color='red'>". $fields[2] ."</font></td>"; echo "<td style='background-color: #FF0000;'>". $fields[2] ."</td>"; } echo "</tr>"; $count++; } } echo "</table>"; echo '</div>'; }
Tables are displayed horizontally instead of vertical [closed]
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed 8 years ago. Improve this question I'm trying to create an table with PHP and HTML which gets the data from a MySQL database. The problem is that the data is displayed horizontally and not vertical. if (isset($_POST['winneron'])) { echo "<tr>"; while ($printuser = mysql_fetch_array($user)) { echo "<th>". $printuser['username'] . "</th>"; } echo "</tr>"; while ($printgames = mysql_fetch_array($games)) { if ( $printgames ['winner'] == $printgames ['team1'] ) { echo "<td><b>". strtoupper($printgames ['winner']) . "</b></td>"; } else { echo "<td>". strtoupper($printgames ['winner']) . "</td>"; } } } Hope somebody can help me.
If you want your display to be vertical then you have to put each piece of information into a table row <tr><td>...</td></tr> while ($ausgabespiele = mysql_fetch_array($spiele)) { if ( $ausgabespiele['sieger'] == $ausgabespiele['team1'] ) { echo "<tr><td><b>". strtoupper($ausgabespiele['sieger']) . "</b></td></tr>"; } else { echo "<tr><td>". strtoupper($ausgabespiele['sieger']) . "</td></tr>"; } }
There are no <tr> and </tr> in your while ($ausgabespiele = mysql_fetch_array($spiele)) { }...
You are missing TR in while if (isset($_POST['winneron'])) { echo "<tr>"; while ($ausgabeuser = mysql_fetch_array($user)) { echo "<th>". $ausgabeuser['username'] . "</th>"; } echo "</tr>"; while ($ausgabespiele = mysql_fetch_array($spiele)) { echo "<tr>"; if ( $ausgabespiele['sieger'] == $ausgabespiele['team1'] ) { echo "<td><b>". strtoupper($ausgabespiele['sieger']) . "</b></td>"; } else { echo "<td>". strtoupper($ausgabespiele['sieger']) . "</td>"; } echo "</tr>"; } }
You have to add the row-tags within the while loop... if (isset($_POST['winneron'])) { echo "<tr>"; while ($ausgabeuser = mysql_fetch_array($user)) { echo "<th>". $ausgabeuser['username'] . "</th>"; } echo "</tr>"; while ($ausgabespiele = mysql_fetch_array($spiele)) { echo "<tr>"; if ( $ausgabespiele['sieger'] == $ausgabespiele['team1'] ) { echo "<td><b>". strtoupper($ausgabespiele['sieger']) . "</b></td>"; } else { echo "<td>". strtoupper($ausgabespiele['sieger']) . "</td>"; } echo "</tr>"; } }
You forget to create a table row insde the loop. To display vertically you need to place the table cells in rows: while ($ausgabespiele = mysql_fetch_array($spiele)) { echo "<tr>"; if ( $ausgabespiele['sieger'] == $ausgabespiele['team1'] ) { echo "<td><b>". strtoupper($ausgabespiele['sieger']) . "</b></td>"; } else { echo "<tr><td>". strtoupper($ausgabespiele['sieger']) . "</td></tr>"; } echo "</tr>"; }
Try this - if (isset($_POST['winneron'])) { $echo = "<tr>"; while ($ausgabeuser = mysql_fetch_array($user)) { $echo .= "<th>". $ausgabeuser['username'] . "</th>"; } $echo .= "</tr><tr>"; while ($ausgabespiele = mysql_fetch_array($spiele)) { if ($ausgabespiele['sieger'] == $ausgabespiele['team1']) $echo .= "<td><b>". strtoupper($ausgabespiele['sieger']) . "</b></td>"; else $echo .= "<td>". strtoupper($ausgabespiele['sieger']) . "</td>"; } $echo .= "</tr>"; echo $echo; }