I need to pass value with href inside fetch array echo...
php code
$user = $get['username'];
$resource=mysqli_query($con,$sql);
echo "<font color=\"#000000\">
<h2 align=\"center\"></h2>
<table align=\"center\" border=\"1\" width=\"50%\">
<tr>
<td><b>GROUP NAME</b></td> <td><b>TASK TITLE 1</b></td> <td><b>TASK TITLE 2</b></td> <td><b>CREATED BY</b></td> <td><b>ASSIGNED TO</b></td> <td><b>DUE DATE</b></td> <td><b>PRIORITY</b></td> <td><b>CHANGE</b></td></tr> ";
while($result=mysqli_fetch_array($resource))
{
echo "<tr><td>".$result[0]."</td> <td>".$result[1]."</td> <td>".$result[2]."</td> <td>".$result[3]."</td> <td>".$result[4]."</td> <td>".$result[5]."</td> <td>".$result[6]."</td> <td> "<a href="changetask1.php?username='.$user.'">"</td></tr>";
} echo "</table></font>";
I need to pass username to next page with href value.
You are all messed up with quotes...
First... Learn to indent your code to make it readable.
Then, avoid echoing simple HTML if not necessary:
See your code after my «formatting»:
Try it, i've done a couple corrections...
<?php
$user=$get['username'];
$resource=mysqli_query($con,$sql);
?>
<!-- This is only HTML -->
<font color="#000000">
<h2 align="center"></h2>
<table align="center" border="1" width="50%">
<tr>
<td><b>GROUP NAME</b></td>
<td><b>TASK TITLE 1</b></td>
<td><b>TASK TITLE 2</b></td>
<td><b>CREATED BY</b></td>
<td><b>ASSIGNED TO</b></td>
<td><b>DUE DATE</b></td>
<td><b>PRIORITY</b></td>
<td><b>CHANGE</b></td>
</tr>
<?php
// This is a PHP block until the next ?>
while($result=mysqli_fetch_array($resource)){
echo "<tr>
<td>".$result[0]."</td>
<td>".$result[1]."</td>
<td>".$result[2]."</td>
<td>".$result[3]."</td>
<td>".$result[4]."</td>
<td>".$result[5]."</td>
<td>".$result[6]."</td>
<td><a href='changetask1.php?username=".$user."'></td>
</tr>";
}
?>
</table>
</font>
To avoid these problems of double and single quote you can write your code like following.
<td><a href="cheangetask1.php?username=<?php echo $user;?>"></td>
Now on the changetask1.php you can get username like this.
<?php echo $_REQUEST['username'];?>
Related
I could use some help here, because I cannot figure out how to echo a php row (a URL) as a link to an image.
This is the code I already have
echo"<table border=1>
<tr>
<th width=80px>Release</th>
<th width=250px>Title</th>
<th width=200px>Genre</th>
<th width=200px>Developer</th>
<th width=200px>Publisher</th>
<th width=100px>Links</th>
</tr>";
while($row=mysqli_fetch_assoc($result))
{
echo"
<tr>
<td>{$row['game_release']}</td>
<td>{$row['game_name']}</td>
<td>";
$query="SELECT * FROM genre WHERE genre_id=".$row['game_genrea'];
$genrearesult=mysqli_query($link,$query); $genrearow=mysqli_fetch_assoc($genrearesult);
echo $genrearow['genre_name'];
echo "</td>
<td>{$row['game_dev']}</td>
<td>{$row['game_pub']}</td>
<td>{$row['game_site']}</td>
</tr>";
}
echo"</table>";
The last tabel data ($row['game_site']} echoes the URL right now, but I would like to have an image appear(ie a browser icon) that links to to the echoed website and which is saved in my images folder. Is that possible? I tried different syntaxes, but nothing seems to work.
The data being executed is a url, you will have to use some html to make it the href of an anchor tag and then provide an image inside the anchor tag to get what you want.
<td><img src=\"IMAGE_URL_GOES_HERE\" /></td>
Something like this should work:
echo "<td><a href='".$row['game_site']."'> <img src='image.gif'/></a></td>";
note the "a" tag with href
I have the following scenario. MySQL database and PHP page that get a set of user data from the database and displays them in a table. The code works fine and it is as follows:
<form id="iform" name="iform" method="post" action="<?php echo $_SERVER['SCRIPT_NAME'];?>">
<table class="tabcont" width="100%" valign="center" border="0" cellpadding="0" cellspacing="0" summary="main area">
<tr><td align="center" class="listlr" colspan="2">
</td></tr>
<tr><td align="center" class="listlr" colspan="2">
</td></tr>
<?php if (is_array($result) && count($result) > 0):
foreach ($result as $reskey => $resvalue) {
echo "<tr><td width='30%'>{$reskey}:</td>";
echo "<td width='70%'>";
if ($reskey == 'PortraitImage')
echo "<img id='{$reskey}' src='{$resvalue}' value=''/>";
else if ($reskey == 'SignatureImage')
echo "<img id='{$reskey}' src='{$resvalue}' value=''/>";
else
echo "<input class='formfld' id='{$reskey}' value='{$resvalue}'/>";
echo "</td></tr>";
}
else: ?>
<tr> <td>
<?php
echo "<div align=\"center\" class=\"listtopic\" id=\"iderror\">{$errormsg}</div>";
?>
</td>
</tr>
<?php endif; ?>
</table>
</</form>
What I need to do now is to display the data arranged in another way, in a html table like the one attached (which will have a background image but that's easyly implemented via css). The table needs to be in this format:
HTML Table
I am trying to modify the above code but can't seem to get it right in this table format.
I can certainly display it fine as it is in the above code or in a simple table, but it gets all messed up when I try to display the data in the above table format. Any suggestions based on the above code? Thanks.
So I have problem with firefox not showing results of search form for query i enter, but code is working normally in Opera,Chrome,IE and Android default browser.
This is the search form :
<div id="menu_right">
<div id="searchBar">
<form id='search_form' method='POST' action='index.php?menu=search'>
<input id="topSearchText" class="inputText" type="text" name="movie" size="30" onfocus="this.value=''" value="Search" style="color: rgb(119, 119, 119);"/>
<input type="image" name="search_movies" value="Search" src="./images/search.png"/>
</form>
</div>
and this is the php part of the code:
<table width='100%' cellspacing='0' cellpadding='0' border='0'>
<tbody>
<tr>
<td class='normal_header' colspan='2'>Search Results</td>
<td class='normal_header' width='40' align='center' nowrap=''>Score</td>
</tr>
<?php
if(isset($_POST['search_movies']))
{
$movie=$tmdb->searchMovie($_POST['movie']);
foreach ($movie['results'] as $value) {
$filepath = $value['poster_path'];
$image_url = $tmdb->getImageUrl($filepath, TMDb::IMAGE_POSTER, 'w92');
echo "
<tr>
<td class='borderClass bgColor' width='50' valign='top'>
<div class='picSurround'>
<a href='http://www.themoviedb.org/movie/{$value['id']}'>
<img border='0' src='{$image_url}'>
</a>
</div>
</td>
<td class='borderClass bgColor' valign='top'>
<a href='http://www.themoviedb.org/movie/{$value['id']} '>
<strong>{$value['title']}</strong>
</a>
<a class='button_add' title='Quick add movie to my list' href='addmovie.php?id={$value['id']}'>add</a>
<div class='spaceit'>
<a href='http://www.themoviedb.org/movie/{$value['id']}'>Read more about: {$value['title']}</a>
</div>
</td>
<td class='borderClass bgColor' align='center'>{$value['vote_average']}</td>
</tr>";
}
}
?>
</tbody>
Is it something wrong with my query or maybe some tag because I cant seem to find the problem.
Have you checked the error_log that was possibly created?
Also.. and I might be wrong here.. but as far as I know php only interprets code between double quotes "", not between single quotes ''.
So for instance:
$test = 5;
echo "this string shows the value of $test"
echo 'this string just shows the string $test';
If this is a search form based on the results of the input field then it should be;
isset($_POST['movie'])
Look at this question :
HTML Input (type=image) not working on Firefox 4
Maybe your problem comes from the way firefox handles image's input tag.
Edit : More infos in the accepted answer to this question : Code working in Chrome but not in Firefox
This seem to be a common "problem" with image-type inputs.
My code
<?php
include('ConnectToDb.php');
$query = "SELECT * FROM News WHERE NewsFlag = 1 ORDER BY PostDate DESC";
$arrCount = -1;
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
$ID=$row['ID'];
$PostDate = $row['PostDate'];
$NewsHeader = stripslashes($row['NewsHeader'])
;
$NewsStart = stripslashes($row['NewsStart'])
;
echo "<hr>";
echo "<div>". date('j F Y',strtotime($PostDate)). "</div>";
echo "<p>";
$news_id = strval(sprintf("%1$04d",$ID));
$array = scanImageFolder("newsImages/newsThumbs",$news_id);
if(count($array)>0) {
echo "<img src='". $array[0]. "' alt='' />";
}
echo "<h2 style='text-align:center'><u><a href='latestnews_full.php?ID=$ID'>". $NewsHeader. "</a></u></h2>";
echo "<div style='text-align:left'><h3>";
echo $NewsStart. " ......<a href='latestnews_full.php?ID=$ID'>(more)</a><br />";
echo "<div style='text-align:center'>";
echo "</div>";
echo "</h3></div>";
}
?>
displays my data nicely on four lines with date at the top, then a picture, title and then description.
However, I want to display the data as a table like this
<table style="width: 100%">
<tr>
<td colspan="2">postDate here</td>
</tr>
<tr>
<td rowspan="2">picture here</td>
<td>newsHeader here</td>
</tr>
<tr>
<td>newsStart here</td>
</tr>
</table>
I'm not sure how to echo the table cells correctly and all of my attempts so far have resulted in a white page. Could anyone please enlighten me?
I'd suggest you to make your logic separated from your presentable part. Close the PHP tag once you are ready fetching the results, assigning var's etc, then:
<table style="width: 100%">
<?php
//yourcode
//...
//...
$NewsStart = stripslashes($row['NewsStart']);
$news_id = strval(sprintf("%1$04d",$ID));
$array = scanImageFolder("newsImages/newsThumbs",$news_id);
?>
<tr>
<td colspan="2"><?= date('j F Y',strtotime($PostDate)) ?></td>
</tr>
<tr>
<?php
if(count($array)>0) {
?>
<td rowspan="2"><img src='<?= $array[0] ?>' alt='' /></td>
<?php } ?>
<td><?= $NewsHeader ?></td>
</tr>
<tr>
<td><?= $NewsStart ?> </td>
</tr>
<?php } ?>
</table>
However, it's again not so clear, and I would suggest using a template engine. If you want I can post a code with assigning vars to Smarty and output your presentation in Smarty template
I have a HTML content in a variable like this.
$message ="<div>
<table align='center'>
<tr><td><h1>Reporte de Tipo de Documentos</h1></td></tr>
<tr><td><h2>Farmaceutica MDC</h2></td></tr>
</table>
</div>
<div>
<table style='width:960px; margin:0 auto;'>
<tr colspan='7'>
<td><?php echo 'Fecha: '".$time = date('d/m/Y h:i:s A')."; ?></td>
</tr>
<tr bgcolor='#CCCCCC' height='30'>
<td><b>Sr. No.</b></td>
<td><b>Tipo Documento</b></td>
<td><b>Cant. Pasos</b></td>
<td><b>Costo</b></td>
<td><b>Precio</b></td>
<td><b>Balance</b></td>
<td><b>Notifica Cliente</b></td>
</tr>
</table>";
I want to print a printout page of this HTML Content.
Like for web page we use
<script type="text/javascript">
function printpage()
{
window.print();
}
</script>.
So what i use to print the above HTML content?
How about embedding the contents of this page in HTML and adding a script to print it out automatically on page load?
<?php
$message ="<div>
<table align='center'>
<tr><td><h1>Reporte de Tipo de Documentos</h1></td></tr>
<tr><td><h2>Farmaceutica MDC</h2></td></tr>
</table>
</div>
<div>
<table style='width:960px; margin:0 auto;'>
<tr colspan='7'>
<td><?php echo 'Fecha: '".$time = date('d/m/Y h:i:s A')."; ?></td>
</tr>
<tr bgcolor='#CCCCCC' height='30'>
<td><b>Sr. No.</b></td>
<td><b>Tipo Documento</b></td>
<td><b>Cant. Pasos</b></td>
<td><b>Costo</b></td>
<td><b>Precio</b></td>
<td><b>Balance</b></td>
<td><b>Notifica Cliente</b></td>
</tr>
</table>";
echo "<html><head></head><body>" . $message . "<script type='application/javascript'>window.onload=function(){window.print()}</script></body></html>";
?>
To literally print the HTML code, you can sanitize the HTML like:
echo "<html><head></head><body>" . htmlspecialchars($message, ENT_QUOTES) . "<script type='application/javascript'>window.onload=function(){window.print()}</script></body></html>";
?>
More information about this:
What's the best method for sanitizing user input with PHP?
Sanitizing HTML input
PHP HTML sanitizer
http://se2.php.net/manual/en/function.htmlspecialchars.php
<input type="submit" value="Print" onclick="printIframe(report);"/>
<script>
function printIframe(objFrame) {
objFrame.focus();
objFrame.print();
bjFrame.save();
}
</script>
<iframe name="report" id="report" src="report.php"></iframe>
try calling the form inside an iframe then a link or button that will run the js to print the html/php inside the iframe..