I'm attempting to display my data in a table from my database, I used the exact same code for another table but for some reason the table appears but is empty.
Thanks its solved!
you have to put brackets in while loop, close tag and the last :
echo "<table border=1 cellpadding=5>";
echo "<tr>";
echo "<th>Workshop Name</th>";
echo "<th>Workshop Price (£)</th>";
echo "<th>Workshop Description</th>";
echo "<th>Further Information</th>";
echo "</tr>";
$SQL="select workshopId,workshopName, workshopPrice,workshopDescription from Workshops order by workshopId";
$exeSQL=mysql_query($SQL) or die (mysql_error());
while ($arrayworkshop=mysql_fetch_array($exeSQL))
{
echo "<tr>";
//display details
echo "<td>".$arrayworkshop['workshopName']."</td>";
echo "<td>".$arrayworkshop['workshopPrice']."</td>";
echo "<td>".$arrayworkshop['workshopDescription']."</td>";
echo "<td><a href='ViewWorkshop.php?workshopId=".$arrayworkshop['workshopId']."'>";
//Display name of the Task
echo "Further Information"."</a></td>";
echo "</tr>";
}
echo "</table>";
Related
I'm trying to rotate an array (5x6 for example) on pos to right each value, the last must to be the first
//ADD VALUES (RANDOM)
for($i=0;$i<6;$i++){
for($j=0;$j<7;$j++){
$aleatorio=mt_rand(10,99);
$a[$i][$j]=$aleatorio;
}
}
echo "<br>"; / SHOW IN A TABLE
echo "<table border=1 width=200px >";
for($i=0;$i<count($a);$i++){
echo "<tr>";
for($j=0;$j<count($a[0]);$j++){
echo "<td>".$a[$i][$j]."</td>";
}
echo "</tr>";
}
echo "</table>";
echo "<br>";echo "<br>";
$last=array_pop($a); //KEEP THE LAST VALUE
array_unshift($a,$last); //PUT IN THE FIRST POSITION
//SHOW AGAIN
echo "<br>";echo "<br>";
echo "<table border=1 width=200px >";
for($i=0;$i<count($a);$i++){
echo "<tr>";
for($j=0;$j<count($a[0]);$j++){
echo "<td>".$a[$i][$j]."</td>";
}
echo "</tr>";
}
echo "</table>";
Why does the last value appear in first row last column? not in [0][0] position
The images are stored as a BLOB type in my database. I want the user to be able to click on a 'View Inventory' button and be taken to a page with an HTML table that displays images for each item.
This is the table in my php file:
echo "<table border='1'>";
echo "<tr>";
echo "<th>Categor</th>";
echo "<th>Description</th>";
echo "<th>Unit Cost</th>";
echo "<th>XS Quantity</th>";
echo "<th>S Quantity</th>";
echo "<th>M Quantity</th>";
echo "<th>L Quantity</th>";
echo "<th>XL Quantity</th>";
echo "<th>XXL Quantity</th>";
echo "<th>XXXL Quantity</th>";
echo "<th>Image</th>";
echo "<th></th>";
echo "</tr>";
while($row=mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>{$row['category']}</td>";
echo "<td>{$row['description']}</td>";
echo "<td>$ {$row['unitCost']}</td>";
echo "<td>{$row['xsQuantity']}</td>";
echo "<td>{$row['sQuantity']}</td>";
echo "<td>{$row['mQuantity']}</td>";
echo "<td>{$row['lQuantity']}</td>";
echo "<td>{$row['xlQuantity']}</td>";
echo "<td>{$row['xxlQuantity']}</td>";
echo "<td>{$row['xxxlQuantity']}</td>";
echo "<td><img src='Downloads/".$row['apparelImage']."'></td>";
echo "<td><a href='#'>Add</a></td>";
echo "</tr>";
}
echo "</table>";
If your image is stored as blob, you can't do echo "<td><img src='Downloads/".$row['apparelImage']."'></td>";
You should print a img tag which will handling your image. Pass row ID in src attribute of this tag and get it in script. Then, get the record from database and set headers to show image.
Like:
echo '<img src="script_to_show_image.php?id=' . $row['id'] . '">';
In script_to_show_image.php, after get record from database, you must set headers to print image correctly:
header("Content-Type: image/jpeg");
Then, print the content:
echo $apparelImage;
I use this while loop to display events from facebook. I want to add an href link in each record that will open a new tab displaying only this event. I have created links for each record but I can't understand how I can make the link to lead to that event.
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<table class='table table-hover table-responsive table-bordered'>";
echo "<tr>";
echo "<td rowspan='6' style='width:20em;'>";
echo "<img src=". $row["COVER_PHOTO"]." width='200px' />";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td style='width:15em;'>What:</td>";
echo "<td><b>". $row["NAME"]."</b></td>";
echo "</tr>";
//owner
echo "<tr>";
echo "<td>Who:</td>";
echo "<td>". $row["OWNER"]."</td>";
echo "</tr>";
echo "<tr>";
echo "<td>What kind:</td>";
echo "<td>". $row["PAGE_CAT"]."</td>";
echo "</tr>";
echo "<tr>";
echo "<td>When:</td>";
echo "<td>". $row["START_DATE"]." at ". $row["START_TIME"]."</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Where:</td>";
echo "<td>". $row["PLACE"]."</td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
echo "<a href='view.php?more=". $row["EVENT_ID"]."' target='_blank' <?php echo >Λεπτομέρειες</a>";
echo "<tr>";
echo "<td>Description:</td>";
echo "<td>". $row["DESCRIPTION"]."</td>";
echo "</tr>";
Your code for this page is just fine. Now to display each individual event in the view.php file, you will need to access the data (in your case the event ID, stored in more variable) sent via GET method in the view.php page, as thus:
view.php
<?php
if(isset($_GET['more']))
{
$more = $_GET['more'];
}
?>
The value of the more variable sent via the URL will now be saved in the $more PHP variable. For example, if the page called is view.php?view=22, the $more variable will have the value of 22.
You can now use this $more variable - which stores the event ID - to fetch whatever other detail you require.
echo "<a href='view.php?more=". $row["EVENT_ID"]."' target='_blank'> Λεπτομέρειες</a>";
This might sound a little vague, but I'm looking to place a variable from a MySQL database inside a line of HTML. Currently it looks like this:
.
Below is the code I am using.
Thanks!
echo "<table border='1'>";
echo "<tr> <th>Helo</th> <th>Class</th> <th>Need</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo $row['Icon'];
echo "</td><td>";
echo $row['Class'];
echo "</td><td>";
echo $row['Need'];
echo "</td></tr>";
}
echo "</table>";
?>
Try:
echo '<img src="'.$row['Helo'].'" title="'.$row['Class'].'">';
I've put together the following code which creates a table upon a selection being made with a drop down menu.
echo "<table>";
$result=mysql_query($query);
while($rows=mysql_fetch_array($result)){
echo "<tr>";
echo "<th>Find Name:</th>";
echo "<th>Find Description:</th>";
echo "</tr>";
echo "<tr>";
echo "<td>".$rows['findname']."</td>";
echo "<td>".$rows['finddescription']."</td>";
echo "</tr>";
}
echo "</table>";
The problem I've got is that for each record that is returned the 'headers' are repeated. The live page can be found here. I just wonder whether someone could perhaps take a look at this please and tell me where I've gone wrong.
Apologies for the really simple question, but I've been looking at this for a while and I just can't find the answer. I think it just needs a fresh pair of eyes to look at it.
Try this, you just need to get headers out of while loop
echo "<table>";
echo "<tr>";
echo "<th>Find Name:</th>";
echo "<th>Find Description:</th>";
echo "</tr>";
$result=mysql_query($query);
while($rows=mysql_fetch_array($result)){
echo "<tr>";
echo "<td>".$rows['findname']."</td>";
echo "<td>".$rows['finddescription']."</td>";
echo "</tr>";
}
echo "</table>";
The answer is obvious, you are repeating the output of the headers in the loop. Move the
while($rows=mysql_fetch_array($result)){
after the first
echo "</tr>";
You need to put the headers outside of the while loop:
echo "<table>";
echo "<tr>";
echo "<th>Find Name:</th>";
echo "<th>Find Description:</th>";
echo "</tr>";
$result = mysql_query($query);
while ($rows = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $rows['findname'] . "</td>";
echo "<td>" . $rows['finddescription'] . "</td>";
echo "</tr>";
}
echo "</table>";
This should work:
echo "<table>";
echo "<tr>";
echo "<th>Find Name:</th>";
echo "<th>Find Description:</th>";
echo "</tr>";
$result=mysql_query($query);
while($rows=mysql_fetch_array($result)){
echo "<tr>";
echo "<td>".$rows['findname']."</td>";
echo "<td>".$rows['finddescription']."</td>";
echo "</tr>";
}
echo "</table>";
Your headers are being repeated because you are writing them inside the loop, for each row returned by the query. You simply need to move your headers outside the loop so they're only written once, before the rows returned by the query start printing:
echo "<table>";
echo "<tr>";
echo "<th>Find Name:</th>";
echo "<th>Find Description:</th>";
echo "</tr>";
$result=mysql_query($query);
while($rows=mysql_fetch_array($result)){
echo "<tr>";
echo "<td>".$rows['findname']."</td>";
echo "<td>".$rows['finddescription']."</td>";
echo "</tr>";
}
echo "</table>";
headers are repeating becasue they are in while loop, it should work well
echo "<table>";
echo "<tr>";
echo "<th>Find Name:</th>";
echo "<th>Find Description:</th>";
echo "</tr>";
$result=mysql_query($query);
while($rows=mysql_fetch_array($result)){
echo "<tr>";
echo "<td>".$rows['findname']."</td>";
echo "<td>".$rows['finddescription']."</td>";
echo "</tr>";
}
echo "</table>";
Change to:
echo "<tr>";
echo "<th>Find Name:</th>";
echo "<th>Find Description:</th>";
echo "</tr>";
echo "<tr>";
while($rows=mysql_fetch_array($result)){
echo "<td>".$rows['findname']."</td>";
echo "<td>".$rows['finddescription']."</td>";
echo "</tr>";
}
echo "</table>";