This question already has answers here:
How to pass multiple parameters in a querystring
(7 answers)
Closed 1 year ago.
I'm carrying one variable in "reserva" wich I later I use $_GET('reserva'), but I also need another one of the rows,how could I do it?
<?php
while($row = mysqli_fetch_array($search_result)):?>
<tr>
<td><?php echo $row['idps'];?></td>
<td><?php echo $row['Descrição'];?></td>
<td><?php echo $row['dia'];?></td>
<td><?php echo $row['dataini'];?></td>
<td><?php echo $row['datafim'];?></td>
<td><?php echo $row['tblstaff_idPrestador'];?></td>
<td><a href='marcar.php?reserva=<?php echo $row['idps'];?>'>Marcar</a></td>
</tr>
<?php endwhile;?>
Yes, you can append multiple values in a GET request using &:
<a href='marcar.php?reserva=<?php echo $row['idps'];?>&key=value'>Marcar</a>
^^^^^^^^^^
as #raina77ow pointed out, be aware that & is a "reserved" char, so if your string contains that, you have to encode it, and for that, in PHP you have the function urlencode
Related
This will in this case echo multiple authors, release dates, and covers for a book on a single page.
My question is: How do I make it look nice with a table, and my CSS file? I just can't get it right, kinda almost made it work once, but it showed just the one book and then started on a new row, and I want at least 4 books/row, and the borders were completely off.
Really silly question I know, and I've tried googling and experimenting but I'm having serious trouble making it really work.
Also, if I want to echo a variable ($genre) in a link-text, say
Home > Books > CurrentGenreVariable($genre)
how'd I do that neatly? I need a slight kick-start, that's all I think.
Thanks in advance.
You follow the generic looping patterns. I presume you're doing this with a while() loop?
<table>
<?php while ($row = FETCH_THE_DATA): ?>
<tr>
<td><?php echo $row['author']; ?></td>
<td><?php echo $row['date']; ?></td>
<td><?php echo $row['cover']; ?></td>
</tr>
<?php endwhile; ?>
</table>
I've got a table which outputs two mySQL records, one original and one which has been edited and flagged for approval/disapproval by the admin. I want to change the column color to highlight rows which have been edited.
The color highlight on changed rows works for all rows except "SalaryFrom" and "Email", for some reason they are always highlighted as different even when the values appear to be completely identical.
Is there any function in PHP which highlights the difference between two strings so I can figure out where the difference is?
Here's my code for one row:
<tr>
<?php
if (htmlval($cand['salaryfrom'])!==htmlval($flaggedcand['salaryfrom']))
{
$tcolor="#000000";
}
else
{
$tcolor="#D3D5E8";
}
?>
<td bgcolor=<?php echo $tcolor ;?>><b>Salary from</b></td>
<td><?php htmlout($flaggedcand['salaryfrom']." "); ?></td>
</tr>
function htmlval($text)
{
return html_entity_decode($text, ENT_QUOTES);
}
Use this
<?php
if ( $cand['salaryfrom'] != $flaggedcand['salaryfrom'] ) $tcolor ="#000000";
else $tcolor="#D3D5E8";
?>
<td style="background: <?php echo $tcolor; ?>;"><b>Salary from</b></td>
<td><?php echo $flaggedcand['salaryfrom'] ." "; ?></td>
There are several reasons why your strings may look the same but they aren't for real. Example: Maybe you need to trim heading and trailing space like this :
function htmlval($text)
{
return trim(html_entity_decode($text, ENT_QUOTES));
}
There are a couple of classes, lib, or self-made function to highlight two strings differences (not in core php) but in your case it might be just enought to output explicitly string 1 and then string 2 so that you can spot the differences by yourself like this :
<tr>
<?php
if (htmlval($cand['salaryfrom'])!==htmlval($flaggedcand['salaryfrom']))
{
$tcolor="#000000";
ob_start();
var_dump(htmlval($cand['salaryfrom']));
echo " is not equal to ";
var_dump(htmlval($flaggedcand['salaryfrom']));
$out = ob_get_clean();
}
else
{
$tcolor="#D3D5E8";
$out = $flaggedcand['salaryfrom'];
}
?>
<td bgcolor=<?php echo $tcolor ;?>><b>Salary from</b></td>
<td><?php htmlout($out." "); ?></td>
</tr>
This question already has answers here:
How do I access this object property with an illegal name?
(2 answers)
Closed 9 years ago.
So I'm writing a php project and I got stuck on hyphens in column names of a table in a database.
I have the following code:
$results = $conn->query($sql)->fetchAll(PDO::FETCH_OBJ);
foreach ($results as $row) { ?>
<tr>
<td><?= $row->factuur-status ?></td>
<td><?= $row->verkoop-orderid ?></td>
</tr>
<?php } ?>
Now obviously because of the hyphens in the column names this doesn't work.
How can one fix this?
I found it, if someone's interested:
<?= $row->{'factuur-status'} ?>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am so new to PHP, now i am trying to print the not null values. I have following php code which throws me all values including null and not nulls. In my website I need only not null values.
<tr>
<td><?php echo $stock['stsymbol']?><td>
<td><?php echo $stock['noshares']?><td>
<td><?php echo $stock['purchaseprice']?><td>
<td><?php echo $stock['datepurchased']?><td>
<td><?php echo $stock['Original Value']?><td>
<td><?php echo $stock['Current Price']?><td>
<td><?php echo $stock['Current Value']?><td>
</tr>
<?php } // end foreach ?>
change the all td like this example :
<?php if(!is_null($stock['stsymbol'])){ ?>
<td><?php echo $stock['stsymbol']; ?><td>
<?php } ?>
try using this
<td><?php if(!empty($stock['stsymbol'])){ echo $stock['stsymbol']; }?><td>
php has is_null clearly for situation like this. use
if (!is_null($varname)) echo $varname;
The basic pattern you want to follow to conditionally print a value is
<?php
if (!empty($stock['stsymbol'])) {
echo $stock['stsymbol'];
}
?>
This can be shortened by using a ternary if
<?php echo (!empty($stock["stsymbol"]))?$stock["stsymbol"]:"" ?>
UPDATE
Much discussion has gone on in the comments regarding the mechanism used to test for a null value. I thought it might be good to recap the merits of each.
is_null - returns true if the variable is strictly null or undefined (will issue a notice if it is undefined)
empty - returns true if the variable is falsy or undefined (will not issue a notice)
!$val - same as empty but with a notice with undefined values.
You can avoid the problem altogether and use another foreach loop in your current foreach.
It goes like this:
foreach ($stock as $key=>$value) {
echo "<td>$value</td>";
}
Im looking for help with this. I've tried unset and other options and nothing seems to be working. I hate to bother people but ive searched google till the cows come home and im doing it wrong.
Here is my code:
<?php
$orderArray = $_SESSION['orderVal'];
foreach($orderArray as $orderVal)
{
$valInvent = getOrderInventories($orderVal['invId']);?>
<tr><td><?php echo $valInvent['itemnumber'];?></td>
<td><?php echo $valInvent['description'];?></td>
<td><?php echo $valInvent['cp'];?></td>
<td><?php echo $orderVal['price'];?></td>
<td><?php echo $orderVal['qty'];?></td>
<td></td>
</td>
I want to remove an item from this array using one of the variables.
This should work.
I am using
unset($valInvent['itemnumber']);