I upload some image to phpMyAdmin, and write some code on Dreamweaver.
Then got this:
The code is on below:
<?php
require_once("connection.php");
$result = mysql_query("SELECT * FROM food");
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Food & Beverages</title>
</head>
<body>
<form>
<table width="400" border="1">
<tbody>
<?php
while($row = mysql_fetch_assoc($result)){
?>
<tr>
<td width="240" height="130"><img src="<?php echo $row['image']?>"></td>
<td><?php echo $row['info'];?></td>
</tr>
<?php }?>
</tbody>
</table>
</form>
</body>
</html>
How to solve this problem?
Related
How would I be able to make a table from php using html with a foreach loop?
My goal is to have a table with href tags for each of the sites. It's just that I'm a newbie to php
<?php
$baseConf = ['site' => [abc.com],[abc.org]];
?>
<!DOCTYPE html>
<html>
<head>
<title>Default Page</title>
</head>
<body>
<table>
<!--<?php //$site; ?>-->
<?php
foreach($site as $value ) {
printf $value;
}
?>
</table>
</body>
</html>
You can use a simple foreach loop to put <a> tag with href in table.
<table>
<?php
$sites=$baseConf['site'];
foreach($sites as $item) {
?>
<tr>
<td>
<a href="<?= $item ?>">
<?=$item?>
</a>
</td>
</tr>
<?php
}
?>
</table>
It is very simple for loop and you can grab it from SO. Still I am solving it for you.
I assume you have a multidimensional array. Let's simplify it.
$baseConf = ['site' => [example.com],[example.org]];
$sites = $baseConf['site']; // we will loop sites now
Now Use the html like this
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Links</th>
</tr>
</thead>
<tbody>
<?php for ($i = 0; $i < count($site); $i++){?>
<tr>
<th scope="row"><?php echo $i?></th>
<td><?php echo $site[$i]?></td>
</tr>
<?php}?>
</tbody>
</table>
I have fixed my code a bit and this is what worked out:
$baseConf = array(
'site' => array("abc.com","abc.org"),
);
?>
<!DOCTYPE html>
<html>
<head>
<title>Default Page</title>
</head>
<body>
<!--<?php //$site; ?>-->
<?php
foreach ($baseConf as $value) {
//echo "$value\n";
print_r($value);
}
?>
</body>
</html>
I had this project wherein, I am supposed to insert and select pictures, as in upload and view them. Initially, when I tried a code, it worked but the image didn't display. After many trials, I just copied a code from a mate which worked for him but when I tried, it didn't. Why? I have posted everything below-
Image upload code
<head>
<title>Retrieve Image</title>
</head>
<body>
<h1>Retrieving Image from database using PHP</h1>
<table border="1px" >
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Image</th>
</tr>
</thead>
<?php
$connection = mysqli_connect("localhost","root","");
$db = mysqli_select_db($connection,"olap");
$query = "SELECT * FROM `blobclob`";
$query_run = mysqli_query($connection,$query);
while($row = mysqli_fetch_array($query_run))
{
?>
<tr>
<td> <?php echo $row['id']; ?></td>
<td> <?php echo $row['name']; ?></td>
<td> <?php echo '<img
src="data:image;base64,'.base64_encode($row['image']).' " alt="FlowerImage"
style="width:100px; height:100px;">'; ?></td>
</tr>
<?php
}
?>
</table>
</body>
</html>
Image View Code
<html>
<head>
<title>Retrieve Image</title>
</head>
<body>
<h1>Retrieving Image from database using PHP</h1>
<table border="1px" >
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Image</th>
</tr>
</thead>
<?php
$connection = mysqli_connect("localhost","root","");
$db = mysqli_select_db($connection,"olap_exp");
$query = "SELECT * FROM `images`";
$query_run = mysqli_query($connection,$query);
while($row = mysqli_fetch_array($query_run))
{
?>
<tr>
<td> <?php echo $row['id']; ?></td>
<td> <?php echo $row['name']; ?></td>
<td> <?php echo '<img
src="data:image;base64,'.base64_encode($row['image']).' " alt="FlowerImage"
style="width:100px; height:100px;">'; ?></td>
</tr>
<?php
}
?>
</table>
</body>
</html>
Output
Database
it should be something like this
echo '<img src="data:image/jpeg;base64,'.base64_encode($row['image']).'"/>';
it should be **src="data:image/jpeg;base64 ... ** instead of src="data:image..
Im trying to finish a upload tool which can open a json file and show it in a table. The script i posted below (basis.php) is already working properly.
basis.php
$data = file_get_contents("data.json"); // put the contents of the file into a variable
$characters = json_decode($data); // decode the JSON feed
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css/pure-min.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<table class="pure-table">
<thead>
<tr>
<th>Tijdstempel</th>
<th>Voornaam</th>
<th >NHL E-mailadres</th>
<th>Geboortejaar</th>
<th>Kwaliteit</th>
<th>Moeilijkheidsniveau</th>
<th>Gegevenscontrole</th>
</tr>
</thead>
<?php foreach ($characters as $character) : ?>
<tbody>
<tr >
<td> <?php echo $character->Tijdstempel; ?> </td>
<td> <?php echo $character->Voornaam; ?> </td>
<td> <?php echo $character->Email; ?> </td>
<td> <?php echo $character->Geboortejaar; ?> </td>
<td> <?php echo $character->Kwaliteit; ?> </td>
<td> <?php echo $character->Moeilijkheidsniveau; ?> </td>
<td> <?php echo $character->Gegevenscontrole; ?> </td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</body>
</html>
Now here comes the problem, I am trying to change the basis.php and adapt it to the following index.php. This way I want to be able to upload a suitable json file instead.
index.php
<!doctype html>
<html lang="nl">
<head>
<meta charset=utf-8>
<title>Basisformulier voor het uploaden van een bestand</title>
</head>
<body>
<h1>Excel bestanden importeren en exporteren</h1>
<form action="basis.php" method="post" enctype="multipart/form-data">
<label for="frm_importfile">Selecteer het bestand:</label>
<input type="file" name="importfile" id="frm_importfile">
<button type="submit">Upload het bestand</button>
</form>
</body>
So I tryed to change the basis.php in this way:
basis.php(not working)
<?php
if(!isset($_FILES['importfile'])){
echo "FOUT: Je hebt geen bestand geselecteerd om te uploaden";
exit;
}
$data = fopen($_FILES['importfile']['tmp_name'], "r");
$characters = json_decode($data); // decode the JSON feed
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css/pure-min.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<table class="pure-table">
<thead>
<tr>
<th>Tijdstempel</th>
<th>Voornaam</th>
<th >NHL E-mailadres</th>
<th>Geboortejaar</th>
<th>Kwaliteit</th>
<th>Moeilijkheidsniveau</th>
<th>Gegevenscontrole</th>
</tr>
</thead>
<?php foreach ($characters as $character) : ?>
<tbody>
<tr >
<td> <?php echo $character->Tijdstempel; ?> </td>
<td> <?php echo $character->Voornaam; ?> </td>
<td> <?php echo $character->Email; ?> </td>
<td> <?php echo $character->Geboortejaar; ?> </td>
<td> <?php echo $character->Kwaliteit; ?> </td>
<td> <?php echo $character->Moeilijkheidsniveau; ?> </td>
<td> <?php echo $character->Gegevenscontrole; ?> </td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</body>
</html>
I have been searching for solutions for a long while on the internet but I still cant get the problem solved. I hope that someone can help me and show me how I can make it possible to upload a json file to the basis.php.
Kind Regards,
Sierra
You open the file but you didn't read any data from it.
A simple method to get the contents of a file is file_get_contents
$data = file_get_contents($_FILES['importfile']['tmp_name']);
Did you try
$data = file_get_contents($_FILES['importfile']['tmp_name']);
I have the following code, and the tutorial I followed says that the table should show up, but it doesn't. All that shows up is the text inside the <h1> and <h4> tags, and the external CSS file is also not taking effect. The code I have is as follows:
<?php
include_once('connection.php');
$query="select * from myanimelist";
$result=mysql_query($query);
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles-2.css">
</head>
<body>
<h1> Callum Stewart's Amazing Website. </h1>
<h4> The Home of Entertainment. </h4>
<table align="center" border="1px" style="width: 300px" color="black">
<tr>
<th>Anime Database</th>
</tr>
<tr>
<th>Title</th>
<th>MediaType</th>
<th>Rating</th>
<th>NumOfEpisodes</th>
<th>NumOfVolumes</th>
</tr>
</table>
</body>
</html>
This is very quick.
I have a form that when submitted should add user input into my DB. I have had a similar form working well but for some reason this one is not working.
Please excuse my sloppy code but here is the whole page. For some reason 'observation' will not take the user input and display it on the next page (showOne.php). The next page simply shows a blank space for observation and I checked the DB and there was nothing in the observation field of course.
Is it something simple that I can't see? I've been at this for days since it is identical to another form I have that works well on another page.
Thank you for any insight.
<?php
//including the database connection file
include("config.php");
$activePage = "start.php";
if(isset($_POST['update'])) {
$id = $_POST['id'];
$observation = $_POST['observation'];
$result = mysqli_query($mysqli, "UPDATE tasks SET observation='$observation' WHERE id=$id");
header("Location: showOne.php?id=$id");
}
//getting id from url
$id = $_GET['id'];
//selecting data associated with this particular id
$result2 = mysqli_query($mysqli, "SELECT * FROM users WHERE id=$id ORDER BY id ASC");
$result = mysqli_query($mysqli, "SELECT * FROM tasks ORDER BY taskNumber ASC");
include_once "nav.php";
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Pathfinder - A User Testing Dashboard</title>
<meta name="description" content="Pathfinder - A User Testing Dashboard">
<meta name="author" content="James Stables - Thurs April 13th 2017">
<link rel="stylesheet" href="core.css">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,700" rel="stylesheet">
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"> </script>
<![endif]-->
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
</head>
<body>
<header>
<h1 class="logo"><img src="images/logo.png">Pathfinder</h1>
<h4>User Testing Dashboard</h4>
</header>
<section class="nonav">
<div class="showAllUsers">
<table border='0'>
<tr>
<?php while($res = mysqli_fetch_array($result2))
{ ?>
<td class="widthHundred no-border left"><h2><?php echo $res['nameFirst']; ?></h2></td>
<?php } ?>
</tr>
</table>
<table border='0'>
<thead>
<tr>
<th>Image</th>
<th>Category</th>
<th>Task Number</th>
<th>Task Name</th>
<th>Observation</th>
<td> </td>
<td> </td>
<td> </td>
</tr>
</thead>
<tbody>
<form name="start" method="post" action="start.php" enctype="multipart/form-data">
<tr>
<td><a href="<?php echo $res['$image'];?>" data-lightbox="example-1" data-title="Task Number <?php echo $res['taskNumber'];?>">
<img id="imageResize" src="<?php echo $res['image'];?>" /></a></td>
<td><?php echo $res['category'];?></td>
<td><?php echo $res['taskNumber'];?></td>
<td><?php echo $res['taskName'];?></td>
<td><input type="text" name="observation" value="<?php echo $res['observation'];?>"></td>
<td> </td>
<td> </td>
<td> </td>
<?php } ?>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><input type="hidden" name="id" value="<?php echo $_GET['id'];?>"><input type="submit" class="buttonUpdate right" name="update" value="Update"></td>
<td><a class="buttonCancel right" href="tasks.php" onClick="return confirm('Cancel and go back?')">Cancel</a></td>
</tr>
</form>
</tbody>
</table>
</div>
</section>
<script src="js/lightbox-plus-jquery.min.js"></script>
<script>
lightbox.option({
'resizeDuration': 200,
'showImageNumberLabel': false,
'fitImagesInViewport': true
})
</script>
</body>
</html>