Line break in table cell PHP - php

I am trying to perform several line break (br) in my table cell.
But I have problem with the syntax.
Below is my code to perform line break (br) within a single cell, but it doesn't work.
How should I go about doing it?
echo("<tr><td>".$row[0].
<br/>
$row[1].
<br/> $row[2].
<br/>
"<img src=images/".$row["skuCode"]."_1.jpg>".
<br/>
View".
"</td></tr>");

You're not using quotes properly, but I think it would be much easier to use a heredoc.
echo <<<HTML
<tr><td>$row[0]<br/>$row[1]<br/>$row[2]<br/>
<img src=images/$row[skuCode]_1.jpg<br/>
<a href=viewProductItem.php?skuCode=$row[0]>View</a>
</td></tr>
HTML;

You forgot the quotes around the <br/>s , try:
echo("<tr><td>".$row[0].
"<br/>" .
$row[1].
"<br/>". $row[2].
"<br/>" .
"<img src=images/".$row["skuCode"]."_1.jpg>".
"<br/>".
"View".
"</td></tr>");
Or alternatively:
echo("<tr><td>{$row[0]}
<br/>
{$row[1]}
<br/> {$row[2]}
<br/>
<img src=images/.$row[skuCode]._1.jpg>
<br/>
<a href=viewProductItem.php?skuCode={$row[0]}>View</a>.
</td></tr>");

You forgot to open and close the quotes in your string:
<?php
echo "<tr><td>".$row[0]."<br/>".$row[1]."<br/>".$row[2]."<br/><img src=images/".$row["skuCode"]."_1.jpg><br/>View</td></tr>";
?>

Try this:
echo "<tr><td>{$row[0]}<br/>{$row[1]}<br/>{$row[2]}<br/><img src=\"images/{$row['skuCode']}_1.jpg\"><br/>View</td></tr>";
You forgot to wrap the br tags around brackets, also you can use curly braces to never have to exit out of your string and concat it in php
echo "String with $variable works";
echo "String with {$array['key']} works with curly bracers."

If you want to make its HTML output well-formatted, then you could check this:
echo "<tr>\n";
echo " <td>" . $row[0] . "<br />\n";
echo " " . $row[1] . "<br />\n";
echo " " . $row[2] . "<br />\n";
echo ' <img src="images/' . $row["skuCode"] . '_1.jpg"><br />' . "\n";
echo ' View</td><br />' . "\n";
echo "</tr>\n";
Or this:
echo "<tr>\n";
echo " <td>" . $row[0] . "<br />\n";
echo " " . $row[1] . "<br />\n";
echo " " . $row[2] . "<br />\n";
echo " <img src=images/" . $row["skuCode"] . "_1.jpg><br />\n";
echo " View</td><br />\n"
echo "</tr>\n";
Or if you did not like those, look at this:
echo("<tr><td>" . $row[0] . "\n" .
"<br />\n" .
$row[1] . "\n" .
"<br />" . $row[2] . "\n" .
"<br />\n" .
"<img src=images/" . $row["skuCode"] . "_1.jpg>\n" .
"<br />\n" .
"View\n" .
"</td></tr>\n");

Related

How to create a multiple hyperlink in in single php line

I have tried below code; as you can see in bold line i want to add two hyperlink but i am not getting results.I want to create a variable hyperlink.
<?php
echo "<!DOCTYPE html>";
echo "<html>";
echo "<title> disorders </title>";
echo "<body>";
include ('menu.php');
echo "<br>";
echo "<br>";
$disorder = $_GET ['disorder'];
$sql_disorder= "SELECT * FROM `disorders raw datasets` WHERE `Name of disorder` = '$disorder' ";
if ($result_disorder = mysqli_query($conn, $sql_disorder));
{
echo "<table border='1' cellpadding='2' cellspacing='1'> ";
echo "<tr>";
echo "<th>Accession ID</th>";
echo "<th>Title</th>";
echo "<th>Abstract</th>";
echo "<th>Tissue type</th>";
echo "<th>PMID</th>";
echo "<th>Other information</th>";
echo "</tr>";
while($row_disorder = mysqli_fetch_array($result_disorder))
{
echo "<tr>";
**echo "<td><a href='https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc= href='https://www.ebi.ac.uk/arrayexpress/experiments/" . $row_disorder['Accession ID'] . " ' ' >" . $row_disorder['Accession ID'] . "</a> </td>";**
echo "<td>" . $row_disorder['Title'] . " </td>";
echo "<td>" . $row_disorder['Abstract'] . "</td>";
echo "<td>" . $row_disorder['Tissue type'] . " </td>";
echo "<td><a href='https://www.ncbi.nlm.nih.gov/pubmed/" . $row_disorder['PMID'] . " '>" . $row_disorder['PMID'] . "</a></td>";
echo "<td><a href='disorder_info.php?" . $row_disorder['Other information'] . " ' >" . $row_disorder['Other information'] . "</a></td>";
echo "</tr>";
}
echo "</table>";
}
echo "</body>";
echo "</html>";
?>
I don't know why you are using two href in a single tag, that does not support by any dom. Although replace your code with the following line.
echo "
<td><a href='https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=' href='https://www.ebi.ac.uk/arrayexpress/experiments/' " . $row_disorder['Accession ID'] . " ' '>" . $row_disorder['Accession ID'] . "</a> </td>";
You will have to use urlencode for it to work
$queryString = urlencode("href='https://www.ebi.ac.uk/arrayexpress/experiments/{$row_disorder['Accession ID']}'");
echo "
<td>
<a href='https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=$queryString'>
{$row_disorder['Accession ID']}
</a>
</td>";

foreach loop in while loop with div inside list element

hello guys i am trying to make a foreach loop in a while loop. in foreach loop i try to produce list elements with divs inside them but i have very strange output
here is my code
$countercat= 0;
$classvar= 1;
echo "<div class='selector-page'>";
echo "<div class='selector'>";
echo "<ul>";
while ($countercat <= 8){
$stmt=$conn->prepare('SELECT eidos, name, meta_keys, address, telephone, perioxi, st_img, st_open, st_close, lat, longtit FROM magazia WHERE perioxi= :perioxi AND eidos= :eidos ORDER BY st_id ASC');
$stmt->bindParam(':perioxi', $name, PDO::PARAM_STR);
$stmt->bindParam(':eidos', $eidos, PDO::PARAM_STR);
$eidos= $c_titles[$countercat]['c_name'];
$stmt->execute();
$allrows=$stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($allrows as $row) {
echo "<li>";
echo "<div class='p". $classvar . " w3-card targetDiv w3-margin-top cardsmar'>";
echo "<img src='../uploads/" . $row['st_img'] . "' class='cccard' alt='" . $row['name'] . "'";
echo "<div class='w3-container w3-center'>";
echo "<h3>" . $row['name'] ."</h3>";
echo "<p>" . $row['eidos'] . "</p>";
echo "<p>" . $row['address'] . " , " . $row['perioxi'] . "</p>";
echo "<p>" . $lang['wrlt'] . " : " . $row['st_open'] . "-" . $row['st_close'] . "</p>";
echo "<a href='katastimata.php?name=" . $row['name'] . "' role='button' class='w3-button w3-round w3black'>" . $lang['t9'] . "</a><br />";
echo "<a href='https://www.google.com/maps?q=loc:" . $row['lat'] . "," . $row['longtit'] . "' role='button' class='w3-button w3-round w3-green btnmar'>" . $lang['spot2'] . "</a>";
echo "</div>";
echo "</div>";
echo "</li>";
}
$countercat++;
$classvar++;
}
echo "</ul>";
echo "</div>";
echo "</div>";
}
?>
here is an image from my debugger consonle
as you see in the image inside in the ul tag exists only one li elemenemt
and the rest of them are out side ul /ul.
my first thought was that is not valid to put div tag in a li tag but this is not true if i use this in the top of my file
DOCTYPE html PUBLIC "-//W3C// DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/html1-transitional.dtd"
html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang:"en"
i am stack here for so long
what am i missing guys?
thanks in advance
vaggelis
You Didn't Close the <img> tag here.
echo "<img src='../uploads/" . $row['st_img'] . "' class='cccard' alt='" . $row['name'] . "'";
You Must Close the tag as
echo "<img src='../uploads/" . $row['st_img'] . "' class='cccard' alt='" . $row['name'] . "'/>";

Saving a fetched result back into the database

i want know how I can save a result i fetched from my database back into the database.
I selected and fetched a row from a table in my database, there is a column from the row i want to insert in another table in the same database. I tried to turn the $row['example']; to a variable but it wont work, i echo the variable to be sure if its working but its not showing .
please i need a help , below is my codes.
<?php
$query =mysqli_query ($dbconnect, "select * from stuprofile where username ='$user' limit 1");
while ($row= mysqli_fetch_assoc($query)){?>
<?php
$uname= "USERNAME :";
$ebc= "EBC16";
$id ="MATRIC NO : ";
$wel = "WELCOME ";
$name ="FIRSTNAME : ";
$lname ="LASTNAME : ";
$sex ="SEX : ";
$add ="ADDRESS : ";
$mob ="MOBILE : ";
$inst ="INSTITUTION : ";
$chap ="CHAPTER : ";
$marr ="MARITAL STATUS : ";
$lc ="LOCAL CHURCH : ";
$bap ="BAPTISM : ";
$baptised ="BAPTISED : ";
$bank ="BANK : ";
$teller ="TELLER NUMBER : ";
$pay ="PAYMENT NUMBER : ";
$email ="EMAIL : ";
// dont forget to style your above varibles
//<span id ="ty">
?>
<div class="wel">
<?php
echo "<p>" . $wel . "<div id='ten' >" . " " . $row['firstname'] . " " . $row['lastname'] . "</div>" . "<p>" . "<br />" ;
?>
</div>
<!--<section><img src= "images/egliselogocomp.jpg" height="310" width: 50px> </section>-->
<p class= "names">
<?php
echo
$id . "<span >" . $ebc . $row['id']. "</span >" . " <br />" .
$name . "<span >" . $row['firstname']. "</span >" . "<br />" .
$lname . "<span >" .$row['lastname']. "</span >" . "<br />" .
$uname . "<span >" .$row['username']. "</span >" . "<br />" .
$sex . "<span >" .$row['sex'] . "</span >" . "<br />" .
$add . "<span >" .$row['address']. "</span >" . "<br />" .
$email . "<span >" .$row['email']. "</span >" . "<br />" .
$mob . "<span >" .$row['mobile']. "</span >" . "<br />" .
$inst . "<span >" .$row['institution']. "</span >" . "<br />" .
$chap . "<span >" .$row['chapter']. "</span >" . "<br />" .
$marr . "<span >" .$row['marital_status']. "</span >" . "<br />" .
$lc . "<span >" .$row['local_church']. "</span >" . "<br />".
$bap . "<span >" .$row['baptised']. "</span >" . "<br />" .
$baptised . "<span >" .$row['baptism']. "</span >" . "<br />" .
$bank . "<span >" .$row['bank']. "</span >" . "<br />" .
$teller . "<span >" .$row['teller_no']. "</span >" . "<br />".
$pay . "<span >" .$row['payment_date']. "</span >" . "<br />";
}
?>
</p>
<?php
} else {
header("location: ebcreg.php");
}
I need to insert the . $ebc . $row['id'] back into the database.
How do I do that please.
thanks
mysqli_query($dbconnect, "INSERT INTO ....");
The same way you selected your data, just change your query.

PHP code to display db data

Hi guys I have a problem with my PHP, What I am trying to achieve is this:
<li>Product name from DB
<strong>£499<img src="images/thumb.png" alt="Product name from DB"/></strong>
</li>
and here is my code with php:
<ul id="items">
<?php while($product_data = mysql_fetch_array($query_product_result))
{
$num_rows_products = $num_rows_products - 1;
Print "<li><a href = 'main.php?prodid=" . $product_data["product_id"] . " <strong> Name: " . $product_data["title"] . "</strong></a>";
Print "<strong>Price: £" . $product_data["price"] . "'><img src='images/" . $product_data["mainImageThumbnail"] . "' alt='Product image' /></a></strong></li>";
if($num_rows_products > 0)
Print '<p> nu products ? wtf</p>';
}
?>
For some reason all I get is an image with a hyperlink, no title and no price, any chance you can spot the mistake?
Your not closing the <a> tag properly. See the code below. Notice the missing ">" in your code?
Print "<li><a href = 'main.php?prodid=" . $product_data["product_id"] . "'> <strong> Name: " . $product_data["title"] . "</strong></a>";
Print "<strong>Price: £" . $product_data["price"] . "<img src='images/" . $product_data["mainImageThumbnail"] . "' alt='Product image' /></a></strong></li>";
Use Echo instead. Print won't displays concatenated string.
<ul id="items">
<?php while($product_data = mysql_fetch_array($query_product_result))
{
$num_rows_products = $num_rows_products - 1;
echo "<li><a href = 'main.php?prodid=" . $product_data["product_id"] . " <strong> Name: " . $product_data["title"] . "</strong></a>";
echo "<strong>Price: £" . $product_data["price"] . "'><img src='images/" . $product_data["mainImageThumbnail"] . "' alt='Product image' /></a></strong></li>";
if($num_rows_products > 0)
echo '<p> nu products ? wtf</p>';
}
?>

php pass parameter issue

This my code:
<?php
$lijstDoelmannen = mysql_query("SELECT * FROM Speler WHERE positie = 'Doelman' ORDER BY familienaam, voornaam");
$teller = 1;
while($rij = mysql_fetch_array($lijstDoelmannen))
{
if($teller < 5){
echo "<td><a href='spelerDetail.php?spelerId='" . $rij['id'] . "><img src='images/spelers/unknown.png' alt='' width='50' />
<br /><br />" . $rij["id"] . " " . $rij['familienaam'] . " " . $rij['voornaam'] . "</a></td>";
}
}
?>
The problem is that in the hyperlink the parameter spelerId = spaces (not filled in). If I echo $rij["id"], it gives me the right value.
You have a ' in the wrong spot in your href.
"...<a href='spelerDetail.php?spelerId='" . $rij['id'] . ">..."
This should be:
"...<a href='spelerDetail.php?spelerId=" . $rij['id'] . "'>..."
<a href='spelerDetail.php?spelerId='" . $rij['id'] . ">
You need to move the apostrophe:
<a href='spelerDetail.php?spelerId=" . $rij['id'] . "'>
It's currently ending the link, before the variable is added.
You can also do:
echo "<td><a href='spelerDetail.php?spelerId={$rij['id']}'
while($rij = mysql_fetch_array($lijstDoelmannen))
{
if($teller < 5){
echo "<td><a href='spelerDetail.php?spelerId='" . $rij['id'] . "><img src='images/spelers/unknown.png' alt='' width='50' />
<br /><br />" . $rij["id"] . " " . $rij['familienaam'] . " " . $rij['voornaam'] . "</a></td>";
}
}
?>
I prefer writing the above code this way to avid these types of issues:
while($rij = mysql_fetch_array($lijstDoelmannen)){
if($teller < 5){ ?>
<td><a href="spelerDetail.php?spelerId=<?php echo $rij['id'] ?>">
<img src="images/spelers/unknown.png" alt="" width="50" />
<br /><br /><?php echo $rij['id'] . " " . $rij['familienaam'] . " " . $rij['voornaam'] ?></a></td>
<?php }} ?>

Categories