How to print Table of this format [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have following data in mysql, and I want to echo in this format:
Data:
Name,Image URL,Link
I want to print it dynamically like this : http://screensaver.cf/screensavers.php
I don't know user's screen width, still I want it to appear as much as possible in width.
How can I do this in html and PHP?
My code:
<?php
require("config.php");
?>
<div id="main-wrap">
<div class="container">
<div id="main">
<div id="content"><div id='wsite-content' class='wsite-elements wsite-not-footer'>
<div class="paragraph" style="text-align:left;">
<?php
$sql='SELECT * FROM `games` where 1=1';
$data = mysql_query($sql);
echo '<h4 class="result">Result:</h4>';
while($row = mysql_fetch_row($data)){
$table=WHAT TO DO HERE TO MAKE IT LOOK LIKE THAT???????
echo $table;
echo '<br><br>';
}
?>
</div>
</div>
</div>
</div>
</div>
<?php
include("footer.php");
?>
P.S I know mysql is depreciated and I am constantly working to learn Mysqli, as I am in 8th class, I don't have much time.

<style>.a{float:left;}
</style>
>
in while loop use this
<div class = "a">
<?php <img src='".$row['url']."' width='140' height='140'> ?>
</div>

Related

how to search for something in a database and display it? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I tried this code for displaying an item name, price and a photo from database for searching an item name in a search bar
<?php
try
{
require('connection.php');
$sql2="SELECT * FROM items
where item.item_name like '".$txt1."%'
$result2=$db->query($sql2);
if ($result2->rowCount()!=0) {
foreach ($result2 as $r2) { ?>
<a href="images/<?php echo $r2['item_photo'] ?>" class="fh5co-card-item image-popup">
<figure>
<div class="overlay"><i class="ti-plus"></i></div>
<img src="images/<?php echo $r2['item_photo']?>" alt="Image" class="img-responsive">
</figure>
<div>
<?php echo "<p><span class='price kk'>" ; ?>
<p style="font-family:'georgia';text-align:center;font-size:20px;color:black;"><?php echo ($r2['item_name']); ?></span></p>
<h2 style="font-family:'georgia';text-align:center;font-size:18px;color:grey;"><?php echo ("BD ".$r2['item_price']); ?></h2>
</div>
<?php }
} ?>
The problem is the sql, There is an extra name after where
$sql2="SELECT * FROM items
where item.item_name like '".$txt1."%' ;
There should be only item_name not item.item_name. Change this as:
$sql2="SELECT * FROM items
where item_name like '".$txt1."%';
And your code may be exploited with sql injection. Be carefull for production use this code.

How can I download a image file to my local system using php [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am having multiple images, for that individual image i am having download button
<div>
<?php
for($a=0;$a<5;$a++) { ?>
<img src='image_<? echo $a;?>.jpg'/>
<button id='dwn_<? echo $a;?>'>Download</button>
<br>
<? } ?>
</div>
If i click that download button i need to save that corresponding image to my local system.
Kindly give some solution for this.
the easiest way without javascript i think it would ( I edited your code, but i cant try it now)
<div>
<?php
for($a=0;$a<5;$a++) { ?>
<img src='image_<? echo $a;?>.jpg'/>
<form method="get" action='image_<? echo $a;?>.jpg'>
<button id='dwn_<? echo $a;?>' type="submit">Download</button>
</form>
<br>
<? } ?>
</div>
You can delete the id in button if you only use for download
download.php
.........
<?php
if(isset($_REQUEST) && ($_REQUEST['image_name'])){
$filename = $_REQUEST['image_name'].'.jpg';
// Write download code here
}
display_page.php
............
<div>
<?php
for($a=0;$a<5;$a++) { ?>
<img src='image_<? echo $a;?>.jpg'/>
<a href="download.php?image_name=<?php echo $a; ?>" >Download</a>
<br>
<? } ?>
</div>
Most easiest way by using html 5
<div>
<?php
for($a=0;$a<5;$a++) { ?>
<img src='image_<? echo $a;?>.jpg'/>
<a href='image_<? echo $a;?>.jpg' download>
<span id='dwn_<? echo $a;?>'>Download</span >
</a>
<br>
<? } ?>
</div>

pull Else if from SQL [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need the data to have a different style if the sold = 0 in the mysql table
and when i use the code below the website shows a blank white page
(?=$vehicle-> this is the vehicle reference
and sold is the column withing the sql table
<?php
if (?=$vehicle->sold?!= 1)
{
<div class="foo">
<div class="fboverlay"></div>
<a>
<img src="/media.php?productId=<?=$vehicle->vehicle_id?>&file=<?=$vehicle->main_image?>" />
</a>
</div>
}
else {
<img src="/media.php?productId=<?=$vehicle->vehicle_id?>&file=<?=$vehicle->main_image?>" />
}
?>
You need to learn the PHP from the basics. Learn about operators, PHP and HTML secion, etc..
Anyway, i fixed your code. The condition is if $vehicle->sold is not equal to 1. But i think, (in your OP you mentioned it should be 0) you want this: $vehicle->sold == 0
//Use sytnax like this. See php opeartors.
if ($vehicle->sold != 1) {
?> <!-- Close the php -->
<div class = "foo">
<div class = "fboverlay"></div>
<img src = "/media.php?productId=<?= $vehicle->vehicle_id ?>&file=<?= $vehicle->main_image ?>" />
</div>
<?php
//Open the php again
} else {
?> <!-- close the php -->
<img src = "/media.php?productId=<?= $vehicle->vehicle_id ?>&file=<?= $vehicle->main_image ?>" />
<?php //Open again
}

Selecting php out with JQuery [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
This is a code snippet I have and I would like to be able to select the out of PHP. When I try to grab the PHP output and store it into a variable, I receive "undefined".
<h1 id=<?php echo '$test; ?> class="list-name--original">
My last attempt I tried this code:$("h1.list-name--original")[0].outerHTML);
Why not just put all your PHP output in a variable
<script>
var data = '<?=$test?>';
</script>
You can then set the contents of an H1 tag like this
<h1 id="myid"></h1>
<script>
$('h1#myid').text(data);
</script>
Try
<h1 id="<?php echo $test; ?>" class="list-name--original">
in jQuery
$(".list-name--original").html();
or
$("#<?= $test ?>").html();
Try this:
<?php $test = "Hello world!"; ?>
<h1 id="example" class="list-name--original"><?php echo $test; ?></h1>
<script language="javascript">
$("#example").html();
</script>

How do I write this html as php [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
All of this needs to be inside my loop so I don't know if I can break it (don't think I can) but I need PHP to read it as HTML.
$movieDetails =
<header class="masthead" role="banner">
<div class="logo-container">
<a class="logo" href="">Movie Details</a>
</div>
</header>
<div class="bubble-container">
<div class="speech-bubble speech-bubble-top">
Text that goes into the bubble
</div>
</div>
You can just close your PHP tag to render text that will display as HTML.
<?php
foreach($movies as $movie) {
?>
<div>
<?php echo htmlspecialchars($movie); ?>
</div>
<?php
}
?>
$movieDetails = <<<HTML
<header class="masthead" role="banner">
<div class="logo-container">
<a class="logo" href="">Movie Details</a>
</div>
</header>
<div class="bubble-container">
<div class="speech-bubble speech-bubble-top">
Text that goes into the bubble
</div>
</div>
HTML;
echo $movieDetails;
http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

Categories