I have been working on trying to teach myself programming and have come stuck on a simple problem ,
the line I am working with is
echo "<td>" . $row['website'] . "</td>";
only in the database {mysql} it is in plain text under the column 'website' , I have been trying to work out how to make the row website clickable for the whole table,
i have tried <href ="echo "<td>" . $row['website'] . "</td>"";
I have tried searching the web for an answer , only i dont seem to be able to phrase the question for the right results.
thank you .
I also tried
<?
$result = mysql_query("SELECT * FROM leader");
echo "<table border='1'> <tr> <th>id</th> <th>Club</th> <th>Website</th> <th>Club Badge</th> </tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr>"."<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['club'] . "</td>";
echo "<td>" . $row['website' ] . "</td>";
echo "<td><a class=\"mylink\" href=\"" . $row['website'] . "\">" . $row['website'] . "</a></td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
but still got Parse error: syntax error, unexpected '<' in /home/a6332763/public_html/res.php on line 29
UPDATE......... Have now got link to show in right box only its adding the sites url in-front of the links url, here is the code , minus mysqul connection .
<?php
$result = mysql_query("SELECT * FROM leader");
echo "<table border='1'>
<tr>
<th>id</th>
<th>Club</th>
<th>Website</th>
<th>Club Badge Url</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>"."<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['club'] . "</td>";
echo "<td><a class=\"mylink\" href=\"" . $row['website'] . "\">" . $row['website'] . "</a></td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
<html>
<body>
Link text
Click on this link to run your first PHP script.
</body>
</html>
Anchor tags (<a>) cannot contain table rows or cells. To make the entire row clickable, you must bind an onclick handler with JavaScript or wrap the contents of each individual <td> element with its own <a> tag.
If what you are looking for is a way to make a link out the area of the row where your links is do the following:
In the PHP file:
echo "<td><a class=\"mylink\" href=\"" . $row['website'] . "\">" . $row['website'] . "</a></td>";
In the CSS file:
.mylink{display:block;}
That should do it.
Fill the appropriate onclick attribute with JavaScript code to open the new location.
If you just want the a regular link inside a table cell what you want is
<td><?= $row['website'] ?></td>
If you were actually trying to make the entire table row clickable, you need to use a javascript redirect set on the table row:
<tr onClick="window.location='<?= $row['website'] ?>'">
<td><?= $row['website'] ?></td>
</tr>
Related
I have a page which contains a table. The 'change_id' field contains hyperlinks which direct the user to a different page with an overview of that change_id's details.
'<td>' . $row['change_id'] . '</td>';
Now, just to test that the change_id is being received on the home2.php page, I used the following code:
<?php
include 'config.php';
$change_id=$_GET['change_id'];
print_r($_GET);
?>
This test successfully displayed the correct change id's:
Array ( [changeid] => 1006 )
Now, when I go to query the SQL Database using the change_id it doesn't work as desired.
<?php
include 'config.php';
$change_id=$_GET['change_id'];
$query1 = "SELECT * FROM `change_request_tbl` WHERE `change_id` = $change_id";
$result = mysqli_query($conn, $query1);
echo "<fieldset><legend><strong>New Requests:</legend></strong>
<table border=4 bordercolor=black class=table>
<tr>
<th>Change ID:</th>
<th>Customer Name:</th>
<th>Change Requestor:</th>
<th>Date CR raised:</th>
<th>CPM/Ticket:</th>
<th>Out of Hours:</th>
<th>Change Category:</th>
</tr>";
while ($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['change_id'] . "</td>";
echo "<td>" . $row['customer_name'] . "</td>";
echo "<td>" . $row['change_requestor'] . "</td>";
echo "<td>" . $row['date_cr_raised'] . "</td>";
echo "<td>" . $row['cpm_ticket'] . "</td>";
echo "<td>" . $row['out_of_hours'] . "</td>";
echo "<td>" . $row['category_of_change'] . "</td>";
echo "</tr>";
}
echo "</table></fieldset><br><br><br>";
?>
The table are headers are shown without any data. Any ideas on how to fix? Thanks in advance
You are setting $change_id to $_GET['change_id']
However you are passing $_GET the parameter name of changeid
If you change
$change_id = $_GET['change_id'];
To
$change_id = $_GET['changeid'];
It should work as expected :)
I am working on uploading a file along with a description and table and then displaying it in a table format. My problem is that I'm not sure how to link my the path for the uploaded file into the table so the user can click on the link in the table and it will download.
Code:
This is what I'm attempting to use>
<?php
include 'connect.php';
$result = mysqli_query($con,"SELECT DocDate, Description, DocFile FROM Documents");
echo "<table border='0' width='100%'>
<col width='50'>
<col width='100'>
<tr>
<th>Date</th>
<th>Description</th>
<th>File</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['DocDate'] . "</td>";
echo "<td>" . $row['Description'] . "</td>";
echo "<td>" $row['DocFile'] "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
If you feel it to be usefull I'm happy to add the code where I upload the file to my server.
EdiT Sorry I put in the wrong variable thing into my table, I don't think it changes it too much
Is this what you're looking for?
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['DocDate'] . "</td>";
echo "<td>" . $row['Description'] . "</td>";
echo "<td> " . $row['DocFile'] . " </td>";
echo "</tr>";
}
This is how you can do
echo '<td>'.$name.'</td>';
I prefer to use ' ' and within it have the HTML since HTML will contain a lot of "" so no need to use escape them and then separate PHP and HTML with concatenation.
you have syntax error in this line in while loop:
echo "<td>" $name "</td>";
should be :
echo "<td> $name </td>";
In this line you have an error:
echo "<td>" $row['DocFile'] "</td>";
You need to scape the " character:
echo "<td> " . $row['DocFile'] . " </td>";
With your syntax you are creating an error because you are ending the string after the td tag.
If you are using a web url which uses a php variable in the url and want to open a new tab when you click on the hyper link, use this
echo "<td><a target='_blank' href=\"http://view.php?Id=".$row['Id']."\">". $row['Id'] ."</a></td>";
This is helpful when you have to use a php variable in the hyperlink and is being used in a table. Clicking on the Id will open the page related to that Id in a new tab in this case.
best regards.
I know perhaps some's considering my question is quite stupido. But I've been trying looking for to this simple scripting. As my post title above, how to make the query results into a url. I have this scripts:
$result = mysqli_query($con,'SELECT......');
echo "<table border='1'>
<tr>
<th>Title</th>
<th>Author</th>
<th>Publisher</th>
<th>Category</th>
<th>Link</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['title'] . "</td>";
echo "<td>" . $row['author_name'] . "</td>";
echo "<td>" . $row['publisher_name'] . "</td>";
echo "<td>" . $row['cat_name'] . "</td>";
echo "<td>" . $row['url_flipbook'] . "</td>";
echo "</tr>";
}
echo "</table>";
I want to make the result from $row ->'url_flipbook' into a url. The $row -> 'url_flipbook' will produce a html pages that users can click on it, it's located to a folder in my localhost.
The database field:
| url_flipbook |
-----------------
/myspace/click-it/info_1.html
I want that query results became a link for the output.
I've tried:
<a href=''echo $row['url_flipbook'];'?>''>FLIPBOOK</a>"</td>";
echo "<td>" . <a href='$row['url_flipbook']>FLIPBOOK</a>"</td>";
Nothing works...if you could help me to solve this problems. Thank you so much...
best regards,
Kris
Just concat the string to the href:
echo "<td>FLIPBOOK</td>";
or alternatively:
echo '<td>FLIPBOOK</td>';
did u try
echo "<td>" . "<a href='" . $row['url_flipbook'] . "' >FLIPBOOK</a></td>";
try this
echo "<td><a href='".$row['url_flipbook']."'>FLIPBOOK</a></td> ";
Please kindly look into my code and help me fix the errors in my code. only my first data displays on the table on my view page but the other data displays on the view page not on the table.
my image name and the image itself successfully inserted in my database and my image directory which i name "upload" but the image wont display on my view page.
<?php
include ("config.php");
// Retrieve data from database
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
echo "<table border='1'>
<tr>
<th>id</th>
<th>firstname</th>
<th>lastname</th>
<th>address</th>
<th>nationality</th>
<th>accountnumber</th>
<th>accounttype</th>
<th>balance</th>
<th>passport</th>
<th>username</th>
<th>passport</th>
<th>update</th>
<th>delete</th>
</tr>";
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['address'] . "</td>";
echo "<td>" . $row['nationality'] . "</td>";
echo "<td>" . $row['account'] . "</td>";
echo "<td>" . $row['accounttype'] . "</td>";
echo "<td>" . $row['balance'] . "</td>";
echo "<td><h1><img src=\"upload/\" height=35 width=35 /> $row[id]</h1></td>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['password'] . "</td>";``
echo "<td>update</td>";
echo "<td>delete</td>";
echo "</table>";
// close while loop
}
?>
With a quick view, I see you are closing the table inside the while loop. You should change it for a
</tr>
and remember using the thead and tbody tags.
Close tbody and table after ending the loop.
This needs to be outside your while loop.
echo "</table>";
And
<img src=\"upload/\"
Is only pointing to the upload directory, you aren't specifying an actual image. Try something like:
echo "<td><h1><img src=\"upload/$row['image']\" height=35 width=35 /> $row['id']</h1></td>";
Moving the table closing tab out side the while loop will solve the first issue.
Change the code as follows to solve the image problem.
echo '<td><img src="upload/'.$row['your image name'].'" height=35 width=35 ></td>';
Your code should be as follows.
<?php
include ("config.php");
// Retrieve data from database
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
echo "<table border='1'>
<tr>
<th>id</th>
<th>firstname</th>
<th>lastname</th>
<th>address</th>
<th>nationality</th>
<th>accountnumber</th>
<th>accounttype</th>
<th>balance</th>
<th>passport</th>
<th>username</th>
<th>passport</th>
<th>update</th>
<th>delete</th>
</tr>";
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['address'] . "</td>";
echo "<td>" . $row['nationality'] . "</td>";
echo "<td>" . $row['account'] . "</td>";
echo "<td>" . $row['accounttype'] . "</td>";
echo "<td>" . $row['balance'] . "</td>";
echo '<td><img src="upload/'.$row['your image name'].'" height=35 width=35 ></td>';
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['password'] . "</td>";``
echo "<td>update</td>";
echo "<td>delete</td>";
echo "</tr>";
// close while loop
}
echo "</table>";
?>
i am having a little difficulty in displaying my id info on my update page. i have two entries 6 and 7 if i click update on id 6 , it will show on my update page but if i click update on id 7, on the address bar, it will indicate that the id =7 but it will still show id 6 infos.
here is my display code that display data on my update page
<?ph
include ('config.php');
// Retrieve data from database
$sql="SELECT * FROM $tbl_name ";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
?>
secondly if i change data my update page, the change wont reflect on my view page.
<?php
include('config.php');
//This is the directory where images will be saved
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$address=$_POST['address'];
$nationality=$_POST['nationality'];
$accountnumber=$_POST['account'];
$accounttype=$_POST['accounttype'];
$balance=$_POST['balance'];
$username=$_POST['username'];
$password=$_POST['password'];
$id=$_POST['id'];
// update data in mysql database
$sql="UPDATE $tbl_name SET firstname='$firstname', lastname='$lastname', address='$address', nationality='$nationality',accountnumber='$account',accounttype='$accounttype',balance='$balance',username='$username',password='$password'
WHERE id='$id'";
$result=mysql_query($sql);
header ("Location: details.php");
?>
I have a code that populates data from a mysql table into an html table. I also have a text box and a button at the end of each row. I want to send all the variables in the row including the text in the textbox to update.php. Could not do that somehow. Here is the code I am trying. Please help. I can send it through GET method. But I want to use POST.
<?php
require 'config.php';
mysql_connect ($dbhost, $dbusername, $dbuserpass);
mysql_select_db($dbname) or die('Cannot select database');
$query = "SELECT * FROM cust_info;";
$result = mysql_query($query) or die(mysql_error());
echo "</br>";
echo "<table border='1'>
<tr>
<th>Pop Code</th>
<th>Open_Date</th>
<th>Maturity_Date</th>
<th>Amount</th>
<th>Balance</th>
<th>Collection Amount</th>
</tr>";
while($row1 = mysql_fetch_array($result))
{
echo "<div class=\"addform\"><form method='post' action=\"update.php?upd=".$row1['pop_code']."\">\n";
echo "<tr>";
echo "<td>" . $row1['pop_code'] . "</td>";
echo "<td>" . $row1['open_date'] . "</td>";
echo "<td>" . $row1['mat_date'] . "</td>";
echo "<td>" . $row1['depoamt'] . "</td>";
echo "<td>" . $row1['balance'] . "</td>";
echo "<td>" . " <input type=\"text\" name=\"amount\"/>\n" . "</td>";
echo "<td>" . " <input type=\"image\" src=\"images/update.png\" alt=\"Update Row\" class=\"update\" title=\"Update Row\">\n" . "</td>";
echo "</tr>";
echo "</form></div>";
}
echo "</table>";
?>
Change your table code to something like this:
echo "<td><input type='hidden' name='pop_code' value='".$row1['pop_code']."'>" . $row1['pop_code'] . "</td>";
It looks like your code isn't actually sending anything, just displaying it on the page. This will display it as well as sending a hidden field when the form is submitted.
Edit: Another way to do it would be to have a single form on your page outside your loop and have the button run a javascript function that copies the data to the form and submits the form. Probably easier the way you have it at the moment, but a javascript like that would be able to pick up other information off the user/page easily and send it via a single form to the next page.
You can make the fields hidden:
echo "<td><input type='hidden' name='pop_code' value='" . $row1['pop_code'] . "' />" . $row1['pop_code'] . "</td>";
echo "<td><input type='hidden' name='open_date' value='" . $row1['open_date'] . "' />" . $row1['open_date'] . "</td>";
your HTML is broken, <table> only allows <thead>, <tbody>, <tfoot> and <tr> as direct children, try fix this first because this will cause your Browser to close Tags automatically