I am attempting to create a table that consists of 2 forms where the first form gets info from the second. so i have table1 and table 2. I want to make it to be users choice . a user picks the number of rows and columns(I went up to 7 rows and columns in dropbox) and color from a drop down box and whatever they pick it generates. My problem is when I select something instead of showing me a table row and columns with the colors its showing me 1111 can anyone suggest something? Maybe my logic is wrong please help.
<?php
$color= substr(filter_input(INPUT_GET,'color',FILTER_SANITIZE_NUMBER_INT),0,10);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="keywords" content="Table">
<meta name="description" content="table Creator">
<link rel="stylesheet" type="text/css" href="style.css">
<style>
tr:nth-child(even) {
background-color:#000000;
color:#000000;
<?php
echo $color
?>;
}
table, th, td {
border: 1px solid #000000; ;
padding: 10px;
}
table {
border-collapse: collapse;
}
</style>
<title>table</title>
</head>
<body>
<header>
<h1> Projects</h1>
</header>
<nav>
</nav>
<section>
<h2> Table Creator</h2>
<?php
$rows= substr(filter_input(INPUT_GET,'rows',FILTER_SANITIZE_NUMBER_INT),0,3);
$cols= substr(filter_input(INPUT_GET,'cols',FILTER_SANITIZE_NUMBER_INT),0,3);
echo "<Table>";
for ($x=1; $x<=$rows; $x++)
{
echo "<tr>";
for ($y=1; $y<=$cols; $y++)
echo "<td>$rows $x $cols $y</td>";
}
{
echo "<tr>";
}
echo "</Table>";
?>
</section>
<footer>
</footer>
<p></p>
</body>
</html>
Related
Iam new to this stuff. But I want to send checked checkbox value(s) to different page. Iam illustrating what i desire with code below;
php_checkbox.php file
<!DOCTYPE html>
<html>
<head>
<title>Get Values of Multiple Checked Checkboxes</title>
<link rel="stylesheet" href="css/php_checkbox.css" />
</head>
<body>
<div class="container">
<div class="main">
<center>
<h2>PHP: Get Values of Multiple Checked Checkboxes</h2>
<form action="checkbox_value.php" method="post">
<label class="heading">Select Your Technical Exposure:</label><p>
<input type="checkbox" name="check_list[]"
value="C/C++"><label>C/C++ </label> <p>
<input type="checkbox" name="check_list[]" value="Java">
<label>Java</label> <p>
<input type="checkbox" name="check_list[]" value="PHP"><label>PHP</label><p>
<input type="checkbox" name="check_list[]"
value="HTML/CSS"><label>HTML/CSS</label><p>
<input type="checkbox" name="check_list[]"
value="UNIX/LINUX"><label>UNIX/LINUX</label><p>
<input type="submit" name="submit" Value="Submit"/>
<p>
</form>
</div>
</div>
</body>
</html>
checkbox_value.php file
<?php
if(isset($_POST['submit'])){
if(!empty($_POST['check_list'])) {
// Counting number of checked checkboxes.
$checked_count = count($_POST['check_list']);
foreach($_POST['check_list'] as $selected) {
echo "<p>".$selected ."</p>";}
for ($x = 1; $x <= $checked_count; $x++) {
?>
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}
</style>
</head>
<body>
<h2>Cell that spans two columns</h2>
<p>To make a cell span more than one column, use the colspan attribute.</p>
<table style="width:50%">
<tr>
<td>Technology</td>
<td><?php echo $selected; ?></td>
</tr>
</table>
<?php
}
}
else{
}
}
?>
</body>
</html>
The above code work. The problem is when I select Java and PHP, I get PHP displayed in both tables. When I select 3 options, the last option get displayed in all tables. What I need is when I select e.g. PHP, JAVA, and UNIX/LINUX, the 3 options (PHP, JAVA, UNIX/LINUX) be displayed on the tables separately - PHP on the first table, Java on the second table and UNIX/LINUX on the third table.
When I select only 2 (e.g. Java and PHP), I want Java on the first table and PHP on the second.
Please help.
You have to write the row logic inside the loop.
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}
</style>
</head>
<body>
<h2>Cell that spans two columns</h2>
<p>To make a cell span more than one column, use the colspan attribute.</p>
<table style="width:50%">
<?php
if(isset($_POST['submit'])){
if(!empty($_POST['check_list'])) {
// Counting number of checked checkboxes.
$checked_count = count($_POST['check_list']);
foreach($_POST['check_list'] as $selected) {
echo "<p>".$selected ."</p>";
?>
<tr>
<td>Technology</td>
<td><?php echo $selected; ?></td>
</tr>
<?php
}
}
else{
}
}
?>
</table>
</body>
</html>
Checkout the code below. You don't need to count the number of elements sepeartely as you are using foreach() loop already.
Also, just loop the table, not the complete HTML.
<?php
if(isset($_POST['submit'])){
if(!empty($_POST['check_list'])) {
//Counting number of checked checkboxes.
//$checked_count = count($_POST['check_list']);
?>
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}
</style>
</head>
<body>
<h2>Cell that spans two columns</h2>
<p>To make a cell span more than one column, use the colspan attribute.</p>
<?php
foreach($_POST['check_list'] as $selected)
{
?>
<table style="width:50%">
<tr>
<td>Technology</td>
<td><?php echo $selected; ?></td>
</tr>
</table>
<?php
}
}
}
?>
</body>
</html>
Hi im a begginer in php and html i would like to ask how do i put this table into my html sidelist. when i put my table inside that space this always appear ( "; foreach($testaroni as $x=>$y) { echo ""; echo "" . $y . ""; } echo ""; echo ""; ?>)
This is my table. This is the problem (2)
<?php
session_start();
$testaroni = explode("', '" , $_SESSION["data"]);
?>
<?php
echo "<table border = '1'>";
foreach($testaroni as $x=>$y) {
echo "<tr>";
echo "<td>" . $y . "</td>";
}
echo "</tr>";
echo "</table>";
?>
And i would like to put it inside here.
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.links line {
stroke: #999;
stroke-opacity: 0.6;
}
.nodes circle {
stroke: #fff;
stroke-width: 1.5px;
}
text {
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
font-size: 10px;
}
</style>
<?php
session_start();
$testaroni = explode("', '" , $_SESSION["data"]);
?>
<html>
<head>
<title>Search</title>
</head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<body>
<!-- Sidebar -->
<div class="w3-sidebar w3-blue-grey w3-bar-block " style="width:15%">
<h4 class="w3-bar-item">Sidelist</h4>
<table border = "1">
<?php
foreach($testaroni as $x=>$y) {
echo '<tr>';
echo '<td>' . $y . '</td>';
}
echo '</tr>';
?>
</table>
</div>
</form>
</body>
</html>
You just need to modify your explode function and your code will work as you want
session_start();
//lets say your $_SESSION["data"] contains
$_SESSION["data"] = 'Value1,Value2,Value3';
//$testaroni = explode("', '" , $_SESSION["data"]);// just use single or double quotes without space
$testaroni = explode("," , $_SESSION["data"]);
You try var_dump( $_SESSION["data"]) and you should check empty $_SESSION["data"].I try put
$testaroni = array("1","2","3");//it work fine
You can read more about my this here
Seems like my eyes are failing me took me a while to see it.
You shouldn't use " when trying to use HTML tags in PHP
What you need to use is '.
<table border = "1">
<tr>
<?php
foreach($testaroni as $x=>$y) {
echo '<td>'.$y.'</td>';
}
?>
</tr>
</table>
The reason for this is that " will treat anything inside it as string while ' will treat it as is.
Refer here for a better explanation.
Also, follow the answer above for your session since it's also wrong.
Your session variable is a CSV string. simply exploding on the comma isn't going to get what you're looking for. You can verify this with var_dump($testaroni);.
Use str_getcsv.
<?php
// always start with php logic;
// it makes the script much easier to follow and
// if you need to redirect, you haven't put out any output yet.
session_start();
// check the docs for info on this function
$testaroni = str_getcsv($_SESSION['data']);
// then, when everything is calculated, print out your output
?>
<html>
<head>
<title>Search</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<style>
.links line {
stroke: #999;
stroke-opacity: 0.6;
}
.nodes circle {
stroke: #fff;
stroke-width: 1.5px;
}
text {
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
font-size: 10px;
}
</style>
</head>
<body>
<!-- Sidebar -->
<div class="w3-sidebar w3-blue-grey w3-bar-block " style="width:15%">
<h4 class="w3-bar-item">Sidelist</h4>
<table border = "1">
<?php foreach($testaroni as $y): ?>
<tr>
<td><?= $y ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
</form>
</body>
</html>
Can someone help me please?
I need a loop for a checkerboard pattern project.
Right now i have this:
<?php
$uitvoer="<table summary=''>\n";
$j=0;
$uitvoer .= "\t<tr>\n";
for($i=0;$i<8;$i++)
{
$uitvoer .= "\t\t<td class='kleur".(($i+$j)%2)."'> </td>\n";
}
echo <<<END
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Page title</title>
<style type="text/css">
<!--
td
{
width: 50px;
height: 50px;
border:4px groove red;
}
td.kleur0
{
background-color: white;
}
td.kleur1
{
background-color: black;
}
-->
</style>
</head>
<body>
$uitvoer
</body>
</html>
END;
?>
Then i get this:
So far so good.
But i need 8 rows with different lines and colors
The result need to be like this:
How can i do that the easiest and fastest way in a loop or a array??
You just need a second loop that adds table rows (<tr>). The beginning of your file should look like this:
$uitvoer="<table summary=''>\n";
for ($j=0; $j < 8; $j++) {
$uitvoer .= "\t<tr>\n";
for($i=0;$i<8;$i++) {
$uitvoer .= "\t\t<td class='kleur".(($i+$j)%2)."'> </td>\n";
}
$uitvoer .= "\t</tr>\n";
}
So, inside the loops, $i will hold your table cell (<td> tag) and $j will hold your table row (<tr> tag).
basic question is im trying to make a table similar to this
https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_caption_test
for my webpage: http://lamp.cse.fau.edu/~mcuervo5/p6/
in my php file for "name" & "votes"
by making the table for my boy table and girl table all border up and separated neatly
but it my first time using margin and padding to make the space neat & been having a lot of trial and error here & cant seem to solve the problem
tried to replace this:
$myTable = "<table>
with this:
$myTable = "<table style="margin: 5px; border: 1px; border-color: black;">
but got error code :(.
You can right click "inspect" the page or take it from here from my php code so far. Thanks guys if you can help me with this
<?php
require_once './php/db_connect.php'; // Will call this php file
?>
<!DOCTYPE html>
<html lang="en">
<head>
Just added this to make the border line
<style>
table, th, td
{
border: 2px solid black;
}</style>
End new edit
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Maundy | Comming Soon Page</title>
<meta name="description" content="Free Bootstrap Theme by BootstrapMade.com">
<meta name="keywords" content="free website templates, free bootstrap themes, free template, free bootstrap, free website template">
<link href='https://fonts.googleapis.com/css?family=Lobster|Open+Sans:400,400italic,300italic,300|Raleway:300,400,600' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/animate.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.countdown.min.js"></script>
<script src="js/wow.js"></script>
<script src="js/custom.js"></script>
<script src="contactform/contactform.js"></script>
<body>
<div class="col-lg-12">
<form method="post" action="index.php">
<label>Enter Name for Baby:</label>
<input type="text" name="baby_name" />
<label>Select Gender:</label>
<select name="gender">
<option value="B">Boy</option>
<option value="G">Girl</option>
</select>
<input type="submit" value="Sumbit!" />
</form>
</div>
<?php
if (isset($_POST['gender'])&& isset($_POST['baby_name']) )
{
$gender = $_POST['gender'];
$val_input = $_POST['baby_name'];
// Add two rows to the table
$selectStmt = 'SELECT `Votes`
FROM `Free_Names`
WHERE `Gender` = \''.$gender.'\' AND `Name` = \''.$val_input.'\';';
$result = $db->query($selectStmt); //query the "select" statement and update the result
if($result->num_rows > 0) { //if has a results
while($row = $result->fetch_assoc()) { //updates the statments
$UpdateStmt = 'UPDATE `Free_Names`
SET `Votes` = '.($row["Votes"] +1).'
WHERE `Gender` = \''.$gender.'\' AND `Name` = \''.$val_input.'\';';
$db->query($UpdateStmt); //this will run, but wont work
}
}
else
{
$insertStmt = 'INSERT INTO `Free_Names` (`Name`, `Gender`, `Votes` )' . PHP_EOL
. ' VALUES (\''.$val_input.'\',\''.$gender.'\',1);';
$db->query($insertStmt); //
}
}
?>
<?php
// Get the rows from the table, and \\ for single quote to show up
$selectStmt = 'SELECT `Name` , `Votes`
FROM `Free_Names`
WHERE `Gender` = \'B\'
ORDER BY `Votes` DESC
LIMIT 5';
?>
<div class="col-md-6">
<div class="mx-auto" style="width: 200px;">
It around here is the table for the names
BOY NAMES
</div>
<?php
$result = $db->query($selectStmt); //query the "select" statement and store the result
if($result->num_rows > 0) {
$myTable = "<table>
<thead>
<tr><th>Name</th>
<th>votes</th></tr>
</thead><tbody>";
while($row = $result->fetch_assoc()) {
$myTable.= "<tr>
<td>".$row["Name"]."</td>
<td>".$row["Votes"]."</td>
</tr>";
}
$myTable.= "</tbody></table>";
echo $myTable;
} else {
echo ' <div class="alert alert-success">No Results</div>' . PHP_EOL;
}
?>
</div>
<?php
// Get the rows from the table, and \\ for single quote to show up
$selectStmt = 'SELECT `Name` , `Votes`
FROM `Free_Names`
WHERE `Gender` = \'G\'
ORDER BY `Votes` DESC
LIMIT 5';
?>
<div class="col-md-6">
<div class="mx-auto" style="width: 200px;">
GIRL NAMES
</div>
<?php
$result = $db->query($selectStmt); //query the "select" statement and store the result
if($result->num_rows > 0) {
$myTable = " <table>
<thead>
<tr >
<th>Name</th>
<th>votes</th>
</tr>
</thead><tbody>";
while($row = $result->fetch_assoc()) {
$myTable.= "<tr>
<td>".$row["Name"]."</td>
<td>".$row["Votes"]."</td>
</tr>";
}
$myTable.= "</tbody></table>";
echo $myTable;
} else {
echo ' <div class="alert alert-success">No Results</div>' . PHP_EOL;
}
?>
</div>
</body>
</html>
I'll just use the W3Schools example. When it comes to cellpadding, add the style to <td> . When it comes to cell margins, add the style to <table> using border-spacing :
td{
padding: 12px 6px;
}
table{
border-spacing: 10px;
}
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
td{
padding: 12px 6px;
}
table{
border-spacing: 10px;
}
</style>
</head>
<body>
<table>
<caption>Monthly savings</caption>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$50</td>
</tr>
</table>
</body>
</html>
For example when the user is login, after login I want to automatic update a specific row from this actual user. How can I do for it?
Well when the user is login I want to update is row points, I want to add some points to it, for example 5 points.
I have try a few examples but it just add other row but not for this specific user
<?php
session_start();
include_once 'dbconnect.php';
if(!isset($_SESSION['user'])){
header("Location: index.php");
}
$res=mysql_query("SELECT * FROM users WHERE user_id=".$_SESSION['user']);
$userRow=mysql_fetch_array($res);
// Retrieve data from database
$sql="SELECT * FROM users ORDER BY user_points DESC LIMIT 10";
$result=mysql_query($sql);
$sql = mysql_query("INSERT INTO `users` (`user_points`) VALUES ('5');");
// Start looping rows in mysql database.
print "Top 10 Users! ";
while($rows=mysql_fetch_array($result)){
echo $rows['user_name'] . " * " . $rows['user_points'] . " * ";
// close while loop
}
// close MySQL connection
mysql_close();
$page = $_SERVER['PHP_SELF'];
$sec = "30";
?>
<!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" />
<meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body bgcolor="#ffffff">
<div id="header">
<div id="left">
<label>Bitcoin Rotator</label>
</div>
<div id="right">
<div id="content">
hi' <?php echo $userRow['user_name']; ?> Sign Out
Welcome Back Your Points <?php echo $userRow['user_points']; ?>
Bitcoin Rotator<br /><br />
<style>
#main {
width: 70px;
height: 300px;
border: 1px solid #c3c3c3;
display: -webkit-flex;
display: flex;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-align-content: center;
align-content: center;
}
#main div {
width: 70px;
height: 70px;
}
</style>
</div>
</div>
</div>
<div id="body">
<font color="FF00CC"; style="color: rgb(0,255,0)" >Click Here</font><font color="FF00CC"> to go on our faucet</font>
<br>
<br>
<font color="FF00CC"; style="color: rgb(0,255,0)" >Click Here</font><font color="FF00CC"> to see the top 10 users!</font>
<br>
<br>
<font color="FF00CC"; style="color: rgb(0,255,0)" >Make Your Rotator </font><font color="FF00CC">Click Here To Start!</font>
<br>
<br>
<font color="FF00CC"; style="color: rgb(0,255,0)" >All The Rotators From Our Website </font><font color="FF00CC">Click Here To Start!</font>
<div id="main">
<div style="background-color:coral;"></div>
<div style="background-color:lightblue;"></div>
<div style="background-color:pink;"></div>
</div>
</div>
</body>
</html>
you try to INSERT the value 5 every time the user logged on
what you want is UPDATE the content of row points
u can do this by this command sql
"UPDATE `users` SET points=`points`+5 WHERE user_id='".$_SESSION['user']."'"
The query you need is
$user_id = mysql_real_escape_string($_SESSION['user']);
$sql = mysql_query("UPDATE `users` SET user_points = user_points + 5 WHERE user_id = " . $user_id);
Please don't use mysql_ library because it was deprecated (use mysqli_ instead)