How to add height and width in a PHP script? - php

I have the following line. It works fine but I want to add height and width to the image. How?
echo "<td>" . "<img src='img/" .$row['Foto'] . "'>" . "</td>";

You can use style attribute :
echo "<td>" . "<img style = 'width:?;height:?' src = 'img/" .$row['Foto'] . "'>" . "</td>";
or width and height attributes :
echo "<td>" . "<img width = '?' height = '?' src = 'img/" .$row['Foto'] . "'>" . "</td>";

Related

PHP glob() Loop stops after a certain number of loops

I have a script that reads multiple XML files, takes data from them and lists it as HTML.
Here's the short version of the script (Slightly adjusted because of language and XML contents.):
<?php
$files = glob("./PDFs/*xml");
foreach($files as $filename) {
$xml=simplexml_load_file($filename) or die("Error: Cannot create object");
foreach($xml->xml->rechnung_list->rechnung as $data) {
$belegnr = $data->belegnr;
$file = glob("*" . "$belegnr.pdf");
echo '<tr>';
echo "<td>" . $data->auftrag . "</td>";
echo "<td>" . $data->belegnr . "</td>";
echo "<td>" . $data->kundennummer . "</td>";
echo "<td>" . $data->name . "</td>";
echo "<td>" . date("d. m Y" , strtotime($data->datum)) . "</td>";
echo "<td>" . "<a href='" . $file[0] . "'>DOWNLOAD</a>" . "</td>";
echo '</tr>';
}
}
?>
This code works and does exactly what I want, however it stops after a certain number of iterations.
My PHP memory_limit is set to 512M and the whole thing loads in about 30s so I don't feel like there should be a timeout.

How can i put an href link in my foreach statement?

For starters i am fairly new at this.
I am trying to figure out how to a href link my row 'inspection_files' and i have tried just about everything. Is there anybody who could help me?
<?php
$i = 0;
foreach ($result as $r) {
echo "<tr>";
echo "<td>" . $r['last_inspection'] . "</td><td>" . strtolower(trim(($r['inspected_by_company']))) . "</td><td>" . strtolower(trim($r['inspection_files'])) . "</td>";
echo "</tr>";
$i++;
}
?>
Hey you can directly use <a> tag inside the <td>, just like below
echo "<td>" . $r['last_inspection'] . "</td><td>" . strtolower(trim(($r['inspected_by_company']))) . "</td><td><a href='" . strtolower(trim($r['inspection_files'])) . "'>" . strtolower(trim($r['inspection_files'])) . "</a></td>";
I hope $r['inspection_files'] this is your URL if this is not your redirect URL then just replace with your actual URL.

Appending a character to a PHP output

I have a simple question.
echo "<tr>";
echo "<td>" . $row['Rep'] . "</td>";
echo "</tr>";
Assume that the above snippet outputs "1". How can I append a dot . in front of it in the above code? So that the output will be .1 instead of 1 only. I couldn't find a similar example on the web, so I decided to ask here. Thanks!
echo "<tr>";
echo "<td>" . "." . $row['Rep'] . "</td>";
echo "</tr>";
or in case it's not 1
echo "<tr>";
echo "<td>" . ($row['Rep'] == 1 ? "." . $row['Rep'] : $row['Rep']) . "</td>";
echo "</tr>";
Like
echo '<tr><td>.' . $row['Rep'] . '</td></tr>';

php increment variable with onclick

I want to use the function onclick to increment a variable [increment the variable paid]
paid is by default at 0 i want to increment at 1.
I try this code : onclick='paid++' but is not working...
My Code
foreach($query as $index=>$row) {
echo ($colorCount++%2) ? "<tr class='alt'>" : "<tr>";
echo "<td class='" . getPaidColor($row['paid']) . "' onclick='paid++ '></td>";
echo "<td class='" . getDelayColor($row['hour']) . "' onclick='postDeleteForm(" . $index . ")'></td>";
foreach($columns as $column) {
echo "<td>" . $row[$column] . "</td>";
}
}

Stop table from being generated IF less then X

I have a table that is generated upon REST API, I generate for the first 50 in the result. My issue is if the response from REST is less then 50 the table still make the table for 50, just with empty rows on the X amounts that is not available in the response.
So e.g I get result of 47 , then my code generates for 50 still only so last three rows is empty. How do I avoid this ?
for($x=0;$x<50;$x++)
echo "<table><tr><td>" . "<img style='width:200px; height:150px;' src='" . $imagehost . $newImgUrl = preg_replace($pattern, $replacement, $hotelSummary[$x]['thumbNailUrl']) . "'/>" . "</td><td>" . $hotelSummary[$x]['name'] . "</td><td>" . $hotelSummary[$x]['hotelId'] . "</td><td>" . $hotelSummary[$x]['city'] . "</td><td>" . $hotelSummary[$x]['RoomRateDetailsList']['RoomRateDetails']['RateInfos']['RateInfo']['ChargeableRateInfo']['#total'] . "</td><td><button type='button'>Hotel Info</button><td><a href='" . $hotelSummary[$x]['deepLink'] . "' ><button type='button'>Book Now</button></a></td></tr></table>";
So if the response is less then 50 only create for the x amount found, and if the amount is less then 1 echo out e.g No results matches your search.
Can I implement an if sentence in this or how should I do this ?
Don't compare
$x<50
but
$x < $responseFromRest && $x < 50
You could add an if to check to see if the sizeof your response is bigger than $x, if so, echo your line else break. Example:
$reponse = $data;
for($x=0;$x<50;$x++) {
if($x > sizeof($respnse)) {
break;
}
echo "<table><tr><td>" . "<img style='width:200px; height:150px;' src='" . $imagehost . $newImgUrl = preg_replace($pattern, $replacement, $hotelSummary[$x]['thumbNailUrl']) . "'/>" . "</td><td>" . $hotelSummary[$x]['name'] . "</td><td>" . $hotelSummary[$x]['hotelId'] . "</td><td>" . $hotelSummary[$x]['city'] . "</td><td>" . $hotelSummary[$x]['RoomRateDetailsList']['RoomRateDetails']['RateInfos']['RateInfo']['ChargeableRateInfo']['#total'] . "</td><td><button type='button'>Hotel Info</button><td><a href='" . $hotelSummary[$x]['deepLink'] . "' ><button type='button'>Book Now</button></a></td></tr></table>";
}

Categories