I have a MySql database online for transcriptions of document images. Those images are located on another website. I want to include the link to the actual image in the database so that the person researching can click the link and go directly to the image.
I have done the following:
Created a column named IMAGE
In my excel spreadsheet that will be uploaded via ODBC to PhpMyAdmin for my datbase, i have included the IMAGE
When the file is uploaded via ODBC, I can see the link in the Table on PhpMyAdmin for my database.
I have also included the IMAGE column to be shown on my results page and the column does appear.
But the hyperlink does NOT appear at all on the results page for any entry that has a link in the Image column so there is nothing to click on to go directly to the image
What am I doing wrong?
I wrote this up quickly to try and help you out. You will need to change DBHOST, DBUSERNAME, yourtablename etc to your databases information.
<?php
$con=mysqli_connect("DBHOST","DBUSERNAME","DBPASSWORD","DBNAME");
$result = mysqli_query($con,"SELECT * FROM 'yourtablename'");
echo "<table border='1'>
<tr>
<th>Notes</th>
<th>Image</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['NOTES'] . "</td>";
echo "<td>" . $row['IMAGE'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
Edit: Here is an alternate solution that will put the link formatting in for you.
I wrote this up quickly to try and help you out. You will need to change DBHOST, DBUSERNAME, yourtablename etc to your databases information.
<?php
$con=mysqli_connect("DBHOST","DBUSERNAME","DBPASSWORD","DBNAME");
$result = mysqli_query($con,"SELECT * FROM 'yourtablename'");
echo "<table border='1'>
<tr>
<th>Notes</th>
<th>Image</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['NOTES'] . "</td>";
echo "<td><a href='" . $row['IMAGE'] . "'>Link</a></td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
Related
Here is the code I'm using that is pulling all data fields nicely from mysql database. But email addresses are being displayed as user%40domainname.com instead of standard email output of user#domainname.com.
$myData = mysql_query($sql);
echo "<table class='table table-hover table-bordered table-striped'>
<tr>
<th>Username</th>
<th>Email</th>
<th>Score</th>
</tr>";
while($record = mysql_fetch_array($myData)) {
echo "<tr>";
echo "<td>" . $record['id'] . "</td>";
echo "<td>" . $record['email'] . "</td>";
echo "<td>" . $record['score'] . "</td>";
echo "</tr>";
}
echo "</table>";
You can use urldecode to solve this:
$email = 'user%40domainname.com';
echo urldecode($email); //user#domainname.com
demo: http://ideone.com/hEdpxk
... or in your case you can use the following while loop:
while($record = mysql_fetch_array($myData)) {
echo "<tr>";
echo "<td>" . $record['id'] . "</td>";
echo "<td>" . urldecode($record['email']) . "</td>";
echo "<td>" . $record['score'] . "</td>";
echo "</tr>";
}
I've made a button, here is the piece of code (bootstrap):
<span class="glyphicon glyphicon-download-alt"></span> Download
And this piece of mysql code, which contains a few links:
<?php
$con=mysqli_connect("localhost","admin","admin133","kernel");
if (mysqli_connect_errno())
{
echo "Error bij connecten: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM hack ORDER BY ID DESC ");
echo "<table border='0'>
<tr>
<th>Name</th>
<th>Status</th>
<th>Retepreter</th>
<th>Kwikie</th>
<th>Nevermind</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['kakatoeee'] . "</td>";
echo "<td>" . $row['kakatoe2'] . "</td>";
echo "<td>" . $row['kakatoe'] . "</td>";
echo "<td>" . $row['papaja'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
Now, my question is, how do I make it so that the links connect to the bootstrap buttons? (Sorry if I'm a bit unclear, I'm Dutch an it's pretty hard to type in English)
papaja, kakatoe etc. is my http!
I am trying to load articles from 1 to 5 on the homepage of this website.
When loading the homepage, only results from ID 2 to 5 vs. 1 to 5 are getting displayed and I'm not sure why. It seems there probably is a problem with my while loop but I can't seem to figure it out.
I have added a link to a screenshot of the database to show that there is in fact an article with the ID 1 and I've also added a link to the website itself.
Database in question
Website in question
<div class="bodymainwrap">
<div class="contentwrap">
<?php
if (isset($_GET['id']) && !empty($_GET['id'])) {
$page = "between " . (($_GET['id']*5)-5) . " and " . ($_GET['id']*5);
} else {
$page = "between 1 and 5";
}
require_once '/db.connect';
$query = "SELECT * FROM Articles where id " . $page;
$result = mysqli_query($link, $query);
if (!$result) {
echo "<br />" . $query;
die("<br/> Error: occured while trying to execute the query " . mysqli_error($link));
}
$row = mysqli_fetch_array($result)
?>
<div class="sidebar" align="center">
<a href="/nothing/index.php?id=2" >Page 2</a>
<?php echo $query ?>
</div>
<?php
while ($row = mysqli_fetch_array($result)){
echo '<div class="entry">';
echo '<img src="/nothing/images/julie.jpg">';
echo'<H2>';
echo $row['Title'];
echo'</h2>';
echo '<p>';
echo $row['Article'];
echo '</p>';
echo '</div>';
}
?>
</div>
Your issue is here I believe, with the lone mysqli_fetch_array call after you get $result
$result = mysqli_query($link, $query);
if (!$result) {
echo "<br />" . $query;
die("<br/> Error: occured while trying to execute the query " . mysqli_error($link));
}
$row = mysqli_fetch_array($result) //delete this
Here you have already fetched the first row. Remove that, and just keep it within the loop. That's the underlying reason for how the while loop works. It keeps advancing while mysqli_fetch_array doesn't return null.
I have the following code and the plan is to display the data from the database but allow for the administrator of the site to delete a row if a job is no longer available. I have put "Delete" where I would like a link to delete the row.I have tried using <a href='delete1.php?del=$row[JobID]'>Delete</a> but that just throws an error up on the page.
<?php
include_once('db.php');
$result = mysqli_query($con,"SELECT * FROM Job ORDER BY JobID");
echo "<table border='1'>
<tr>
<th>Job ID</th>
<th>Job Title</th>
<th>Job Description</th>
<th>Industry</th>
<th>Job Type</th>
<th>Salary</th>
<th>County</th>
<th>Town</th>
<th>Delete</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['JobID'] . "</td>";
echo "<td>" . $row['JobTitle'] . "</td>";
echo "<td>" . $row['JobDescription'] . "</td>";
echo "<td>" . $row['Industry'] . "</td>";
echo "<td>" . $row['JobType'] . "</td>";
echo "<td>" . $row['Salary'] . "</td>";
echo "<td>" . $row['County'] . "</td>";
echo "<td>" . $row['Town'] . "</td>";
echo "<td>" . "Delete" . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
You should put this in the the listing code:
echo "<a href='delete1.php?del={$row['JobID']}'>Delete</a>";
(documentation)
Then, in your delete1.php you should have something like:
$jobid = intval($_GET['JobID']);
if ($jobid > 0) {
mysqli_query($con, "DELETE FROM Job WHERE JobID=$jobid LIMIT 1");
}
(note: this is untested and can be quite insecure; it only shows the concept on how to do this)
How do I fill an inputbox with mysql data. So that I can update the database?
I have this code that will show the table corresponding to the users request. But I don't know the syntax on how I can fill an inputbox with mysql data.
$result = mysql_query("SELECT * FROM t2 WHERE STAT='{$_POST["stat1"]}'");
echo "<table border='1'>
<tr>
<th>HospNum</th>
<th>RoomNum</th>
<th>LastName</th>
<th>FirstName</th>
<th>MidName</th>
<th>Address</th>
<th>TelNum</th>
<th>Status</th>
<th>Nurse</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['HOSPNUM'] . "</td>";
echo "<td>" . $row['ROOMNUM'] . "</td>";
echo "<td>" . $row['LASTNAME'] . "</td>";
echo "<td>" . $row['FIRSTNAME'] . "</td>";
echo "<td>" . $row['MIDNAME'] . "</td>";
echo "<td>" . $row['ADDRESS'] . "</td>";
echo "<td>" . $row['TELNUM'] . "</td>";
echo "<td>" . $row['STAT'] . "</td>";
echo "<td>" . $row['NURSE'] . "</td>";
echo "";
}
echo "";
And I want to display the corresponding records with this html form, by inputting a primary key. And clicking the search button, the record will appear on each box. Just like when you update mysql database through phpmyadmin. But this time using a custom html form.
<td width="168"><input name="hnum" type="text" id="hospnum"></td>
<td width="41"><font size="3">Room #</td>
<td width="3">:</td>
<td width="168"><input name="rnum" type="text" id="rnum"></td>
how can I do that?
<input name="hnum" type="text" id="hospnum" value="<?php echo $row['ROOMNUM']; ?>" />
In text field you have fill the value attribute with php fetched attribute value
echo "<input name='rnum' type='text' id='rnum' value =".$row['ROOMNUM'].">";