So I have a dynamic PHP table where I am trying echo one of the table columns as a dynamically generated link. Presently, the $url variable i have declared is returning null. $row['username'] is returning what it should, so I suspect I have the syntax off for that. I also am having trouble with the syntax on the following line. How do I insert the $row['username'] as the link text?
echo "<td>" . "<a href='".$url."'> . $row['username'] . </a>" . "</td>";
this present example returns an error, but when I replace it with:
echo "<td>" . "<a href='".$url."'> blahblahfiller </a>" . "</td>";
the page runs, so I know it's my syntax there.
Here is my full code for the table:
<?php
while ($row = mysql_fetch_array($query)) {
$url = "profilepage.php?name=" + $row['username'];
echo "<tr>";
echo "<td>" . '<input type="checkbox" name="checkbox"/>' . "</td>";
echo "<td>" . "<a href='".$url."'> . $row['username'] . </a>" . "</td>";
echo "<td>" . $row['gender'] . "</td>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $url . "</td>";
echo "</tr>";
}
?>
Sincere thanks for any and all help! It means a lot.
You are using + instead of . for to concatenate. It should be -
$url = "profilepage.php?name=". $row['username'];
Related
I want to put a button in the table at php.
here is my code.
echo "<td>";?> <img src="<?php echo $row["image"]; ?>" height = "100" width = "100" border="1"> <?php echo "</td>"; //row에 값넣는 것
echo "<td>" . $row['bookName'] . "</td>";
echo "<td>" . $row['publisher'] . "</td>";
echo "<td>" . $row['writer'] . "</td>";
echo "<td>" . $row['libraryowned'] . "</td>";
echo "<td>" . $row['codenumber'] . "</td>";
// I want to button here
echo "<td>" . $row['loan'] . "</td>";
echo "<td>" . $row['publicationdate'] . "</td>";
echo "<td>" . $row['reservation'] . "</td>";
echo "<td>" . $row['borrowdate'] . "</td>";
echo "<td>" . $row['returndate'] . "</td>";
echo "<tr></tr>";
just put a button element inside a element like this:
<td><button></button></td>
if you like to refer to some script / page:
<td><button></button></td>
You can put in the href part whatever you want. You can also omit the button element and heir your button-CSSClass to the <a> element.
I hope I helped you.
Have Fun!
I have a PHP code, showing me raw data from a MySQL database in a table.
I want to add some text to one of the existing cells, depending on a value in another column which is not displayed in the table.
My code looks like this:
while($row = mysqli_fetch_array($rs))
{
echo '<tr class="lokbes">';
echo "<td class='blaa'>" . $row['Navn'] . "</td>"; // I want the extra text here.
echo "<td>" . $row['Stilling'] . "</td>";
echo "<td>" . $row['Institution'] . "</td>";
echo "<td><a href='mailto:$row[Email]'>" . $row['Email'] . "</a></td>";
echo "<td>" . $row['Mobiltelefon'] . "</td>";
}
echo "</tr>";
echo "</table>";
This outputs a table consisting of Name, job, workplace etc.
In the cell displaying the name, I would like to add some text if a column in my MySQL DB has the value 1 in the row.
What to do? I've tried using if, as seen below - but that doesn't seem to work.
echo "<td class='blaa'>" . $row['Navn'] .
if ($row['Formand'] == 1) {
echo "(Formand)";
} "</td>";
You have to do multiple echos :
echo "<td class='blaa'>" . $row['Navn'];
if ($row['Formand'] == 1) {
echo "(Formand)";
}
echo "</td>";
Or, with ternary operator :
echo "<td class='blaa'>" . $row['Navn'] . ($row['Formand'] == 1 ? "(Formand)" : "") . "</td>";
update like this.
echo "<td class='blaa'>" . $row['Navn'];
if ($row['Formand'] == 1) {
echo " (Formand)";
}
echo "</td>";
or you can use short PHP tag in HTML code.
?>
<td class="blaa">
<?php echo $row['Navn']?><?php echo ($row['Formand'] == 1)?' (Formand)':'';?>
</td>
<?php
Try below code.
while($row = mysqli_fetch_array($rs))
{
echo '<tr class="lokbes">';
echo "<td class='blaa'>" . $row['Navn']." ".($row['Formand'] == 1 ? "(Formand)" : ""). "</td>"; // I want the extra text here.
echo "<td>" . $row['Stilling'] . "</td>";
echo "<td>" . $row['Institution'] . "</td>";
echo "<td><a href='mailto:$row[Email]'>" . $row['Email'] . "</a></td>";
echo "<td>" . $row['Mobiltelefon'] . "</td>";
}
echo "</tr>";
echo "</table>";
I have a table with different column. on of them is website, which should redirect me to a website when clicked upon. however it is looking the website up in my local host.
http://127.0.0.1:8090/test/http://www.amity.edu/mauritius/
it should be
http://www.amity.edu/mauritius/
here is the code for the table:
<?php
include ('db_connect.php');
$sql="select * from institution";
$result= mysqli_query($conn, $sql);
while ($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['ins_id'] . "</td>";
echo "<td>" . $row['ins_name'] . "</td>";
echo "<td>" . $row['address'] . "</td>";
echo "<td>" . $row['contact'] . "</td>";
echo "<td>" . $row['website'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "</tr>";
}
echo "</table>"
?>
What should i do to make it go to the website?
Thank you in advance.
Change this, use single quotes for href, and use protocol
$protocol = stripos($_SERVER['SERVER_PROTOCOL'],'https') === true ? 'https://' : 'http://';
echo "<td><a href='" $protocol. $row['website'] . "'>" . $row['website'] . "</a></td>";
You need to prepend your URL with http:// or https://
echo "<td><a href='http://" . $row['website'] . "'>" . $row['website'] . "</a></td>";
if variable $row['website'] has http:// in start,It will redirect to http://www.amity.edu/mauritius/ otherwise it will append local host url in start.
try this :
<?php
include ('db_connect.php');
$sql="select * from institution";
$result= mysqli_query($conn, $sql);
while ($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['ins_id'] . "</td>";
echo "<td>" . $row['ins_name'] . "</td>";
echo "<td>" . $row['address'] . "</td>";
echo "<td>" . $row['contact'] . "</td>";
echo "<td>" . $row['website'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "</tr>";
}
echo "</table>";
function addhttp($url) {
if (!preg_match("~^(?:f|ht)tps?://~i", $url)) {
$url = "http://" . $url;
}
return $url;
}
i need list something like this.
First table is display By using the this code.
<?php
if (isset($_REQUEST['asign'])) {
include 'includes/connection.php';
$sql12= $cid->query("SELECT name FROM user WHERE designation='Technical' AND status='1'");
$query = "SELECT * FROM allinone WHERE flag=3 ORDER BY id ASC";
$rs = $cid -> query($query);
$n = $rs -> num_rows;
echo "<br /><span style='color:red;'><center>$n records found</center></span>";
echo "<div id='record'>";
echo "<table border='1' width='80%' align='center' cellpadding='0' cellspacing='0' id='unsolTable'>";
echo "<tr>";
echo "<th>ID</th>";
echo "<th>Ticket Number</th>";
echo "<th>KOID</th>";
echo "<th>PROBLEM</th>";
echo "<th>COMMENT</th>";
echo "<th>DATE</th>";
echo "<th>TIME</th>";
echo "<th>STATUS</th>";
echo "<th>SOLVED BY</th>";
echo "<th>Assign</th>";
echo "<th>Assigned to</th>";
echo "</tr>";
while ($row = $rs -> fetch_assoc() ) {
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['token'] . "</td>";
echo "<td>" . $row['koid'] . "</td>";
echo "<td>" . $row['problem'] . "</td>";
echo "<td>" . $row['comment'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>" . $row['time'] . "</td>";
echo "<td>" . $row['status'] . "</td>";
echo "<td>" . $row['solvedBy'] . "</td>";
echo "<td><a href='assign.php?qType=technical&name=anshul&id=" . $row['id'] . "'>anshul</a>
<br />
<a href='assign.php?qType=technical&name=kiran&id=" . $row['id'] . "'>kiran</a>
<br />
<a href='assign.php?qType=technical&name=akhilesh&id=" . $row['id'] . "'>akhilesh</a></td>";
echo "<td>" . $row['assTo'] . "-" . $row['assTime'] . "-" . $row['assDate'] . "</td>";
echo "</tr>";
}
echo"</table>";
echo "</div>";
}
?>
On the another side is list on the assign i don't want to write it manually just get from the database how can i do this??
$sql= $cid->query("SELECT name FROM user WHERE designation='Technical' AND status='1'");
while ($row=$sql->fetch_assoc()) {
$name= $row['name'];
}
this is the another code i want to add in first code.
Nothing prevents you from executing another SQL query inside you while loop; just replace the echo...anshul...echo...kiran... part with another while loop containing the code you already provided.
You just have to make sure that you use different variables, otherwise your $row variable is overwritten by the second query. Hence, you can do something like this:
// ...
echo "<td>" . $row['solvedBy'] . "</td>";
$resultSetAssignedUsers = $cid->query("SELECT name FROM user WHERE designation = 'Technical' AND status = '1'");
while ($rowAssignedUsers = $resultSetAssignedUsers->fetch_assoc()) {
echo "<td><a href='assign.php?qType=technical&name=" . $rowAssignedUsers['name'] . "&id=" . $row['id'] . "'>" . $rowAssignedUsers['name'] . "</a>";
}
echo "<td>" . $row['assTo'] . "-" . $row['assTime'] . "-" . $row['assDate'] . "</td>";
// ...
$sql = ""
$result = mysql_query($sql);
while ($row = #mysql_fetch_row($result)) {
echo "<tr bgcolor='#dcdcdc'>" ;
echo "<td>$row[0] </td>";
echo "<td>" . $row[1] . "</td>";
echo "<td>" . $row[2] . "</td>";
echo "<td>" . $row[3] . "</td>";
echo "<td>" . $row[4] . "</td>";
echo "<td>" . $row[5] . "</td>";
echo "<td>" . $row[6] . "</td>";
}
when I run the above php code on my local mysql server , my last row value is correctly displayed.
But when the same is deployed on the server and access from client PC , last cell value is empty.
Please help me how to sort this issue out.
I think you're missing the trailing </tr> from your code, that could potentially do it:
while ($row = #mysql_fetch_row($result)) {
echo "<tr bgcolor='#dcdcdc'>" ;
echo "<td>$row[0] </td>";
echo "<td>" . $row[1] . "</td>";
echo "<td>" . $row[2] . "</td>";
echo "<td>" . $row[3] . "</td>";
echo "<td>" . $row[4] . "</td>";
echo "<td>" . $row[5] . "</td>";
echo "<td>" . $row[6] . "</td>";
echo "</tr>";
}
I'd check the database to make sure you have all of the rows in your table. That would pretty much have to be the problem.
Make sure you have at least 7 columns in there.