sessionStorage is 1/2 working - sessionstorage

pag1.php
<div id="guest_name"></div>
<?
//Some code
echo '<script>';
echo 'var guest_name = ' . json_encode($guest_name) . ';';
echo '</script>';
echo "<a href=main.php>Enter</a>";
?>
<script>
//This works great
$("#guest_name").text(sessionStorage.getItem("guest_name"));
</script>
when I click on and go to main.php, it stops working!!
<div id="guest_name"></div><!--Nothing is shown this div here -->
<script>
$("#guest_name").text(sessionStorage.getItem("guest_name")); //Does not work!!
</script>
main.php is NOT loaded in a new window or a new tab! Thank you

Related

PHP Simple HTML DOM parsing to get to elements inside a href

<div>
text1
</div>
<div>
text2
</div>
<div>
text3
</div>
hello,
i try to parse links in html code below."thread_title" tag has different numbers.but could not solve it
thanks
$html = new simple_html_dom();
$html->load($input);
foreach($html->find('a[id=thread_title_([^\"]*)]') as $link)
echo $link->outertext . '<br>';
$html = new simple_html_dom();
$html->load($input);
foreach($html->find('a[id^=thread_title]') as $link)
echo $link->outertext . '<br>';

Jquery dialog echo check content

How to check echo dialog alert
if <div class="mydialog"></div> no dialog alert
else <div class="mydialog"> $Value-content </div> echo dialog alert $Value-content
Thanks
echo '<script type="text/javascript">'
, 'IF (' . $Value-content . ' != \"\")'
, 'Alert(' . $Value-content . ');'
, '</script>'
;

How to setup thead & tbody for generated table?

<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.

JQuery Sortable\Serialize issue

I have a document that uses PHP to generate a list from a DB
$q = "SELECT * FROM display ORDER BY diplay_order ASC";
$r = #mysqli_query ($dbc, $q);
echo "<ul id='categoryorder'>";
while ($item = mysqli_fetch_array($r)) {
echo "<li><div id='" . $item['ad_type'] . "_" . $item['unique_id'] . "'>
<form name='remove' action='saveable.php' method='get'>
<input type='submit' value='remove' />
<input type='hidden' name='id' value='" . $item['unique_id'] . "'>
</form>" .$item['unique_id'] . "</div></li>";
}
echo "</ul>";
I have then made these sortable which works fine but I can't get the serialize to work and it just creates an empty array.
$(document).ready(function() {
$('ul#categoryorder').sortable({
update: function() {
var order = $("ul#categoryorder").sortable("serialize");
alert(order);
}
});
});
Then the alert box just comes up empty. I am very new to this and any help would be much appreciated.
You need to add id to <li> tag. Change this part of PHP code,
echo "<li id='" . $item['ad_type'] . "_" . $item['unique_id'] . "'><div><form name='remove' action='saveable.php' method='get'><input type='submit' value='remove' /><input type='hidden' name='id' value='" . $item['unique_id'] . "'></form>" .$item['unique_id'] . "</div></li>";
Added id to <li>.

Working with multiple dialog boxes, logics error

I am using the following code to View Complete Messages from Users, on my web page.
u can see my web page here : http://team-kh.hireexpertprogrammers.com/~maiarn/Admin.php
But the only prob is some logic Error here, When i randomly click on the View Complete link, the dialog Box, shows me the title and content of the first message. How can i avoid this error:
Such that, which View Complete Link is clicked, the dialog box shall show the title and content of that row , message.
<?php
$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"FullName");
$Name = $ f1;
$f2=mysql_result($result,$i,"EmailAddr");
$string=mysql_result($result,$i,"Message");
$limit=10;
$string1 = myTruncate($string,$limit);
?>
<tr>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $string1; ?></font>
<a id="button1"href="#">View Complete</a>
<div id="dialog1"title="<?php echo $Name; ?>" style="display: none;">
<?php echo $string; ?></div>
</td>
</tr>
<?php
$i++;
}
?>
The script is
<script type="text/javascript" src="jquery/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="jquery/js/jquery-ui-1.8.18.custom.min.js">
</script>
<script type="text/javascript">
$(document).ready(function() {
$("a#button1").click(function(e) {
e.preventDefault();
$("#dialog1").dialog({height: 300, width: 500, modal: true});
});
});
</script>
You either need to assign dynamic ID's to your dialogs based on a number or some other distinguishing string or load the information from the row into a single dialog before you display it (which would be preferable).

Resources