I am trying to make all $_GET methods into $_POST on this page. I want php?produktid=0 to be invisible on the adress bar.
How can I solve this?
This is an application and I want it to run on its own.
//PREVIOUS BUTTON
$index = $_GET['produktid'];
echo "<td>";
if ($index > 0) {
echo ' <img style="margin-left: 77px;" src="bilder/prev.png"> ';
} else {
echo ' <img style="margin-left: 77px;" src="prev.png"> ';
}
echo "</td>";
//IF I AM ON PAGE ONE, ECHO THIS
if($_GET['produktid']==0){
echo "<p>Page One</p>";
}
//IF I AM ON PAGE TWO, ECHO THIS
if($_GET['produktid']==2){
echo "<p>Page Two</p>";
}
//IF I AM ON PAGE THREE, ECHO THIS
if($_GET['produktid']==3){
echo "<p>Page Three</p>";
}
//NEXT BUTTON
echo "<td>";
if ($index < count($array) - 1) {
echo ' <img style="margin-left: -70px;" src="bilder/next.png"> ';
} else {
echo ' <img style="margin-left: -70px;" src="next.png"> ';
}
echo "</td>";
echo "</table>";
echo "<div>";
?>
HERE IS HOW MY WHOLE PAGE LOOKS LIKE
<!DOCTYPE HTML>
<html lang="sv-SE"/>
<head>
<meta charset="UTF-8"/>
<title>Images</title>
<style media="screen" type="text/css">
tr {display: inline-block;}
td {width: 120px;
height: 90px;
box-sizing: border-box;}
#Latest_products {
height: 280px;
width: 670px;
background-color: grey;
margin-left: auto;
margin-right: auto;
text-align: center;
}
</style>
</head>
<body>
<div id="latest_products">
<?php
error_reporting(0);
echo "<p><h1>New Arrivals</h1></p>";
$mysqli = new mysqli('localhost', 'root', '', 'webshop');
mysql_set_charset("utf-8");
//Identify Photo Sequences
$array = array(
0 => "picture1.jpg",
1 => "picture2.jpg",
2 => "kalle3.jpg",
);
echo "<table>";
//PREV BUTTON
$index = $_GET['produktid'];
echo "<td>";
if ($index > 0) {
echo ' <img style="margin-left: 77px;" src="bilder/prev.png"> ';
} else {
echo ' <img style="margin-left: 77px;" src="bilder/prev.png"> ';
}
echo "</td>";
//FOR PAGE 1 SHOW THIS
if($_GET['produktid']==0){
$res = "SELECT * FROM produktlista ORDER BY produktankomst DESC LIMIT 0,3";
$result = $mysqli->query($res);
while($myRow = $result->fetch_array())
{
echo "<tr>";
echo "<td><a href='./item.php?produktid=".$myRow["produktid"]."'> <img src=".$myRow["produktbild"]." height='132' width='132'> </a> </td>";
echo "<td style='display: block;'><a href='./item.php?produktid=".$myRow["produktid"]."'> <h4>".$myRow["produktnamn"]."</h4></a> </td>";
echo "</tr>";
}
}
//FOR PAGE 2 SHOW THIS
if($_GET['produktid']==1){
$res = "SELECT * FROM produktlista ORDER BY produktankomst DESC LIMIT 1,3";
$result = $mysqli->query($res);
while($myRow = $result->fetch_array())
{
echo "<tr>";
echo "<td><a href='./item.php?produktid=".$myRow["produktid"]."'> <img src=".$myRow["produktbild"]." height='132' width='132'> </a> </td>";
echo "<td style='display: block;'><a href='./item.php?produktid=".$myRow["produktid"]."'> <h4>".$myRow["produktnamn"]."</h4></a> </td>";
echo "</tr>";
}
}
//FOR PAGE 3 SHOW THIS
if($_GET['produktid']==2){
$res = "SELECT * FROM produktlista ORDER BY produktankomst DESC LIMIT 2,3";
$result = $mysqli->query($res);
while($myRow = $result->fetch_array())
{
echo "<tr>";
echo "<td><a href='./item.php?produktid=".$myRow["produktid"]."'> <img src=".$myRow["produktbild"]." height='132' width='132'> </a> </td>";
echo "<td style='display: block;'><a href='./item.php?produktid=".$myRow["produktid"]."'> <h4>".$myRow["produktnamn"]."</h4></a> </td>";
echo "</tr>";
}
}
echo "<td>";
//NEXT BUTTON
if ($index < count($array) - 1) {
echo ' <img style="margin-left: -70px;" src="bilder/next.png"> ';
} else {
echo ' <img style="margin-left: -70px;" src="bilder/next.png"> ';
}
echo "</td>";
echo "</table>";
echo "<div>";
?>
</body>
</html>
After I change it looks like this now, and "PREV" "NEXT" links doesn't work now.
<!DOCTYPE HTML>
<html lang="sv-SE"/>
<head>
<meta charset="UTF-8"/>
<title>Images</title>
<style media="screen" type="text/css">
tr {display: inline-block;}
td {width: 120px;
height: 90px;
box-sizing: border-box;}
#senaste_produkter {
height: 280px;
width: 670px;
background-color: grey;
margin-left: auto;
margin-right: auto;
text-align: center;
}
</style>
</head>
<body>
<div id="senaste_produkter">
<?php
//Databasuppkoppling - Visa senaste produkter ifrån databasen
error_reporting(0);
echo "<p><h1>New Arrivals</h1></p>";
$mysqli = new mysqli('localhost', 'root', '', 'webshop');
mysql_set_charset("utf-8");
//Identify picture sequences
$array = array(
0 => "picture1.jpg",
1 => "picture2.jpg",
2 => "kalle3.jpg",
);
echo "<table>";
//BACK LINK
$index = $_GET['produktid'];
echo "<td>";
if ($index > 0) {
echo '<form action="newarrivals.php"><input type="hidden" name="produktid" value="' . ($index - 1) . '"><input style="margin-left: 77px;" src="bilder/prev.png"></form>';
} else {
echo '<form action="newarrivals.php"><input type="hidden" name="produktid" value="'. (count($array) - 1) . '"> <img style="margin-left: 77px;" src="bilder/prev.png"> </form>';
}
echo "</td>";
//IF I GO TO PAGE 3, SHOW THIS
if($_GET['produktid']==0){
$res = "SELECT * FROM produktlista ORDER BY produktankomst DESC LIMIT 0,3";
$result = $mysqli->query($res);
while($myRow = $result->fetch_array())
{
echo "<tr>";
echo "<td><a href='./item.php?produktid=".$myRow["produktid"]."'> <img src=".$myRow["produktbild"]." height='132' width='132'> </a> </td>";
echo "<td style='display: block;'><a href='./item.php?produktid=".$myRow["produktid"]."'> <h4>".$myRow["produktnamn"]."</h4></a> </td>";
echo "</tr>";
}
}
//IF I GO TO PAGE 2, SHOW THIS
if($_GET['produktid']==1){
$res = "SELECT * FROM produktlista ORDER BY produktankomst DESC LIMIT 1,3";
$result = $mysqli->query($res);
while($myRow = $result->fetch_array())
{
echo "<tr>";
echo "<td><a href='./item.php?produktid=".$myRow["produktid"]."'> <img src=".$myRow["produktbild"]." height='132' width='132'> </a> </td>";
echo "<td style='display: block;'><a href='./item.php?produktid=".$myRow["produktid"]."'> <h4>".$myRow["produktnamn"]."</h4></a> </td>";
echo "</tr>";
}
}
//IF I GO TO PAGE 3, SHOW THIS
if($_GET['produktid']==2){
$res = "SELECT * FROM produktlista ORDER BY produktankomst DESC LIMIT 2,3";
$result = $mysqli->query($res);
while($myRow = $result->fetch_array())
{
echo "<tr>";
echo "<td><a href='./item.php?produktid=".$myRow["produktid"]."'> <img src=".$myRow["produktbild"]." height='132' width='132'> </a> </td>";
echo "<td style='display: block;'><a href='./item.php?produktid=".$myRow["produktid"]."'> <h4>".$myRow["produktnamn"]."</h4></a> </td>";
echo "</tr>";
}
}
echo "<td>";
//NEXT PAGE
if ($index < count($array) - 1) {
echo '<form action="newarrivals.php"><input type="hidden" name="produktid" value="' . ($index + 1) . '"> <img style="margin-left: -70px;" src="bilder/next.png"> </a> ';
} else {
echo '<form action="newarrivals.php"> <img style="margin-left: -70px;" src="bilder/next.png"> </a>';
}
echo "</td>";
echo "</table>";
echo "<div>";
?>
</body>
</html>
You need to use forms instead of links, and put the parameters into hidden inputs. So change
echo ' <img style="margin-left: 77px;" src="bilder/prev.png"> ';
to:
echo '<form action="newarrivals.php" method="post"><input type="hidden" name="produktid" value="' . ($index - 1) . '"><input type="image" style="margin-left: 77px;" src="bilder/prev.png"></form>';
and change all the other links similarly.
Here's the whole rewritten script:
<!DOCTYPE HTML>
<html lang="sv-SE"/>
<head>
<meta charset="UTF-8"/>
<title>Images</title>
<style media="screen" type="text/css">
tr {display: inline-block;}
td {width: 120px;
height: 90px;
box-sizing: border-box;}
#senaste_produkter {
height: 280px;
width: 670px;
background-color: grey;
margin-left: auto;
margin-right: auto;
text-align: center;
}
</style>
</head>
<body>
<div id="senaste_produkter">
<?php
//Databasuppkoppling - Visa senaste produkter ifrån databasen
error_reporting(0);
echo "<p><h1>New Arrivals</h1></p>";
$mysqli = new mysqli('localhost', 'root', '', 'webshop');
mysql_set_charset("utf-8");
//Identify picture sequences
$array = array(
0 => "picture1.jpg",
1 => "picture2.jpg",
2 => "kalle3.jpg",
);
echo "<table>";
//BACK LINK
$index = $_GET['produktid'];
echo "<tr><td>";
if ($index > 0) {
echo '<form action="newarrivals.php" method="post"><input type="hidden" name="produktid" value="' . ($index - 1) . '"><input type="image" style="margin-left: 77px;" src="bilder/prev.png"></form>';
} else {
echo '<form action="newarrivals.php" method="post"><input type="hidden" name="produktid" value="'. (count($array) - 1) . '"> <input type="image" style="margin-left: 77px;" src="bilder/prev.png"> </form>';
}
echo "</td></tr>";
//IF I GO TO PAGE 3, SHOW THIS
if($_GET['produktid']==0){
$res = "SELECT * FROM produktlista ORDER BY produktankomst DESC LIMIT 0,3";
$result = $mysqli->query($res);
while($myRow = $result->fetch_array())
{
echo "<tr>";
echo "<td><a href='./item.php?produktid=".$myRow["produktid"]."'> <img src=".$myRow["produktbild"]." height='132' width='132'> </a> </td>";
echo "<td style='display: block;'><a href='./item.php?produktid=".$myRow["produktid"]."'> <h4>".$myRow["produktnamn"]."</h4></a> </td>";
echo "</tr>";
}
}
//IF I GO TO PAGE 2, SHOW THIS
if($_GET['produktid']==1){
$res = "SELECT * FROM produktlista ORDER BY produktankomst DESC LIMIT 1,3";
$result = $mysqli->query($res);
while($myRow = $result->fetch_array())
{
echo "<tr>";
echo "<td><a href='./item.php?produktid=".$myRow["produktid"]."'> <img src=".$myRow["produktbild"]." height='132' width='132'> </a> </td>";
echo "<td style='display: block;'><a href='./item.php?produktid=".$myRow["produktid"]."'> <h4>".$myRow["produktnamn"]."</h4></a> </td>";
echo "</tr>";
}
}
//IF I GO TO PAGE 3, SHOW THIS
if($_GET['produktid']==2){
$res = "SELECT * FROM produktlista ORDER BY produktankomst DESC LIMIT 2,3";
$result = $mysqli->query($res);
while($myRow = $result->fetch_array())
{
echo "<tr>";
echo "<td><a href='./item.php?produktid=".$myRow["produktid"]."'> <img src=".$myRow["produktbild"]." height='132' width='132'> </a> </td>";
echo "<td style='display: block;'><a href='./item.php?produktid=".$myRow["produktid"]."'> <h4>".$myRow["produktnamn"]."</h4></a> </td>";
echo "</tr>";
}
}
echo "<tr><td>";
//NEXT PAGE
if ($index < count($array) - 1) {
echo '<form action="newarrivals.php" method="post"><input type="hidden" name="produktid" value="' . ($index + 1) . '"> <input type="image" style="margin-left: -70px;" src="bilder/next.png">';
} else {
echo '<form action="newarrivals.php" method="post"> <input type="image" style="margin-left: -70px;" src="bilder/next.png">';
}
echo "</td></tr>";
echo "</table>";
echo "<div>";
?>
</body>
</html>
Related
I am trying to show the first 9 images as previews in an ACF gallery. When clicking one, a lightbox opens and I would like all the images, including the initial 9 to be included
I can only find solutions to show 1 image not more than 1
I tried this
<?php $images = get_field( 'gallery' ); ?>
<?php $image = $images[9]; ?>
<?php if ( $images ) : ?>
<?php foreach ( $images as $gallery_image ): ?>
<a href="<?php echo esc_url( $image['url'] ); ?>">
<img src="<?php echo esc_url( $image['sizes']['medium'] ); ?>" alt="<?php echo esc_attr( $image['alt'] ); ?>" />
</a>
<p><?php echo esc_html( $image['caption'] ); ?></p>
<?php endforeach; ?>
<?php endif; ?>
but this only repeats the 9th image
I also tried this
<?php if ( $gallery_images ) : ?>
<?php foreach(array_slice($gallery_images,0,9) as $gallery_image) ?>
<a href="<?php echo esc_url( $image['url'] ); ?>">
<img src="<?php echo esc_url( $image['sizes']['medium'] ); ?>" alt="<?php echo esc_attr( $image['alt'] ); ?>" />
</a>
<p><?php echo esc_html( $image['caption'] ); ?></p>
<?php endforeach; ?>
<?php endif; ?>
But this doesn't work at all
I would also like to create a button that just opens the gallery without showing any preview image
Essentially I want to trigger a click on the first image when clicking the 'show gallery button'
Any help would be great
edit
I have just tried this:
<div class="listing-preview-gallery">
<?php $gallery_images = get_field( 'gallery' ); ?>
<?php if ( $gallery_images ) : ?>
<?php foreach ( $gallery_images as $gallery_image ): ?>
<?php if ( $i == 1 ) { ?>
<div class="preview-image-container">
<div class="the-image">
<a href="<?php echo esc_url( $gallery_image['url'] ); ?>">
<img src="<?php echo esc_url( $gallery_image['sizes']['medium'] ); ?>" alt="<?php echo esc_attr( $gallery_image['alt'] ); ?>" />
</a>
</div>
</div>
<?php } elseif ( $i == 2 ) { ?>
<div class="preview-image-container">
<div class="the-image">
<a href="<?php echo esc_url( $gallery_image['url'] ); ?>">
<img src="<?php echo esc_url( $gallery_image['sizes']['medium'] ); ?>" alt="<?php echo esc_attr( $gallery_image['alt'] ); ?>" />
</a>
</div>
</div>
<?php } elseif ( $i == 3 ) { ?>
<div class="preview-image-container">
<div class="the-image">
<a href="<?php echo esc_url( $gallery_image['url'] ); ?>">
<img src="<?php echo esc_url( $gallery_image['sizes']['medium'] ); ?>" alt="<?php echo esc_attr( $gallery_image['alt'] ); ?>" />
</a>
</div>
</div>
<?php } elseif ( $i == 4 ) { ?>
<div class="preview-image-container">
<div class="the-image">
<a href="<?php echo esc_url( $gallery_image['url'] ); ?>">
<img src="<?php echo esc_url( $gallery_image['sizes']['medium'] ); ?>" alt="<?php echo esc_attr( $gallery_image['alt'] ); ?>" />
</a>
</div>
</div>
<?php } elseif ( $i == 5 ) { ?>
<div class="preview-image-container">
<div class="the-image">
<a href="<?php echo esc_url( $gallery_image['url'] ); ?>">
<img src="<?php echo esc_url( $gallery_image['sizes']['medium'] ); ?>" alt="<?php echo esc_attr( $gallery_image['alt'] ); ?>" />
</a>
</div>
</div>
<?php } elseif ( $i == 6 ) { ?>
<div class="preview-image-container">
<div class="the-image">
<a href="<?php echo esc_url( $gallery_image['url'] ); ?>">
<img src="<?php echo esc_url( $gallery_image['sizes']['medium'] ); ?>" alt="<?php echo esc_attr( $gallery_image['alt'] ); ?>" />
</a>
</div>
</div>
<?php } elseif ( $i == 7 ) { ?>
<div class="preview-image-container">
<div class="the-image">
<a href="<?php echo esc_url( $gallery_image['url'] ); ?>">
<img src="<?php echo esc_url( $gallery_image['sizes']['medium'] ); ?>" alt="<?php echo esc_attr( $gallery_image['alt'] ); ?>" />
</a>
</div>
</div>
<?php } elseif ( $i == 8 ) { ?>
<div class="preview-image-container">
<div class="the-image">
<a href="<?php echo esc_url( $gallery_image['url'] ); ?>">
<img src="<?php echo esc_url( $gallery_image['sizes']['medium'] ); ?>" alt="<?php echo esc_attr( $gallery_image['alt'] ); ?>" />
</a>
</div>
</div>
<?php } elseif ( $i == 9 ) { ?>
<div class="preview-image-container">
<div class="the-image">
<a href="<?php echo esc_url( $gallery_image['url'] ); ?>">
<img src="<?php echo esc_url( $gallery_image['sizes']['medium'] ); ?>" alt="<?php echo esc_attr( $gallery_image['alt'] ); ?>" />
</a>
</div>
</div>
<?php }
$i++; ?>
<?php endforeach; ?>
<?php endif; ?>
</div>
And it successfully only previews 9, but the rest do not show in the lightbox
I tried this for the button click
jQuery ( function($) {
$('.gallery-button').off('touchstart touchend').on('click', function() {
$('.listing-preview-gallery #preview-image-container:first-child .the-image a').trigger('click');
} );
} );
Edit 2
It occurs to me I can use nth child to hide all but the first 9 thumbnails, but then it still loads the images - I wonder if there is a way to not load the remaining images until the lightbox is opened
So I don't have the answer to your full question, but your php example to show the first 9 photos, there's a MUCH shorter way to write that out. Take a look at the code below.
<div class="listing-preview-gallery">
<?php $gallery_images = get_field( 'gallery' );
if ( $gallery_images ) :
$previewCount = 9;
$i = 0;
foreach ( $gallery_images as $gallery_image ):
$i++;
if($i <= $previewCount){ ?>
<div class="preview-image-container">
<div class="the-image">
<a href="<?php echo esc_url( $gallery_image['url'] ); ?>">
<img src="<?php echo esc_url( $gallery_image['sizes']['medium'] ); ?>" alt="<?php echo esc_attr( $gallery_image['alt'] ); ?>" />
</a>
</div>
</div>
<?php }
endforeach;
endif; ?>
</div>
You would just set the $previewCount variable to whatever number of images you want to preview, and the code will do the rest. It uses $i as a counter, and checks against the $previewCount variable to determine when to stop looping through the $gallery_images.
I have a button which opens a dialog box with a form with following fields : name, age and email.
I want that upon clicking the submit button , the data from the form appends the html table on the page.
jQuery script:
<script>
$(document).ready(function() {
$(function() {
$("#dialog").dialog({
autoOpen: false
});
$("#button").on("click", function() {
$("#dialog").dialog("open");
});
});
$("#submit").click(function(e) {
var email = $("#email").val();
var name = $("#name").val();
var age = $("#age").val();
var ageReg = /^[0-9]{2}$/;
var ageReg1 = /^[0-9]*$/;
var emailReg = /^([\w-\.]+#([\w-]+\.)+[\w-]{2,4})?$/;
if (email === '' || name === '' || age === "")
{
alert("Please fill all fields");
e.preventDefault();
}
else if (!(email).match(emailReg))
{
alert("Invalid Email");
e.preventDefault();
}
else if((!(age).match(ageReg)) || (!(age).match(ageReg1)))
{
alert("Invalid Age");
e.preventDefault();
}
else {
$( "#users tbody" ).append( "<tr>" +
"<td>" + name.val() + "</td>" +
"<td>" + email.val() + "</td>" +
"<td>" + password.val() + "</td>" +
"</tr>" );
dialog.dialog( "close" );
}
});
});
CSS Code:
<style>
table{
border: 1px solid black
border-collapse: collapse;
border-spacing: 0;
width:600px;
height:100%;
margin:0px;padding:0px;
}th{
text-transform : uppercase;
letter-spacing: 0.1em;
font-size : 90%;
border-bottom : 2px solid #111111;
border-top : 1px solid #111111;
}
tr.hover{
background-color:gray;
}
.tablemain{
margin-left: 300px;
margin-right: 300px;
margin-top: 50px;
}
.container{
margin-left: 450px;
margin-right: 300px;
margin-top: 5px;
}
HTML code :
<body>
<div class="container">
<div class="main">
<div id="dialog" title="Dialog Form">
<form action="" method="post">
<label>Name:</label>
<input id="name" name="name" type="text">
<label>Email:</label>
<input id="email" name="email" type="text">
<label>Age:</label>
<input id="age" name="age" type="text">
<input id="submit" type="submit" value="Submit">
</form>
</div>
<h2>jQuery Dialog Form Example</h2>
<p>Click below button to see jQuery dialog form.</p>
<input id="button" type="button" value="Open Dialog Form">
</div>
</div>
<div class= "tablemain">
<table id="users">
<thead>
<tr class="headers">
<th scope="col">Name</th>
<th scope="col">Email</th>
<th scope="col">Age</th>
</tr>
</thead>
<tbody>
<tr>
<td>Aditya</td>
<td>AAA</td>
<td>23</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
You're trying to append text in a function that expects a jQuery object. When you use append, wrap what you're appending with $().
$( "#users tbody" ).append( $("<tr>" +
"<td>" + name.val() + "</td>" +
"<td>" + email.val() + "</td>" +
"<td>" + password.val() + "</td>" +
"</tr>" ));
dialog.dialog( "close" );
}
I'm not sure about all the line breaks and white space - you might have to fiddle with that some, or even break the build out like so:
var t = $('<tr />');
t.append($("<td>" + name.val() + "</td>"));
etc...
I stopped looking for errors after seeing that first one. In addition to using text where you needed an object, you were running .val() on strings that came from the .val() functions, and trying to append a nonexistent string 'password' instead of the age field. You also neglected to add e.preventDefault() in the else block after validation, I moved it to the top of the function since it seems unconditional. I'm also curious that you say the dialog closed, since it was giving me an error because the dialog variable wasn't defined.
Also, while it didn't break anything, this structure is redundant (I would just remove the $(function() {} block, which does the same thing as $(document).ready(function() {}):
$(document).ready(function() {
$(function() {
Fully corrected code follows:
$(document).ready(function() {
$("#dialog").dialog({
autoOpen: false
});
$("#button").on("click", function() {
$("#dialog").dialog("open");
});
$("#submit").click(function(e) {
e.preventDefault();
var email = $("#email").val();
var name = $("#name").val();
var age = $("#age").val();
var ageReg = /^[0-9]{2}$/;
var ageReg1 = /^[0-9]*$/;
var emailReg = /^([\w-\.]+#([\w-]+\.)+[\w-]{2,4})?$/;
if (email === '' || name === '' || age === "") {
alert("Please fill all fields");
} else if (!(email).match(emailReg)) {
alert("Invalid Email");
} else if((!(age).match(ageReg)) || (!(age).match(ageReg1))) {
alert("Invalid Age");
} else {
$( "#users" ).append( $("<tr>" +
"<td>" + name + "</td>" +
"<td>" + email + "</td>" +
"<td>" + age + "</td>" +
"</tr>" )
);
$("#dialog").dialog( "close" );
}
});
});
<?php
mysql_connect("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$data = mysql_query("SELECT * FROM something ORDER by date_sent DESC")
or die(mysql_error());
while($info = mysql_fetch_array( $data ))
{
Print "<table width='1200px' border='0' cellspacing='0' cellpadding='0'>";
Print "<tr id='data'>";
Print "<div class='border'>";
Print "<td width='80px'><div align='center'>".$info['case_number'] ."</div></td>";
Print "<td width='80px'><div align='center'>".$info['credit_number'] . "</div></td>";
Print "</tr>";
Print "</table>";
}
?>
I want to make case_number link to ID
I made: <td width='80px'><div align='center'> <a href='edit.php?id=".$info['id'] ."'> ".$info['case_number'] ." </a> </div></td>";
but it do not work.
Can you explain how can I make this work? Thank you
<html>
<head>
<meta charset="utf-8">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" type="text/javascript"></script>
<script src="jquery.tablesorter.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function()
{
$("#csv_table").tablesorter();
}
);
</script>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data" name="import">
<label for="input_import_file">Umístění CSV souboru:</label>
<input name="import_csvfile" id="import_csvfile" type="file">
<input name="csvsubmit" id="csvsubmit" type="submit">
</form>
<?php
if($_FILES['import_csvfile']['tmp_name']){
echo '<table id="csv_table" width="100%" border="1" cellspacing="5" cellpadding="0">';
$handle = fopen($_FILES['import_csvfile']['tmp_name'], "r");
while (($data = fgetcsv($handle, 1000, ",")) !==FALSE) {
$num = count($data);
echo "<tr>";
for ($c=0; $c < $num; $c++) {
echo "<td> ".$data[$c]."</td>"."\n";
}
echo "</tr>";
}
fclose($handle);
echo "</table>";
}
?>
</body>
</html>
How can I setup and for this table generated from CSV file?
Table is generates using loop (for and while function) and I don't know how to setup first line as or if I should setup table static.
Please help me I am beginner.
Thanks in advance
If your headers are known, you can do as follows:
echo '<table id="csv_table" width="100%" border="1" cellspacing="5" cellpadding="0">';
echo '<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th>...</tr>'
$handle = fopen($_FILES['import_csvfile']['tmp_name'], "r");
Otherwise if your headers come in the CSV file you can determine if you're in the first row using a counter variable:
$counter = 0;
while (($data = fgetcsv($handle, 1000, ",")) !==FALSE) {
$num = count($data);
echo "<tr>";
for ($c=0; $c < $num; $c++) {
if($counter == 0)
{
echo "<th> ".$data[$c]."</th>"."\n";
}else{
echo "<td> ".$data[$c]."</td>"."\n";
}
}
echo "</tr>";
counter++;
}
Note that replacing the while loop with a for loop will have the same benefit.
$display = mysql_query("SELECT * FROM table_comment WHERE blogid=$theID ORDER BY comment_id DESC")or die(mysql_error());
echo "<table border='0' align='center' width='900px' style='margin-bottom:20px;margin-top:-20px;background-color:brown;border-top-left-radius:50px;border-top-right-radius:15px;border-bottom-left-radius:15px;border-bottom-right-radius:50px;'>";
while($r = mysql_fetch_array($display))
{
echo "<tr>";
echo "<td align='left' style='font-size:15px;padding-left:25px;color:PowderBlue'><b style='color:LightGreen'><i>".$r['post_name']."</b></i> said:</td>";
echo "<td align='right' style='font-size:15px;padding-right:25px;'><b style='color:Yellow'>".$r['Time']."</b>  <b style='color:Orange'>".$r['Date']."</td>";
echo "</tr>";
echo "<tr>";
echo "<td align='justify' style='color:White;font-size:20px;padding-left:25px;'> ".$r['comment_area']."</td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='2' align='center' style='padding-right:25px;color:Yellow'>_______________________________________________________________________________________________________</td>";
echo "</tr>";
}
echo "</table>";
echo "</div>";
I have this codes for my table comment, but when i try to comment spamming it over the opposite edge of the comment area, without spaces and when i hit the post button, there, some texts in my comment cannot be seen. my table is stretched far out of the original comment table. Someone can help me please?
You can use CSS to fix this problem.
HTML:
<div class="test">Thisisverylonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglongspamcomment</div>
CSS:
.test {
word-wrap: break-word;
overflow: hidden;
width:250px;}
Demo: http://jsfiddle.net/NkLuW/