Html Box Around live input - php

I'm trying to get a box around 2 different fields of input the script pings a game server and brings back information but pings 2 servers i want them to be put inside a box instead of just laying on the website messy
<?php
// Include the main class file
require '../GameQ.php';
// Define your servers,
// see list.php for all supported games and identifiers.
$servers = array(
array(
'id' => 'BF4',
'type' => 'bf4',
'host' => '192.223.29.138:47200',
),
array(
'id' => 'GMOD',
'type' => 'gmod',
'host' => '31.186.251.28:27015',
)
);
// Call the class, and add your servers.
$gq = new GameQ();
$gq->addServers($servers);
// You can optionally specify some settings
$gq->setOption('timeout', 4); // Seconds
// You can optionally specify some output filters,
// these will be applied to the results obtained.
$gq->setFilter('normalise');
// Send requests, and parse the data
$results = $gq->requestData();
// Some functions to print the results
function print_results($results) {
foreach ($results as $id => $data) {
printf("<h2>%s</h2>\n", $id);
print_table($data);
}
}
function print_table($data) {
$gqs = array('gq_online', 'gq_address', 'gq_port', 'gq_prot', 'gq_type');
if (!$data['gq_online']) {
printf("<p>The server did not respond within the specified time.</p>\n");
return;
}
print("<table><thead><tr><td>Variable</td><td>Value</td></tr></thead><tbody>\n");
foreach ($data as $key => $val) {
if (is_array($val)) continue;
$cls = empty($cls) ? ' class="uneven"' : '';
if (substr($key, 0, 3) == 'gq_') {
$kcls = (in_array($key, $gqs)) ? 'always' : 'normalise';
$key = sprintf("<span class=\"key-%s\">%s</span>", $kcls, $key);
}
printf("<tr%s><td>%s</td><td>%s</td></tr>\n", $cls, $key, $val);
}
print("</tbody></table>\n");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Game List</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="style.css" />
</style>
</head>
<body>
<h1>Game List</h1>
<div id="chat">
Server List. <br/>
Click here for a list of supported games.
</div>
<?php
print_results($results);
?>
</body>
</html>
the css
body {
background-image: url("bg.jpg");
}
table td {
color: #cccccc; // OR WHATEVER
}
h1 {
color: #00ff00;
}
#chat {
color: #00ff00;
}

Add some CSS to change the required font color. Text doesn't come in as black, that's just the default font color for browsers.
table td {
color: #123456; // OR WHATEVER
}

Related

How can I apply style elements to divs created

I have this PHP code that fetches data (an image link and some strings) from my database. The goal is for me to be able to add products (its for an online store) to the database and have that PHP file automatically fetch the data required to display it on the site. I've managed to pull the data I needed but I can't seem to find a way to add some CSS to the divs it creates for each product.
I have already tried linking a CSS file and I don't want to go adding it inline (defeats the purpose of it being automatic)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>testdoc</title>
<style>
.prodimg
{
border: 20px, red, solid;
}
</style>
</head>
<body>
</body>
</html>
<?php
include 'db_connection.php';
$conn = OpenCon();
echo "Connected Successfully";
//query voor var
$sql = "SELECT prod_id, prod_name, stock, prod_price,images FROM PRODUCTS WHERE prod_name = 'red shirt' OR prod_type = 'tshirt'";
$result = $conn->query($sql); // kijken of er results zijn
$numberofRows=0;
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
makeDiv($numberofRows,$row);
}
}
else {
echo "0 results";
}
$conn->close();
function makeDiv($numberofRows,$row)
{
$doc = new DOMDocument;
$div = $doc->createElement('div');//Create new <div> tag
$div->setAttribute('class',"prodimg"); // give it a class
$imglink = $doc->createElement('img'); //create new image
$doc->appendChild($div);//Add the <div> tag to document
$imglink->setAttribute('src',$row['images']); //add the source from the database
$imglink->setAttribute('width',"200px");//give it the right size
$imglink->setAttribute('margin',"50px"); // setattribute seems to only work once for some reason
$div->appendChild($imglink); //add the image to the div
echo $doc->saveHTML(); // save everything
}
?>
You could add style block to the page
<style>.prodimg { background: #FF6600 }</style>

How to make my rows within different html tables selectable using PHP?

I am new to PHP and currently I am using php to create four different conference tables that have some hard-coded data in for now and I am trying to make any of the rows within the four tables selectable and eventually I will save the rows selected into a database, but for now I just can't figure out a way to make the rows selectable using PHP. Below is the current code that displays the four tables on my localhost. If this is not possible with PHP how would I incorporate another language within a php file to make the rows selectable. Thank you all for your help in advance.
Conference Class:
<?php
class Conference
{
protected $teams;
function loadTeams($teams)
{
$this->teams = $teams;
}
function getTeams()
{
return $this->teams;
}
}
?>
Main code:
<?php print( '<?xml version = "1.0" encoding = "utf-8"?>') ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>User selection page</title>
<link rel="stylesheet" href="gameViewStyleSheet.css" type="text/css" />
</head>
<?php
require_once('Conference.php');
for ($j = 0; $j<4; $j++)
{
$loadGameClass = new Conference();
$loadGameClass->loadTeams(array("(1)Gonzaga vs (16)Southern U", "(8)Pittsburgh vs (9)Wichita St", "(5)Wisconsin vs (12)Ole Miss", "(4)Kansas st vs (13)Boise St", "(6)Arizona vs (11)Belmont", "(3)New Mexico vs (14) Harvard", "(7)Notre Dame vs (10)Iowa St", "(2)Ohio St vs (15) Iona"));
$teams = $loadGameClass->getTeams();
echo '<table border="1" align="center">';
switch ($j) {
case 0:
echo "Midwest";
break;
case 1:
echo "West";
break;
case 2:
echo "South";
break;
case 3:
echo "East";
break;
}
for ($i = 0; $i < 8; $i++)
{
$games = $teams[$i];
echo '<tr><td>'.$games.'</td><tr>';
}
echo '</table>';
echo "<br>" . "<br>";
}
?>
<body>
</body>
</html>
If you're talking "selectable" as in front-end interactivity in your browser, that cannot be done with PHP. You need to use JavaScript.
If you just want a link that would tag something as "selected" with a page load and a session value, you could do small form submits for each select/deselect action, and highlight the appropriate rows.
side note: <br> is invalid in XHTML - you need to use <br />

Error on generating chart

In this below code i want to generate pie chart.and i got this error Undefined variable: mysqli, Call to a member function query() on a non-object at line 29.Please any one help me to rectify the problem to get solution.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Pie Chart Demo (LibChart)- http://codeofaninja.com/</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-15" />
</head>
<body>
<?php
//include the library
include "libchart/libchart/classes/libchart.php";
//new pie chart instance
$chart = new PieChart( 500, 300 );
//data set instance
$dataSet = new XYDataSet();
//actual data
//get data from the database
//include database connection
include 'db_connect.php';
//query all records from the database
$query = "select * from programming_languages";
//execute the query
$result = $mysqli->query( $query );
//get number of rows returned
$num_results = $result->num_rows;
if( $num_results > 0){
while( $row = $result->fetch_assoc() ){
extract($row);
$dataSet->addPoint(new Point("{$name} {$ratings})", $ratings));
}
//finalize dataset
$chart->setDataSet($dataSet);
//set chart title
$chart->setTitle("Tiobe Top Programming Languages for June 2012");
//render as an image and store under "generated" folder
$chart->render("generated/1.png");
//pull the generated chart where it was stored
echo "<img alt='Pie chart' src='generated/1.png' style='border: 1px solid gray;'/>";
}else{
echo "No programming languages found in the database.";
}
?>
</body>
</html>
you should not end the <form> until all fields has been printed.
you have a
</form>
<select>....</select>
please output the select first an then close the form. Otherwise the value of your select field will not be submited.

PHP Extract and print latitude and longitude using geolocation with google geolocation api

<?php echo $lat; ?>,
<?php echo $lng; ?>)
I'm trying to use the code from this page to get coordinates and dprint on the page above or below the maps using google,
http://www.galengrover.com/projects/PHPGoogleMaps-Examples/geolocation.php
I don't seem to understand how this works.
require( '_system/autoload.php' );
$map_options = array(
'map_id' => 'map23',
'draggable' => true,
'center' => 'San Diego, CA',
'height' => '500px',
'width' => '500px',
'zoom' => 16,
'bicycle_layer' => true
);
$map = new \PHPGoogleMaps\Map( $map_options );
//
$marker = \PHPGoogleMaps\Overlay\Marker::createFromUserLocation( array( 'geolocation_high_accuracy' => true, 'geolocation_timeout' => 10000 ) );
$map->addObject( $marker );
// If you want to set geolocation options you must call enableGeolocation() explicitly
// Otherwise it will be called for you when you use geolocation functions
$map->enableGeolocation( 5000, true );
// Set the loading content. This will display while the browser geolocates the user.
$map->setLoadingContent('<div style="background:#eee;height:300px;padding: 200px 0 0 0;text-align:center;"><img src="_images/loading.gif" style="display:block; margin: auto;"><p>Locating you...</p></div>'); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Ground Overlays -
<?php echo PAGE_TITLE ?>
</title>
<link rel="stylesheet" type="text/css" href="_css/style.css">
<?php $map->printHeaderJS() ?>
<?php $map->printMapJS() ?>
</head>
<body><h1>Geolocation</h1>(
<?php require( '_system/nav.php' ) ?>
<p>This example finds your location and centers the map on it. It also uses map::setLoadingContent() to display a loading message to the user.
</p>
<?php $map->printMap() ?>(
<?php echo $lat; ?>,
<?php echo $lng; ?>)
EDIT
I edited the code to show you this. See geosuccess() function. It will alert your coordinates. Everything is stored in "this" so if you go to the console in google chrome and type in "this" you will see all the data there.
<?php
// This is for my examples
require( '_system/config.php' );
// Autoload stuff
require( '_system/autoload.php' );
$map = new \PHPGoogleMaps\Map;
//
$marker = \PHPGoogleMaps\Overlay\Marker::createFromUserLocation( array( 'geolocation_high_accuracy' => true, 'geolocation_timeout' => 10000 ) );
$map->addObject( $marker );
// If you want to set geolocation options you must call enableGeolocation() explicitly
// Otherwise it will be called for you when you use geolocation functions
$map->enableGeolocation( 5000, true );
$map->centerOnUser( \PHPGoogleMaps\Service\Geocoder::geocode('New York, NY') );
$map->setWidth('500px');
$map->setHeight('500px');
$map->setZoom(16);
// Set the callbacks
$map->setGeolocationFailCallback( 'geofail' );
$map->setGeolocationSuccessCallback( 'geosuccess' );
// Set the loading content. This will display while the browser geolocates the user.
$map->setLoadingContent('<div style="background:#eee;height:300px;padding: 200px 0 0 0;text-align:center;"><img src="_images/loading.gif" style="display:block; margin: auto;"><p>Locating you...</p></div>');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Geolocation - <?php echo PAGE_TITLE ?></title>
<link rel="stylesheet" type="text/css" href="_css/style.css">
<?php $map->printHeaderJS() ?>
<?php $map->printMapJS() ?>
<script type="text/javascript">
function geofail() {
alert( 'geolocation failed' );
}
function geosuccess() {
alert("Lat:" + this.geolocation.hb + " Long: " + this.geolocation.ib);
//alert( 'geolocation succeeded' );
}
</script>
</head>
<body>
<h1>Geolocation</h1>
<?php require( '_system/nav.php' ) ?>
<p>This example finds your location and centers the map on it. It also uses map::setLoadingContent() to display a loading message to the user.</p>
<?php $map->printMap() ?>
</body>
</html>

php replace links

I have been racking my brains over this for hours, I need to pass some html to a function and have it replace the links and the return the html with the replaced links.
<?php
final static public function replace_links($campaign_id, $text) {
$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
if(preg_match_all("/$regexp/siU", $text, $matches, PREG_SET_ORDER)) {
foreach($matches as $match) {
if(substr($match[2], 0, 2) !== '##') { // ignore the placeholders
if(substr($match[2], 0, 6) !== 'mailto') { // ignore email addresses
// $match[2] = link address
// $match[3] = link text
$url = "http://xxx.com/click?campaign_id=$campaign_id&email=##email_address##&next=" . $match[2];
#$text .= str_replace($match[2], $url, $text);
#echo $links . "\n";
preg_replace($match[2], "<a href='$url'>{$match[3]}</a>", $match[2]);
}
}
return $text;
}
}
}
?>
When I echo the links it shows all the matched links. Question is how do i return the complete HTML with the replaced links example below.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
xxxx
xxxx
xxxx
</body>
</html>
Should become:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
xxxx
xxxx
xxxx
</body>
</html>
Hope this makes sense.
Thanks in advance,
Kyle
Don't reinvent the wheel just use something like this:
http://code.google.com/p/jquery-linkify/
It's really easy i use it as well
I don't know much about preg_replace, but i needed exatcly the same function as you.
Changing the line:
preg_replace($match[2], "<a href='$url'>{$match[3]}</a>", $match[2]);
for this:
str_replace($match[0],$url,$text);
seems to do the trick.
I just needed to get the return from this functions, so:
//$text = preg_replace($match[2], "<a href='$url'>{$match[3]}</a>", $match[2]);
$text = str_replace($match[0],$url,$text);

Categories