I have this HTML code for my div:
<div id="ticketupdates" style="display:none;">
</div>
then within the div i have this PHP Code:
<?php
$sql2="
SELECT
ticket_seq,
CONCAT(CONCAT(notes),'<br><br>',filename,'') as displaydata,
datetime as timestamp,
updatedby,
CONCAT('<strong>Time Start: </strong>',timestart,' - <strong>Time End: </strong>',timeend) as timestartend
from ticket_updates where ticket_seq = '".$result["ticketnumber"]."'
UNION
SELECT
ticket_seq,
CONCAT('<strong>',ticketchange,'</strong><br>' ,description) as displaydata,
datetime as timestamp,
changed_by as updatedby,
blankfield
from ticket_changes where ticket_seq = '".$result["ticketnumber"]."'
ORDER by timestamp ASC ";
$rs2=mysql_query($sql2,$conn) or die(mysql_error());
while($result2=mysql_fetch_array($rs2))
{
$timestartend2 = ($result2["timestartend"] > '') ? '<br><br>'.$result2["timestartend"] : '';
echo '<tr>
<td colspan="2" bgcolor="#666666" align="left"><font color="#FFFFFF"><strong>'.$result2["updatedby"].'</strong></font></td>
<td bgcolor="#666666" align="right"><font color="#FFFFFF"><strong>'.$result2["timestamp"].'</strong></font></td>
</tr>
<tr>
<td colspan="3">'.nl2br($result2["displaydata"]).''.$timestartend2.'</td>
</tr>
<tr>
<td colspan="3"></td>
</tr>';
}
?>
obviously the div is hidden as its got display:none on the style of it but it's still displaying the PHP results.
If i just put some plain text inside the div like this:
<div id="ticketupdates" style="display:none;">
hello
</div>
it doesn't display. I am doing this as I have a link that expands the div to show the content.
Any ideas why it's not working with the PHP Code?
Did you open and close that table that your putting rows and columns too? If you did not open it, you might get some unexpected results.
The name of the ID '#ticketupdates' sounds like this could be loaded by an AJAX request?
Try hiding it after the request with Javascript, or with jQuery;
$('#ticketupdates').hide();
And for the open doors; please try to not use mysql_* functions, and try to seperate the PHP and styling from the HTML (especially from SQL).
Related
I'm in the process of building an entertainment website. It uses THREE MySQL tables; one called title, one called clips and one called dialogue.
I've been playing around all day with having my PHP fetch data from TWO of the tables (clips and dialogue) and output the content in a HTML table.
I've not had much luck and to cap it all, I was using a free host which has now reached its EP limit and although I've upgraded, I've got to wait 24 hours to try the code I've now come up with.
My question is, have I done it right? Will this collect basic information about the clip and then produce each line of the script in a new TR before going back to the start and collecting information for the next clip?
I really hope this makes sense.
I've tried researching this and have re-built my PHP from the ground up, ensuring that I annotate each section. Last time I checked, it still didn't work!
<table class='container'>";
##############################
# CLIPS QUERY & ECHOING HERE #
##############################
$clipsquery = "SELECT * FROM clips WHERE titleid=$mainurn ORDER BY clipid";
$result2 = mysqli_query($cxn, $clipsquery);
while ($row2 = mysqli_fetch_assoc($result2))
{extract ($row2);
echo "
<tr>
<td colspan='3' class='divider'></td>
</tr>
<tr>
<td class='description'>";
if ($epident == "")
{echo "";}
else
{echo "<span class='episode'>$epident</span>";}
echo "</td>
<td rowspan='2' style='text-align: right'><audio controls>
<source src='media/$clipid.mp3' type='audio/mpeg'>Your browser does not support the audio element.</audio></td>
<td rowspan='2' style='text-align: right'><a href='media/$clipid.mp3' download='$clipid.mp3'><img src='graphics/dl-icon.png' alt='Download Icon' title='Right-click here to download this clip to your computer.'></a></td>
</tr>
<tr>
<td class='description'>$clipsynopsis</td>
</tr>
<tr>
<td colspan='3'></td>
</tr>";
#################################
# DIALOGUE QUERY & ECHOING HERE #
#################################
$dialoguequery = "SELECT * FROM dialogue WHERE clipid=$clipid ORDER BY linenum";
$result3 = mysqli_query($cxn, $dialoguequery);
while ($row3 = mysqli_fetch_assoc($result3))
{extract ($row3);
echo "
<tr>
<td class='speaker'>$speaker:</td>
<td colspan='2' class='script'>$dialogue:</td>
</tr>";}}
echo "
</table>
I've got the site to work (sort of) but the formatting went wild and sometimes included clips from other sources not meant to be on the page!
There are some things I would change in your code. If you trust the variables going into your sql query then change your while loops:
while($row = $result->fetch_assoc()){
$fetchValue = $row['COLUMN_NAME'];
}
I would say you shouldn't be using extract here.
If the user is able to modify the variables going into your sql statement you should implement prepared statements. I would build a class/function and just call it when you need it.
From the HTML/CSS side its probably going to serve you better to use css div tables, especially if you are planning to make the site responsive down the line. This can convert yours
With regards to the queries, I'm not sure I understand the structure of your tables. If you want to keep playing around on your machine install a L/W/M/AMP stack depending on your operating system. See here for more information.
You only need one table where you store the data of clips.
First, you fetch the data into an array, then
you can loop through that array with foreach,
creating the table and filling it with data.
You can use an alternative syntax for foreach to make mixing PHP with HTML easier.
//Creating the array of clips
$clips = [];
$sql = "SELECT * FROM clips";
if($result = mysqli_query($db, $sql)) {
while($row = mysqli_fetch_assoc($result)) {
array_push($clips, $row);
}
}
?>
<!-- Looping through the array and creating the table -->
<table class="container">
<?php foreach ($clips as $clip): ?>
<tr>
<td colspan='3' class='divider'></td>
</tr>
<tr>
<td class='description'>
<span class='episode'><?php echo $clip["id"]; ?></span>
</td>
<td rowspan='2' style='text-align: right'>
<audio controls>
<source src='<?php echo "media/". $clip["id"]. ".mp3"; ?>' type='audio/mpeg'>
Your browser does not support the audio element.
</audio>
</td>
<td rowspan='2' style='text-align: right'>
<a href='<?php echo "media/". $clip["id"]. ".mp3"; ?>' download='<?php echo $clip["id"]. ".mp3"; ?>'>
<img src='graphics/dl-icon.png' alt='Download Icon' title='Right-click here to download this clip to your computer.'>
</a>
</td>
</tr>
<tr>
<td class='description'>
<?php echo $clip["sypnosis"]; ?>
</td>
</tr>
<tr>
<td class='speaker'>
<?php echo $clip["speaker"]; ?>
</td>
<td colspan='2' class='script'><?php echo $clip["dialogue"]; ?>
</td>
</tr>
<?php endforeach; ?>
</table>
You need 1 MySQL table (clips) with the 4 attributes.
You should consider using PDO over mysqli, because it's a better way of dealing with the database.
Also, template engines like Smarty can help you make the code more readable and modifiable, separating the application logic from the presentation logic.
you must use JOIN in your Sql query
SELECT
clips.clipid, clips.columnname,
dilogue.id, dialogue.columnname
FROM
clips JOIN dialogue ON
clips.clipid = dialogue.id
WHERE
clipid=$clipid
ORDER BY linenum
then you can use
while($row = mysqli_fetch_assoc($result)){
echo $row['column name in clips table'];
echo $row['column name in dialogue table'];
}
but you must use Prepared statements or
mysqli_real_escape_string()
to avoid Sql Injections
also open and close PHP tags before and after html)
I am trying to match text, and output the entire row including self in xpath.
The issue I am having is the self node also contains javascript in the html table and it is outputing the script as well.
I have tried the following:
Working but contains javascript from the self node:
$bo_row = $bo_xpath->query( "//td[contains(text(),'1234')]/following-sibling::* | //td[contains(text(),'1234')] " );
Failed attempts all look similar to:
$bo_row = $bo_xpath->query( "//td[contains(text(),'1234')]/following-sibling::* | //td[contains(text(),'1234')]//*[not(self::script)] " );
Here is an example of one table row:
<tr>
<!-- <td><a class=info href="**Missing Data**">
<img src="../images/button_go.gif" border=0>
<span>**Missing Data**</span>
</a>
</td> -->
<script>
if (document.getElementById("Function").value != 'Customer')
document.write('<td><a class=info href="OrdDetLine.pgm?Order=CV780&Page=02&Line=05&Seq=00&ShowPrice=&OpenOnly=&Function=Customer"><img src="../images/button_go.gif" border=0><span>Order Line Detail</span></a></td>');</script>
<td align="left">2-05-00</td>
<td align="left"> 1234
<script>if (document.getElementById("Function").value != 'Customer')
document.write("<a class=info href=#><img src=/operations/images/eye.png border=none onClick=window.open(\'StyleHdr.pgm?CompDiv=CO&Style=1234\'><span>Show style master information panel.</span></a>") ; </script>
</td>
<td align="left">MEN'S LAB/SHOP COATS</td>
<td align="left">REG</td>
<td align="left">NAY</td>
<td align="right">1</td>
<td align="right">April 12, 2019</td>
</tr>
I have tried using getAttribute to select the innertext like so:
$bo_row = $bo_xpath->query( "//tr/td[contains(text(),'1234')]/following-sibling::* | //td[contains(text(),'1234')] " );
echo '<br/>';
if ( $bo_row->length > 0 ) {
foreach ( $bo_row as $row ) {
echo $row->getAttribute ('innerText');
}
However I am either using getAttribute incorrectly or it is not supposed by php as indicated by PHPstorm
You have to use getAttribue('innerText'). Here is the console output with 2 different approaches.
I'm trying to display automatically the total sum (also the average for certain rows) of a row in the footer of a PHP table.
I'm not sure how can I do that.
I'm using this query:
$query = "SELECT sector, SUM(usdAmount) AS total, SUM(sumaAbas) as abas FROM DatosSpend WHERE negotiableProcGl='Y' GROUP BY sector
and populating the table like this:
while($row = mysqli_fetch_array($result)){
echo '
<tr>
<td class="text-center title-row-table">'.$row["sector"].'</td>
<td class="text-right table-spend">$'.number_format($row["total"]/"1000",0).'</td>
<td class="text-right table-spend">'.round(#($row["abas"]/$row["total"]*"100"),0).'%</td>';
}
most likely an easy solution, but please forgive my early learning curve in the world of programming and using php with jquery together. I'm able to retrieve information from the database easily and display that on the screen. However, I'd like to be able to hide certain elements that are retrieved from the database and written out in php on the page and show them on a click event. I'm able to do this easily on other sections of the website, that are not being retrieved using $.post. Are there certain rules that apply with jQuery once I've used $.post and ajax to retrieve info from the database?
php below:
<?php echo "
<div class='phone_tracking customCall separation'>
<h3>Phone Tracking</h3>
<a class='showCustomDatePhone' href='#customDate_individualPhone'>View & Listen to Individual Phone Leads >></a>
<table>
<tr class='tableHead'>
<td>Date</td>
<td>Traffic+ Calls</td>
<td>New Vehicle Calls</td>
<td>Used Vehicle Calls</td>
<td>Service Calls</td>
<td class='totalTally'>Total Calls</td>
</tr>
<tr>
<td>`$valueRetrieved` - `$valueRetrieved2`</td>
<td>$customDateTrafficPlusTally</td>
<td>$customDateNewVehicleTally</td>
<td>$customDateUsedVehicleTally</td>
<td>$customDateServiceTally</td>
<td>$customDateTally</td>
</tr>
</table>
<div id='customDate_individualPhone'>
<h4>All Individual Phone Calls For `$valueRetrieved` - `$valueRetrieved2`</h4>
<table>
<tr>
<td>Date</td>
<td>Ad Source</td>
<td>Caller Phone Number</td>
<td>Tracking Phone Number</td>
<td>Target Phone Number</td>
<td>Call Duration (in seconds)</td>
<td>Result of Phone Call</td>
<td>Call Listen Link</td>
</tr> " . $showTheCustomDatePhoneTable ."
</table>
</div>
</div>
"; ?>
jQuery below:
$('#customDate_individualPhone').hide();
$('.showCustomDatePhone').click(function(){
var txt = $("#customDate_individualPhone").is(':visible') ? 'View & Listen to Individual Phone Leads >>' : '<< Hide Individual Phone Leads';
$(".showCustomDatePhone").text(txt);
$('#customDate_individualPhone').toggle();
});
The ajax to retrieve the data (if that helps)
$('#getDateRange').on('click', function(){
var startDate = $('#dateStart').val();
var endDate = $('#dateEnd').val();
if ($.trim(startDate) != '') {
$.post('../../includes/dateRangeWhitePlainsNissan.php', {dateStart: startDate, dateEnd: endDate}, function(data){
$('#fromDatabase').html(data);
});
}
});
I'm still very new to programming so you're help is greatly appreciated! Thanks
You'll need to re-initialize your click functions with a callback, or convert them to use on().
$('.showCustomDatePhone').on('click', function(){});
I have one table in loop which come under li:
<?php
for($i=1;$i<=$tc;$i++)
{
$row=mysql_fetch_array($result);
?>
<li style="list-style:none; margin-left:-20px">
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="hline" style="width:267px"><?php echo $row['tit'] .",". $row['name'] ?></td>
<td class="vline" style="width:1px"> </td>
<td class="hline" style="width:100px"><?php echo $row['city']; ?></td>
</tr>
</table>
</li>
<?php
}
?>
The output comes like this:
alt text http://img20.imageshack.us/img20/4153/67396040.gif
I can't put table outside the loop, due to <li> sorting
if you can't use table outside the loop then i think best option will be use of
<div>
statement
for example
<div class="q-s na">
<div class="st" style="margin-right:10px; width:150px">
<div class="m-c"><?php echo $row['tit'] .",". $row['name'] ?></div>
</div>
this will be same as you one
<td>
you can define style according to your requirements.
for example
<style>
.q-s{overflow:hidden;width:664px;float:left;
padding-top:2px; padding-bottom:2px; height:25px}
.na .st{ float:left;}
.na .m-c {border-bottom:1px dotted #999; padding-bottom:10px; height:15px}
</style>
i can't put table outside the loop.
Why not? This is where it belongs. After all, you (logically) produce one table, not many of them. No need for the list item, either.
If you're unable to put the table outside of the loop, you should probably just use tags rather than creating tables, as you're defeating the purpose of even having a table by making each table a single row and trying to stack them.
Another thing to note if you are going to stick with tables:
If you're hard-coding the table width AND all of the table cell (column) widths, it may cause unexpected issues when they don't add up:
Table width = 600px
Cells = 267 + 1 + 100 = 368px