PHP table and code in echo <td> - php

At this moment I am working on a WordPress website. To get the title of the site I am using the next code:
<div class="site-title"><?php bloginfo( 'name' ); ?></div>
Now I want to put this code/ the result of it in a php table cell, so:
echo "<td align='center' width='50%'>SITENAME</td>";
How can I implement/ use that php bloginfo code at the place where currently SITENAME is written?

Try like
echo "<td align='center' width='50%'>".bloginfo( 'name' )."</td>";

Just echo it like this
echo "<td align='center' width='50%'>".bloginfo( 'name' )."</td>";

Related

How to display database data to another page?

this is my code for the my table of rooms
<?php
include'db.php';
$sql=mysql_query("Select*from tb_rooms1");
echo "<div class='container'>";
echo "<div class='scrolltable'>";
echo "<table class= 'table table-striped table-bordered'>";
echo"<th><div align='center'>ID</div></th>";
echo"<th><div align='center'>Image</div></th>";
echo"<th><div align='center'>Room Name</div></th>";
echo"<th><div align='center'>Description</div></th>";
echo"<th><div align='center'>Price Per Night</div></th>";
echo"<th><div align='center'>Status</div></th>";
echo"<th><div align='center'>Reserve</div></th>";
while($row=mysql_fetch_array($sql))
{
#$id=$row['eid'];
echo"<tr align='center'>";
echo"<td><div style='font-size:11px;' align='center'>".$row['roomID']</div></td>";
echo"<td><div style='font-size:11px;' align='center'><img width=72 height=52 alt='Unable to View' src=".$row['image']."></div></td>";
echo"<td><div style='font-size:11px;' align='center'>".$row['name']."</div></td>";
echo"<td><div style='font-size:11px;' align='center'>".$row['description']."</div></td>";
echo"<td><div style='font-size:11px;' align='center'>".$row['price']."</div></td>";
echo"<td><div style='font-size:11px;' align='center'>".$row['status']."</div></td>";
echo"<td><div align='center' style='margin-top:30px'><input style='margin-top:-2px;' type='checkbox'></div></td>";
}
echo"</table>";
echo"</div>";
echo"</div>";
?>
I don't know how can I display the Information of the room I have selected to another page. Can someone help me? I'm
Make your room clickable and pass the room id through as a parameter
echo"<td><div style='font-size:11px;' align='center'><a href='otherpage.php?roomid={$row['roomID']}'> Room {$row['roomID']}</a></div></td>";
In your other php document you would have something like this:
otherpage.php
<?php
include'db.php';
$roomid = $_GET['roomid'];
$lookupQuery = mysqli_query("SELECT * FROM tb_rooms1 WHERE roomID = [$roomid]");
... Display the data however you want
One thing you will need to look into is mysql injection since you're code is using mysql and parameters are being passed straight into your query...

I upload videos into into directory and i want them to display horizontall when i echo them

I have these codes and am not good at php please can someone help me on how to echo the videos to appear horizontall in my page thanks in advance
<?php
$h=2;
$k=mysql_query("SELECT * from aupload where type='audios' and view>='$h' order by view DESC");
while ($la=mysql_fetch_array($k)){
?>
<center>
<table width='100%'height=''>
<tr>
<?php echo"<td>" . "<a href='uploads/$la[filename]'><img src='uploads/$la[size]' width='180px' height='180px'>
<br><b>$la[filename]</b><br><a href='music1.php?id=".$la['id']."'><input type='button' value='DOWNLOAD'><input type='button' value='$la[view]'> </a></a>
"?></td>
</tr>
</table><br>
</center>
<?php }?>
<?php
include('connect.php');
$k=mysql_query("SELECT * from aupload where type='audios'");
#$la=mysql_fetch_array($k)
?>
<?php
$h=2;
$y=mysql_query("SELECT * from aupload where type='videos' and view>='$h' order by view DESC ");
?>
<table border='0' id='myTable'width='100%'>
<?php
while ($x=mysql_fetch_array($y)){
echo "<tr>";
echo "<td>" . "<video id='myVideo' onclick='message()' width='180px' height='180px' controls><source src='uploads/$x[filename]' '></video>" . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td width='' height=''>"."<a href='music2.php?id=$x[id]' > <b>$x[filename]</b><br><input type='button' value='DOWNLOAD'></a>" ."<input type='button' value='$x[view]'></a></a>". "</td>";
echo "</tr>";
}
echo "</table>"; echo"</center>";
?>
the problem is when I upload two or more videos they appear vertically but I just want them to appear horizontally when echo them please someone help and thanks
Use frames is the best way to display a video, try this code
This is actually a HTML question, not a PHP question. In HTML, designates a table row, and can contain many or table cell elements. So you want to have the a echoed before the while loop, then print just the elements in the while loop, then print the . This will put all the elements in a single table row.

Delete a single db row after clicking delete button

I have this query, where I want to delete a single row from DB when clicking on delete button. Right now, it's deleting the whole DB row. but I want to delete a single row by ID.
Here's the code
add_action('admin_menu', 'conference_register');
function conference_register(){
add_options_page('Register Conference', 'Conference Registration', 'manage_options', 'conference-registration', 'display_conference');
}
function display_conference(){
echo "<form method='post'>";
echo "<div class='wrap'>";
echo "<h2>Conference Registration User Details</h2>";
global $wpdb;
$results = $wpdb->get_results("SELECT `id`,`email`,`details` FROM `conference_register`"); ?>
<table class="wp-list-table widefat fixed striped pages">
<thead>
<tr>
<th id="posts" class="manage-column column-posts num">ID</th>
<th id="email" class="manage-column column-email">Email</th>
<th id="description" class="manage-column column-description">Details</th>
<th id="posts" class="manage-column column-posts num">Delete</th>
</tr>
</thead>
<tbody id="the-list">
<?php foreach($results as $value){
echo "<tr>";
echo "<td class='posts column-posts'>".$value->id."</td>";
echo "<td class='email column-email'>".$value->email."</td>";
echo "<td class='description column-description'><div id='col-container'>".$value->details."</div></td>";
echo "<td class='posts column-posts'><input type='submit' name='delete_registration' value='delete'/></td>";
echo "</tr>";
if(isset($_POST['delete_registration'])){
$wpdb->delete( 'conference_register', array( 'id' => $value->id ) );
}
}
echo "</tbody></table></div></form>";
}
The code for clicking action is set like this in above code:
if(isset($_POST['delete_registration'])){
$wpdb->delete( 'conference_register', array( 'id' => $value->id ) );
}
Am I missing anything here?
Any help will be appreciated.
P.S. I want to delete a row without using jQuery.
Use this as you are deleting the row if delete_registration is set. You need to set/check it for each row and delete that particular row.
<?php foreach($results as $value){
echo "<tr>";
echo "<td class='posts column-posts'>".$value->id."</td>";
echo "<td class='email column-email'>".$value->email."</td>";
echo "<td class='description column-description'><div id='col-container'>".$value->details."</div></td>";
$delRow = "delete_registration_{$value->id}";
echo "<td class='posts column-posts'><input type='submit' name= $delRow value='delete'/></td>";
echo "</tr>";
if(isset($_POST[$delRow])){
$wpdb->delete( 'conference_register', array( 'id' => $value->id ) );
}
}
You are not passing the id or the database query syntax is not okay
Use this:
echo "<td class='posts column-posts'><input type='submit' name= 'delete_registration_{$value->id}' value='delete'/></td>";
echo "</tr>";
if(isset($_POST[delete_registration_{$value->id}])){
$wpdb->delete( 'conference_register', array( 'id' => $value->id ) );
}
This should work
How I do this is in each row I have a hidden input field and have default value = "x". When user changes any field I use javascript to change the value to "e" and if user clicks "delete" I change the value to "d" and submit the form.
On Submit I use a switch . Loop through all records, if e - edit, d-delete.

how to properly transfer user input from index to invoice?

I got a dillema, I'm trying to find a solution for my code. How do I make it so that when the user inputs a given quantity in the text box from the index.php it will transfer that input quantity to the invoice.php. I've tried doing the post method but it seems like it's not working :/ As always, any help or suggestions will be greatly appreciated! I hope it's something simple:( Here's my code:
This code holds my products array and also includes my text box.
//The following arrays contain our products and their information, one product per array.
$hulkhamburger = array('Product' => 'Hulk Hamburger', 'Description' => '...', 'Price' => '$1.00', 'Quantity' => "<input type='text' name='quantity1'>");
$atomichotdog = array('Product' => 'Atomic Hot Dog', 'Description' => '...', 'Price' => '$2.00', 'Quantity' => "<input type='text' name='quantity2'>");
$friedchicken = array('Product' => 'Fantastic 4 Fried Chicken', 'Description' => '...', 'Price' => '$3.00', 'Quantity' => "<input type='text' name='quantity3'>");
$psyonicpizza = array('Product' => 'Psyonic Pizza', 'Description' => '...', 'Price' => '$4.00', 'Quantity' => "<input type='text' name='quantity4'>");
$marvelmeatloaf = array('Product' => 'Marvel Meatloaf', 'Description' => '...', 'Price' => '$5.00', 'Quantity' => "<input type='text' name='quantity5'>");
//The following array takes our previous five arrays and puts them into one array for easier coding and reading.
$allfood = array ($hulkhamburger, $atomichotdog, $friedchicken, $psyonicpizza, $marvelmeatloaf);
?>
index.php
<html>
<style>
body{
background-image: url('URL HERE');
font-family: "Helvetica";
font-size:15px;
}
h1{
color:black;
text-align:center;
}
p{
font-size:15px;
}
</style>
<h1>
STORE TITLE HERE
</h1>
<body>
<form action="login.php" method="post">
<?php
//Include products info.inc (Which holds all our product arrays and info)
//Credit: Tracy & Mark (THank you!)
include 'products_info.inc';
/*The following code centers my table on the page, makes the table background white,
makes the table 50% of the browser window, gives it a border of 1 px,
gives a padding of 2 px between the cell border and content, and gives 1 px of spacing between cells.
*/
echo "<table align=center bgcolor='FFFFFF' width=50% border=1 cellpadding=1
cellspacing=2>";
//Credit: Tracy & Mark (THank you!)
echo '<th>Product</th> <th>Description</th> <th>Price</th> <th>Quantity</th>';
//The following code loops through the whole table body and then prints each row.
for($i=0; $i<count($allfood); $i++)
{
//Credit: Tracy & Mark (THank you!)
echo "<tr align=center>";
echo "<td>{$allfood[$i]['Product']}</td>";
echo "<td>{$allfood[$i]['Description']}</td>";
echo "<td>{$allfood[$i]['Price']}</td>";
echo "<td>{$allfood[$i]['Quantity']}</td>";
echo "</tr>";
}
//This code ends the table.
echo "</table>";
echo "<br>";
?>
<br><center><input type='submit' name='purchase' value='Purchase'></center>
</form>
</body>
</html>
And here's my invoice.php
<html>
<style>
body{
background-image: url('URL HERE');
font-family: "Helvetica";
font-size:15px;
}
h1{
color:black;
text-align:center;
}
p{
font-size:15px;
}
</style>
<h1>
Invoice
</h1>
</html>
<?php
//Include products info.inc (Which holds all our product arrays and info)
//Credit: Tracy & Mark (Thank you!)
include 'products_info.inc';
//Display the invoice & 'WELCOME USER. THANK YOU FOR USING THIS DAMN THING msg'
/*The following code centers my invoice table on the page, makes the table background white,
makes the table 50% of the browser window, gives it a border of 1 px,
gives a padding of 2 px between the cell border and content, and gives 1 px of spacing between cells.
*/
echo "<table align=center bgcolor='FFFFFF' width=50% border=1 cellpadding=1cellspacing=2>";
echo "<tr>";
echo "<td align=center><b>Product</b></td>";
echo "<td align=center><b>Quantity</b></td>";
echo "<td align=center><b>Price</></td>";
echo "<td align=center><b>Extended Price</b></td>";
echo "</tr>";
for($i=0; $i<count($allfood); $i++)
{
//Credit: Tracy & Mark (Thank you!)
$qty= #$_POST['Quantity']['$i'];
// This calculates the price if the user orders more than 1 item.
$extendedprice = $qty*$allfood[$i]['Price'];
echo "<tr>";
echo "<td align=center>{$allfood[$i]['Product']}</td>";
echo "<td align=center>$extendedprice</td>";
echo "<td align=center>{$allfood[$i]['Price']}</td>";
echo "</tr>";
}
// The goal here was to make it so that if the user selected a certain quantity from index.php, it would carry over and display on the invoice.php
if ($qty = 0)
{
echo "please choose 1";
}
elseif ($qty > 0)
{
echo $qty;
}
/*echo "<tr>";
echo "<td align=center>Subtotal</b></td>";
echo "<td align=center></td>";
echo "<td align=center></td>";
echo "<tr>";
echo "<td align=center>Tax at 5.75%</td>";
echo "<td align=center></td>";
echo "<td align=center></td>";
echo "<tr>";
echo "<td align=center><b>Grand total</b></td>";
echo "<td align=center></td>";
echo "<td align=center></td>";
*/
echo "</table>";
?>
<br>
<center>
<form action="index.php" method="post">
<input type="submit" name="home" value="Back to homepage">
</form>
</center>
A form is like a container which handles transfer of data. The action attribute tells where your data will be sent.
Here you got
<form action="login.php" method="post">
Which means the form data will be sent to login.php page. Not what you want i think.
Then, in the target page (defined by action attribute), you can get your parameters values in $_GET or $_POST arrays, depending of the method attribute of your form.
I don't see any textbox in the code you gave us. If you add something like
<input type="text" name="my_textbox"/>
You will be able to get the value of the textbox in your target page by using
$_POST['my_textbox']
Hope this helps.
BTW, i notices some mistakes into your code :
index.php :
Style should be in a <head>...</head> markup
You should not have html output like your <h1> outside of your <body>...</body>
Tables headers (<th>) should be in a <tr> as <td> are.
invoice.php :
$allfood is not declared
Better than $qty= #$_POST['Quantity']['$i'] (# removes errors), test if your key exists (if isset($_POST['Quantity']) && isset($_POST['Quantity'][$i]) $qty = $_POST['Quantity'][$i];
if ($qty = 0) should be if ($qty == 0) : = is affectation operator, == is comparison operator
same thing for html, all your output should be in <body>...</body> markups, and styles should be in an html header (<head>...</head>)
In index.php, your form action is "login.php", not invoice.php, so it will not pass anything to the latter.
Also, in index.php, there is no textbox named "quantity", so $_POST['quantity] will have nothing.
As in index.php inside form you have created table. There is no form elements like text box, hidden field. Form does not post table values hence you are not getting any posted value in invoice.php.

Issue including page.php on page

I am trying to include a vbijreizen_kaart.php within some code. When I put it outside of the echo, but within the loop (i think this is correct terminology). It will load my google map, however, it will not bring back the rest of the results in my (while) results. When I remove it, the results appear, so I'm doing something wrong but I just don't know what.
The bit of code that is where I am having problems is:
$result = mysql_query($sql);
echo "<br />"; ?>
<?php include('vbijreizen_kaart.php');?>
<?php
echo "<table border='0' cellspacing='0'>
<tr>
<th width='20' valign='top'><div align='left'> </div></th>
</tr>
<tr>
<th height='1' colspan='9' valign='top' bgcolor='#333333'></th>
</tr>";
while($row = mysql_fetch_array($result)){
$row_color = ($row_count % 2) ? $color1 : $color2;
echo "<td bgcolor='$row_color'>" .date("d-M-Y H:i",
strtotime($row['vertrekdatum2'])). "</td>";
echo "<td bgcolor='$row_color'><img src='../flags/".$row['countryflag']."'>
<abbr title=\"".htmlspecialchars($row['luchthavennaam'])."\">
".$row['luchthavencode']."</abbr></td>";
echo "<td bgcolor='$row_color'><img src='../flags/".$row['countryflagaankomst']."'>
<abbr title=\"".htmlspecialchars($row['aankomstnaam'])."\">
".$row['aankomstluchthaven']."</abbr></td>";
I have tried doing just
echo "<br />";
echo include('vbijreizen_kaart.php');
echo " blah blah blah
and I've tried as above, and nothing will let me display the map that exits on vbijreizen_kaart.php as well as the data that would display in the while results.
I can verify in Toad that I have the Query working as it should.
include is not a method, so syntax can look like: include 'vbijreizen_kaart.php';, but that's not the problem. include basically allows you to access the classes, functions, and variables that are on the included page. You don't echo or print the included page itself, but rather the classes, functions, and any variables on the included page. Also, the included page can echo or print to the page you include it into, so it could be a matter of position.

Categories