I would like to create a system to issue opinions on a given thing. I'm at a good point, but I can not get created for each element taken from the database a correspond div. Let me explain, for example if I have three reviews made by the three authors, I would like three divs for the reviews, and three for the authors, then automatically generated by the loop. How can i do?
You can do this.. First of all add <body> tag to your html document
<!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" />
</head>
<body>
<?php
$Content = mysql_query("SELECT * FROM feedback");
while($Row = mysql_fetch_array($Content)) {
$Feedback = $Row['FeedbackUser'];
$UserNick = $Row['UserNickname'];
$UserMail = $Row['UserEmail'];
echo "<div>{$Feedback}</div>"; // Displaying feedback as div
echo "<div>{$UserNick }</div>"; // Displaying UserNick as div
echo "<div>{$UserMail }</div>"; // Displaying UserMail as div
}
?>
</body>
Hope this is what you are looking for
Related
https://pastebin.com/pEg8ZARP
<!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" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Future Value</title>
</head>
<body>
<?php # Script 1.8 - futureValue.php.
// Set the variables:
$interest = .08;
$amount = 1000;
$years = 20;
// Calculate the value:
$value = $amount* pow( (1+$interest), $years);
// Format the total:
$value = number_format ($value, 2);
// Print the results:
echo "<p>The future value is <b>/$$value</b>.</p>";
?>
</body>
</html>
I tried pasting it here but the formatting got messed up.
Whenever I try to load the page it just says " The future value is /$$value.
"; ?> " instead of displaying "The future value is $4660.96.".
I am totally lost at what I am doing wrong.
echo "<p>The future value is <b>$".$value."</b>.</p>";
$ is a special character so you need to escape it. Or you can always just concat your string and variable to avoid this problem.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I'm trying to figure out what I'm doing wrong when I combine the explode function with session variables. I've done a decent amount of research already on session variables AND the explode function, but I've had trouble finding help on "combining" the two.
Below is the code I'm using. You'll notice that $_SESSION['shirt_type'] is being "exploded". This variable collects two pieces of info, the shirt type and price. I want to explode $_SESSION['shirt_type'] into two chunks.
However, when I try to echo chunk[0] or [1] using the following,
echo "Shirt Type = {$_SESSION['$shirt_type_chunks[0]']}<br>";
echo "Shirt Price = {$_SESSION['$shirt_type_chunks[1]']}<br>";
My web page echos the following
Shirt Type =
Shirt Price =
I believe I have the syntax wrong and I have not been able to find any place that demonstrates the correct syntax when trying to echo an exploded session variable.
Any help that can be offered will be GREATLY appreciated. Also, I've VERY new to StackOverflow so if I've posted something incorrectly, I apologize.
<!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>
<?php
session_start();
$_SESSION['shirt_type'] = $_POST['shirt_type'];
$_SESSION['shirt_type_chunks'] = explode("|", $shirt_type);
$_SESSION['shirt_size'] = $_POST['shirt_size'];
$_SESSION['shirt_size_chunks'] = explode("|", $shirt_size);
$_SESSION['shirt_qty'] = $_POST['shirt_qty'];
$_SESSION['price'] = $_SESSION['$shirt_type_chunks[1]'] + $_SESSION['$shirt_size_chunks[1]'];
?>
</head>
<body>
<p>
<?php
session_start();
echo "Shirt Type = {$_SESSION['$shirt_type_chunks[0]']}<br>";
echo "Shirt Price = {$_SESSION['$shirt_type_chunks[1]']}<br>";
echo "Shirt Up Charge = {$_SESSION['$shirt_size_chunks[1]']}<br>";
echo "Shirt Size = {$_SESSION['$shirt_type_chunks[0]']}<br>";
echo "Shirt Qty = {$_SESSION['shirt_qty']}<br>";
echo "Price = {$_SESSION['price']}<br>";
?>
</p>
</body>
</html>
You should start session before any output.
Change your code to:
<? session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
...
<title>Untitled Document</title>
<?
$_SESSION['shirt_type'] = $_POST['shirt_type'];
$_SESSION['shirt_type_chunks'] = explode("|", $shirt_type);
$_SESSION['shirt_size'] = $_POST['shirt_size'];
$_SESSION['shirt_size_chunks'] = explode("|", $shirt_size);
$_SESSION['shirt_qty'] = $_POST['shirt_qty'];
$_SESSION['price'] = $_SESSION['$shirt_type_chunks[1]'] + $_SESSION['$shirt_size_chunks[1]'];
?>
</head>
Second thing you have wrong here is that $_SESSION['shirt_type'] and $shirt_type can be the same variable if register_global = on on your system. Try to avoid using same names for variables as for global variables, such as $_POST['some_name'] and $some_name or $_SESSION['var_name'] and $var_name
And the third issue, noticed by #brenjt, you need only one call for session_start() in your script.
Fourth =) $_SESSION['$shirt_type_chunks[1]'] won't work. Using single quotes in PHP means that interpreter will not even try to find any variable in your string. Small example:
<?
$a = "Mike";
echo "Hi, my name is $a"; // will output Hi, my name is Mike
echo 'Hi, my name is $a'; // will output Hi, my name is $a
echo 'Hi, my name is '.$a; // will output Hi, my name is Mike
?>
Third way is a most efficient because in this case PHP sees single quotes and do not spend resources to analyse string. So change it to $_SESSION[$shirt_type_chunks[1]]
Here is what, as I suppose, you was heading to:
<?php session_start(); ?>
<!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>
<?php
$shirtDetails = explode("|", $_POST['shirt_type']);
$_SESSION['shirt_type'] = $shirtDetails['0'];
$_SESSION['shirt_price'] = $shirtDetails['1'];
$sizeDetails = explode("|", $_POST['shirt_size']);
$_SESSION['shirt_size'] = $sizeDetails[0];
$_SESSION['shirt_up_charge'] = $sizeDetails[1];
$_SESSION['shirt_qty'] = $_POST['shirt_qty'];
$_SESSION['price'] = $_SESSION['shirt_qty'] * $_SESSION['shirt_price'] + $_SESSION['shirt_up_charge'];
?>
</head>
<body>
<p>
<?php
echo 'Shirt Type = '.$_SESSION['shirt_type'].'<br>';
echo 'Shirt Price = '.$_SESSION['shirt_price'].'<br>';
echo 'Shirt Up Charge = '.$_SESSION['shirt_up_charge'].'<br>';
echo 'Shirt Size = '.$_SESSION['shirt_size'].'<br>';
echo 'Shirt Qty = '.$_SESSION['shirt_qty'].'<br>';
echo 'Total Price = '.$_SESSION['price'].'<br>';
?>
</p>
</body>
</html>
One final question - why you not just create single input for each form property? Why you want this data to be concatenated by |, is it really necessary?
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
A simple program to CRUD node and node values of xml file
I tried calling the data in my XML in the below way. But it didn't work for me. Can anybody tell me how can I make it work?
<broad>
<site>
<title>My Site Name</title>
<caption>My Site Caption</caption>
<hostname>www.mydomain.com</hostname>
</site>
<broad>
My PHP file is
<?php
$xml = simplexml_load_file('settings.xml');
?>
<!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><?php echo $xml->title; .'|'. $xml->caption; ?></title>
</head>
<body>
</body>
</html>
Why the above way is not working? is there any other way which is more easier than this?
You need to access the site node:
<?php echo (string) $xml->site->title?>
If ever in doubt, use a var_dump:
<?php echo '<pre>'; var_dump($xml); echo '</pre>'; ?>
Use the following:
<?php echo (string)$xml->site->title .'|'. (string)$xml->site->caption; ?>
Use SimpleXML debug with var_dump() and print_r()
Consider the following PHP code for getting RSS news on a site I'm developing:
<?php
$url = "http://dariknews.bg/rss.php";
$xml = simplexml_load_file($url);
$feed_title = $xml->channel->title;
$feed_description = $xml->channel->description;
$feed_link = $xml->channel->link;
$item = $xml->channel->item;
function getTheData($item){
for ($i = 0; $i < 4; $i++) {
$article_title = $item[$i]->title;
$article_description = $item[$i]->description;
$article_link = $item[$i]->link;
echo "<p><h3>". $article_title. "</h3></p><small>".$article_description."</small><p>";
}
}
?>
The data accumulated by this function should be presented in the following HTML format:
<!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" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Новини от Дарик</title>
</head>
<body>
<?php getTheData($item);?>
</body>
</html>
As you see I added windows-1251(cyrillic) and utf-8 encoding but the RSS feed is unreadable if I don't change the browser encoding to utf-8. The default encoding in my case is cyrilic but I get unreadable feed. Any help making this RSS readable in cyrilic(it's from Bulgaria) will be greatly appreciated.
I've just tested your code and the Bulgarian characters displayed fine when I removed the charset=windows-1251 meta tag and just left the UTF-8 one. Want to try that and see if it works?
Also, you might want to change your <html> tag to reflect the fact that your page is in Bulgarian like this: <html xmlns="http://www.w3.org/1999/xhtml" lang="bg" xml:lang="bg">
Or maybe you need to force the web server to send the content as UTF-8 by sending a Content-Type header:
<?php
header("Content-Type: text/html; charset=UTF-8");
?>
Just be sure to include this before ANY other content (even whitespace) is sent to the browser. If you don't you'll get the PHP "headers already sent" error.
Maybe you should take a look at htmlentities.
This can convert to html some characters.
$titleEncoded = htmlentities($article_title,ENT_XHTML,cp1251);
As you'll see, I'm a newbie to all this ajax stuff but I can do a bit of php and so I plumped for xajax to take care of the javascript for me.
I've got an array with items listed in different section. I want to use this array to produce an unordered list that expands when someone clicks on a section.
I've adapted a script I found here:
Sliding Draw
My script currently looks like this:
<?php
include ("xajax_core/xajax.inc.php");
$subs = array(
"Mortice" => array("Union Deadlock 2.5", "Union Deadlock 3", "Union Sashlock 2.5", "Union Sashlock 3"),
"Cylinders" => array("30/30 Euro", "30/40 Euro", "30/50 Euro", "30/60 Euro"),
"uPVC" => array("30/92 Fullex", "35/92 Fullex", "Sash jammer")
);
function addsub($show, $key)
{
$objResponse=new xajaxResponse();
if ($show=="true") {
$objResponse->assign("list", "style.display", "block");
$objResponse->replace("$key","innerHTML","true","false");
}
else {
$objResponse->assign("list", "style.display", "none");
$objResponse->replace("$key","innerHTML","false","true");
}
return $objResponse;
}
$xajax = new xajax();
$xajax->registerFunction("addsub");
$xajax->processRequest();
?>
<!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" />
<?php $xajax->printJavascript() ?>
<title>Expand menu test</title>
<style type="text/css">
.list {display: none;}
</style>
</head>
<body>
<?php
echo "<ul>\n";
foreach ($subs as $key => $group) {
echo "<li id=\"".$key."\" onClick=\"xajax_addsub('true','$key');\">".$key."\n";
echo "<ul class=\"list\" id=\"list\">\n";
while (list($list, $each) = each($group)) {
echo "<li id=\"list\">".$each."</li>\n";
}
echo "</ul>\n</li>\n";
}
echo "</ul>";
?>
</body>
</html>
The idea is that when an element is clicked on it changes the style display to block (thus showing the rest of the list) and sets the function to 'false' so if it's clicked again it will change the display back to none and hide the list.
Needless to say it doesn't work so if someone could point out to me why I'd be eternally grateful.
Cheers,
Nick.
Solved - I sorted it by placing the lists to be shown (or hidden) into <divs> and assigning them each a unique id and setting their style as display: none.
Then I just had to make a request to set the style as block when it was clicked on.
Thanks.
I think you should look into jQuery as your default javascript library, it's used by many web professionals and is very good. There you will find the Accordion control, which I think will suite this need very well.
Good luck!