following code is my php file that will list the people in my text file.
<!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">
<head>
<title>viewlist php</title>
</head>
<body>
<h1>List</h1>
<?php
$file = file("peoplelist.txt");
for($i=0; $i<count($file); $i++)
{
$person = explode(",", $file[$i]);
echo "<hr />";
echo "<table cellspacing=10><tr><td>", $i+1,".", "</td>";
echo "<td>", $person[0], "<br />";
echo $person[1], "</td></tr></table>";
}
?>
<hr />
<p>
Sort A-Z<br />
Sort Z-A<br />
</p>
</body>
</html>
what i want to do is, when i click Sort A-Z link, the file called sortatoz.php will sort the list in my text file and redirect back to viewlist.php with the list in sort order.
below is my sortatoz.php:
<?php
header("Location: http://myserver/workspace/viewlist.php");
?>
<!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">
<head>
<title>sort a to z</title>
</head>
<h1>List</h1>
<body>
<?php
$file = file("peoplelist.txt");
sort($file);
for($i=0; $i<count($file); $i++)
{
$person = explode(",", $file[$i]);
echo "<hr />";
echo "<table cellspacing=10><tr><td>", $i+1,".", "</td>";
echo "<td>", $person[0], "<br />";
echo $person[1], "</td></tr></table>";
}
?>
<hr />
<p>
Sort Visitors A-Z<br />
Sort Visitors Z-A<br />
</p>
</body>
</html>
now, when i click Sort A-Z link, it redirects back to viewlist.php...so I'm assuming the header() function is doing it's job.
but the problem is...it's not sorting.
i am very new with this, so bear with me and give me some guidance please.
what can i do to my codes to redirect back viewlist.php with sorted list?
thanks in advance.
header("Location: http://myserver/workspace/viewlist.php");
sends an HTTP header that causes the browser to redirect. The code below is executing alright, but since the browser is redirecting to another page, the user won't see the result. On the site you're redirecting to, it doesn't matter your sortatoz.php page does, it's a different page.
Also, sortatoz.php doesn't do anything of "lasting value". It just reads the file's contents, sorts these contents in memory, then outputs them. It doesn't write the sorted entries back to the file, as you may think.
Since the code on both pages is virtually the same, you'd rather just send a variable in the URL and act on it.
if (isset($_GET['sort']) && $_GET['sort'] == 'asc') {
sort($file);
}
And link to the site like viewlist.php?sort=asc.
Basically, right now, you're doing the sorting right, but because you redirect to viewlist.php immediately none of the code below is executing. Why do you want to, anyway? You could just stay on sortatoz.php without the redirect and it would work perfectly.
Related
From everywhere I look and research it seems possible to also put the tags within your php code, but for some reason only when my tag is outside of php it works. I can't seem to figure out the issue with it. The reason I am trying to print inside is because I am trying to create a nested for loop. Currently I commented out the table tags outside of the php and have them printed in the php code. This currently does not work. Here is my code and thank you again.
<?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>
</head>
<!-- <table border="1px"> -->
<!-- <tbody> -->
<?php
/*
Version 1.1: Instead of printing the teams in different cells we are going to print the
games in one row and we select the game itself to see if an upset will occur.
*/
require_once('Conference.php');
$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">";
for ($i = 0; $i < 8; $i++)
{
$highSeed = $teams[$i];
//$lowSeed = $teams[((2*8)-1)-$i];
echo "<tr><td>$highSeed</td>"; //<td>$lowSeed</td></tr>
}
echo "</table>";
?>
<!-- </tbody> -->
<!-- </table> -->
<body>
</body>
</html>
First issue is
echo "<table border="1">";
it should be
echo '<table border="1">';
then
echo "<tr><td>$highSeed</td>";
better way is
echo '<tr><td>'.$highSeed.'</td></tr>';
I am creating a program in which I have a list of products. I want a user to click on any specific product and see its details. I have written the following code. I am grabbing the current 'product_id' into $_SESSION variable and displaying its details in the next page. Its working,but not giving me the desired output, its grabbing the same id for each product. I think its because i am storing its value in $_SESSION. Kindly check it and tell me the correct way of doing it.
<!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>
</body>
</html>
<?php
session_start();
include 'connect.php';
$query= mysql_query ("select product_id,name, price, description from products" );
while ($query_array= mysql_fetch_assoc($query))
{
echo '</br><pre>';
$_SESSION['id']= $query_array['product_id'];
$product_id= $_SESSION['id'];
echo "<a href='single_product.php?product_id=$product_id' >";
print_r ($query_array['name']);
echo "</a>";
print_r ($query_array['price']);
echo "<img src= 'all_images.php' alt= 'Image'";
echo '</pre>';
}
?>
you need to define the $row in $_session and not $_session to $row
$_SESSION['id']= $query_array['product_id']; //<---- must reverse it.
$product_id= $_SESSION['id'];
try this
$product_id = $query_array['product_id'] ;
$product_id = $_SESSION['id'];
Or you can pass the ID via $_GET
in your code
echo "<a href='single_product.php?product_id=$product_id' >";
you can get the product_id like that in the other file
echo $_GET['product_id'] ;
i have this code in php. i want my images displayed to be horizontally displayed. those images are saved in xampp. can anybody help me? this is my code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
mysql_connect("localhost","root","");
mysql_select_db("dbLetters");
$res=mysql_query("select * from tbLetters");
echo "<table>";
while ($row = mysql_fetch_array($res))
{
echo "<tr>";
echo "<td>";?> <img src = "<?php echo $row["images"]; ?>" height="200" width="200"> <? php echo "</td>";
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>
your response will be a big help. thanks. :))
Unless you use a data url, you actually need to set up a separate script to pull that will provide the image to the browser.
This will make your image url something like image.php?id=<image_id>. The image.php script will fetch the image and provide the image to the browser.
Its not usually a good idea to store image data in mysql.
Hello I'm making a website, and I want the albums and photos from a facebook page to be shown in a box.
Here is an example
I want the albums and photos to be shown just like this, in a slide, instead of finding the it automatically takes the photos from any decided album.
Example page
Here is the code used in the example page, this takes random pictures stored in a folder and displays them, same method should be used for the facebook album. This is where I'm stuck.
The code:
<!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=iso-8859-1" />
<title>*title*</title>
<script src="scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="scripts/jquery.cycle.all.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#myslides').cycle({
fit: 1, pause: 2, timeout: 200
});
});
</script>
<link rel="stylesheet" href="styles/dynamicslides.css" type="text/css" media="screen" />
</head>
<body>
<?php
$directory = 'images/slideshow/';
try {
// Styling for images
echo "<div id=\"myslides\">";
foreach ( new DirectoryIterator($directory) as $item ) {
if ($item->isFile()) {
$path = $directory . "/" . $item;
echo "<img src=\"" . $path . "\" />";
}
}
echo "</div>";
}
catch(Exception $e) {
echo 'No images found for this slideshow.<br />';
}
?>
</body>
</html>
Hope you understand what I'm trying to say here :)
I have little knowledge about this, so be easy one me.
Sorry for my bad English.
From what i have understood
Give a name tag to each of the photos in an album.. when u click on one album all you need to do is run the a loop for that name tag.
If this doesn't suffice, explain your problem clearly. Some code will actually help understand the problem better
I have found similar questions but none as specific as this one.
The following code is a simplified version that reproduces the problem.
<?php
function addProgressText($texto)
{
echo '<script type="text/javascript">';
echo 'document.getElementById("mensajesEnProgreso").innerHTML += "'.$texto.'";';
echo '</script>';
flush();
ob_flush();
}
?>
<!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 name="viewport" content="width=device-width" />
<title>TEST - Flush for Android</title>
</head>
<body>
<div id="divEnProgreso">
<p id="mensajesEnProgreso"></p>
</div>
<?php
addProgressText("Init...");
sleep(5);
addProgressText("OK<br>Step 1... ");
sleep(5);
addProgressText("OK<br>Step 2... ");
sleep(5);
addProgressText("OK<br>Step 3... ");
sleep(5);
addProgressText("OK<br>FINISHED");
?>
</body>
</html>
The code works as expected (displays the steps one by one) on Chrome, Firefox and IE, but when I open it from an Android browser, the flushes don't work and everything is displayed at once upon completion.
Any hints on the source of the problem?
Thanks
The reason for that is surely the 4K buffering in the Android browser.
The only option you have is to pad the output to 4K as described in this bug report.