I'm having a dynamic data which is stored in a table in HTML..Now I need a hyperlink or button in every row of the table.so that I should perform some operations.
for($i = 0; $i < $index_pointer; $i++)
{
echo '<tr>';
echo "<td>". $brands[$i]. "</td>";
echo "<td>". $models[$i]. "</td>";
echo "<td>". $years[$i]. "</td>";
echo "<td>". $categories[$i]. "</td>";
echo "<td>". $frames_size[$i]. "</td>";
echo "<td>". $frames_type[$i]. "</td>";
echo "<td>". $wheels_size[$i]. "</td>";
echo "<td>". $colors[$i]. "</td>";
echo "<td>". $genders[$i]. "</td>";
echo "<td>". $origins[$i]. "</td>";
echo "<td>"."<a href=""/>"."</td>";
echo '</tr>';
}
How to achieve this?
I'll delete this answer immediatly if this is not what you want or if this isn't the issue but is this what you want?:
for($i = 0; $i < $index_pointer; $i++)
{
echo '<tr>';
echo "<td>". $brands[$i]. "</td>";
echo "<td>". $models[$i]. "</td>";
echo "<td>". $years[$i]. "</td>";
echo "<td>". $categories[$i]. "</td>";
echo "<td>". $frames_size[$i]. "</td>";
echo "<td>". $frames_type[$i]. "</td>";
echo "<td>". $wheels_size[$i]. "</td>";
echo "<td>". $colors[$i]. "</td>";
echo "<td>". $genders[$i]. "</td>";
echo "<td>". $origins[$i]. "</td>";
echo "<td><a href='URL'>The text that's clickable</a></td>";
echo '</tr>';
}
Read more here: http://www.w3schools.com/tags/tag_a.asp
Try this.
mysql_connect("localhost", "root", "ameex") or die(mysql_error());
mysql_select_db("admin") or die(mysql_error());
$result =
mysql_query("SELECT * FROM details") or die(mysql_error());
echo "";
echo " TitleImageDescription"; $dir="images/";
while($row = mysql_fetch_array( $result )) {
echo "";
echo $row['title'];
echo "";
echo "<img src='$dir/$row[image]' width=100px height=100px><br>";
echo"</td><td>";
echo $row['description'];
echo '<td>Edit</td>
<td>Delete</td>';
echo "</td></tr>"; }
Related
I have a PDO connection to a database that returns any results for an item number that is searched. It currently returns each instance in its own table but i would like to see all instances in one table. Here is my code.
if (count($resultssample) > 0) {
echo "<br>";
echo "Number in the business: ".count($resultssample)."<br>";
echo "<br>";
foreach ($resultssample as $r) {
echo "<table>";
echo "<thead>";
echo "<tr>";
echo "<th>site name</th>";
echo "<th>location name</th>";
echo "<th>creation time</th>";
echo "<th>creation date</th>";
echo "<th>damage status</th>";
echo "<th>colour</th>";
echo "<th>inventory status</th>";
echo "<th>notes</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
echo "<tr>";
echo "<td>". $r['site_name'] ."</td>";
echo "<td>". $r['location_name'] ."</td>";
echo "<td>". $r['CreationTime'] ."</td>";
echo "<td>". $r['CreationDate'] ."</td>";
echo "<td>" . $r['damage_status'] . "</td>";
echo "<td>" . $r['colour'] . "</td>";
echo "<td>" . $r['inventory_status'] . "</td>";
echo "<td>" . $r['Notes'] . "</td>";
echo "</tr>";
echo "</tbody>";
echo "</table>";
}
} else {
echo "No results found";
}
How can this be achieved I cant currently get my head around it.
Any help would be greatly appreciated.
All you have to do is move table header out of the foreach loop:
if (count($resultssample) > 0) {
echo "<br>";
echo "Number in the business: ".count($resultssample)."<br>";
echo "<br>";
echo "<table>";
echo "<thead>";
echo "<tr>";
echo "<th>site name</th>";
echo "<th>location name</th>";
echo "<th>creation time</th>";
echo "<th>creation date</th>";
echo "<th>damage status</th>";
echo "<th>colour</th>";
echo "<th>inventory status</th>";
echo "<th>notes</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
foreach ($resultssample as $r) {
echo "<tr>";
echo "<td>". $r['site_name'] ."</td>";
echo "<td>". $r['location_name'] ."</td>";
echo "<td>". $r['CreationTime'] ."</td>";
echo "<td>". $r['CreationDate'] ."</td>";
echo "<td>" . $r['damage_status'] . "</td>";
echo "<td>" . $r['colour'] . "</td>";
echo "<td>" . $r['inventory_status'] . "</td>";
echo "<td>" . $r['Notes'] . "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
} else {
echo "No results found";
}
Here's my database connection code.
I want to display the blob image into td
<?php while ($news = mysql_fetch_assoc($content))
{
echo "<tr>";
echo "<td>" .$news['<img src = "data:image/jpg;base64,'.base64_encode($img).'"/>']. "</td>";
echo "</td>";
echo "<tr>";
echo "<td>" .$news['title']."</td>";
echo "</td>";
echo "<tr>";
echo "<td>" .$news['content']."</td>";
echo "</td>";
echo "<tr>";
echo "<td>" .$news['date']."</td>";
echo "</td>";
echo "<tr>";
echo "<td>" .$news['author']."</td>";
echo "</td>";
}
?>
and I got a error says undefined index
You have a typo in your code. Change your line :
echo "<td>" .$news['<img src = "data:image/jpg;base64,'.base64_encode($img).'"/>']. "</td>";
By
echo "<td><img src='data:image/jpg;base64,".base64_encode($news['img'])."'/></td>";
I am echoing to my website possible checkbox values that are in a table JobChoose like this
<?php
$got = mysql_query("SELECT * FROM JobChoose");
$checkbox = '';
while ($row = mysql_fetch_assoc($got)) {
$checkbox .= '<li><input type="checkbox" id="Jobselect" name="Job" value = "' . $row['Job'] . '">' . $row['Job'] . '</input></li>';
} ?>
<?php echo $checkbox;?>
When a checkbox is selected is inserted to a customer info.
But when i am trying to to get selected value back nothing appears when i click to a customer although it appears in mysql database
echo "<td align='center' class='hidden'>". $row["Job"] ."</td>";
<script type='text/javascript'>
$('#tabled').on('click', 'tr', function () {
$("#Jobselect").val($(this).find("td").eq(19).html());
});
</script>
Also i fetch search results into a table like this
<?php
$sql = "SELECT * FROM new_record WHERE surname LIKE
'%".$_POST["search"]."%' or name LIKE'%".$_POST["search"]."%' or
barcode LIKE'%".$_POST["search"]."%'"; $result =
mysqli_query($connect, $sql); if(mysqli_num_rows($result) > 0) {
while($row = $result->fetch_assoc()){
echo "<tr>";
echo "<td >". $row["id"] ."</td>";
echo "<td>". $row["surname"] ."</td>";
echo "<td>". $row["name"] ."</td>";
echo "<td>". $row["company_name"] ."</td>";
echo "<td>". $row["firm"] ."</td>";
echo "<td>". $row["address"] ."</td>";
echo "<td>". $row["town"] ."</td>";
echo "<td>". $row["tk"] ."</td>";
echo "<td>". $row["country"] ."</td>";
echo "<td>". $row["telephone"] ."</td>";
echo "<td>". $row["fax"] ."</td>";
echo "<td>". $row["mobile"] ."</td>";
echo "<td>". $row["mail"] ."</td>";
echo "<td>". $row["web_site"] ."</td>";
echo "<td>". $row["barcode"] ."</td>";
echo "<td>". $row["visitors"] ."</td>";
echo "<td align='center' class='hidden'>". $row["custId"] ."</td>";
echo "<td align='center' class='hidden'>". $row["trn_date"] ."</td>"; echo "<td align='center' class='hidden'>".
$row["HowToFindUs"] ."</td>"; echo "<td align='center'
class='hidden'>". $row["Job"] ."</td>";
echo "</tr>";
} } else {
echo 'Data Not Found'; } ?>
To get selected checkbox value you should try below code :
<?php
$got = mysql_query("SELECT * FROM JobChoose");
$checkbox = '';
while ($row = mysql_fetch_assoc($got)) {
$checkbox .= '<li><input type="checkbox" name="Job[]" value = "' . $row['Job'] . '">' . $row['Job'] . '</input></li>';
} ?>
<?php echo $checkbox;?>
Here in your case you have place id for all checkboxes are same which was not correct.
Also in JS you should try below code :
echo "<td align='center' class='hidden'>". $row["Job"] ."</td>";
<script type='text/javascript'>
$('input[type=checkbox]').click(function () {
if($(this).is(':checked')) {
alert($(this).val());
}
});
</script>
Please try this.
Solved !!!
I passed data to table with
echo "". $row["Job"] ."";
And then
$('input[type=checkbox]').each(function(){ var str =
$('#check').val(); var strarray = str.split(',');
if($.inArray($(this).val(),strarray)!=-1){
$(this).prop("checked","checked"); } else {
$(this).prop("checked",""); } });
I have a mysql table with a row that is either going to be a 0 or a 1. However, I want to be able to display the table with PHP and have 0 show up as no, and 1 show up as yes. I am still a beginner with PHP and have been searching for a way to do it, but have had no luck. The row in question is the 'masterwork' row. The line of code I thought would do it is
$row['masterwork'] = ( intval( $row['masterwork']) == 1) ? "YES" : "NO";
Here is the code that displays the table:
<?php
$con=mysqli_connect("localhost","username","password","database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM weapons");
$row['masterwork'] = ( intval( $row['masterwork']) == 1) ? "YES" : "NO";
while($row = mysqli_fetch_array($result))
{
echo "<center>";
echo "<table border='1' class='display'>";
echo "<tr>";
echo "<td>Weapon Name: </td>";
echo "<td>" . $row['weaponName'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Creator: </td>";
echo "<td>" . $row['creator'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Weapon Category: </td>";
echo "<td>" . $row['weaponCategory'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Weapon Sub-Category: </td>";
echo "<td>" . $row['weaponSubCategory'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Cost: </td>";
echo "<td>" . $row['costAmount'] . " " . $row['costType'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Damage(S): </td>";
echo "<td>" . $row['damageS'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Damage(M): </td>";
echo "<td>" . $row['damageM'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Critical: </td>";
echo "<td>" . $row['critical'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Range Increment: </td>";
echo "<td>" . $row['rangeIncrement'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Weight: </td>";
echo "<td>" . $row['weight'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Weapon Type: </td>";
echo "<td>" . $row['weaponType'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Masterwork: </td>";
echo "<td>" . $row['masterwork'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Special Abilities: </td>";
echo "<td>" . $row['specialAbilities'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Additional Info: </td>";
echo "<td>" . $row['additionalInfo'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "</center>";
mysqli_close($con);
?>
try this --
$result = mysqli_query($con,"SELECT * FROM weapons");
while($row = mysqli_fetch_array($result))
{
$row['masterwork'] = ( intval( $row['masterwork']) == 1) ? "YES" : "NO";
echo "<center>";
echo "<table border='1' class='display'>";
echo "<tr>";
echo "<td>Weapon Name: </td>";
echo "<td>" . $row['weaponName'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Creator: </td>";
echo "<td>" . $row['creator'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Weapon Category: </td>";
echo "<td>" . $row['weaponCategory'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Weapon Sub-Category: </td>";
echo "<td>" . $row['weaponSubCategory'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Cost: </td>";
echo "<td>" . $row['costAmount'] . " " . $row['costType'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Damage(S): </td>";
echo "<td>" . $row['damageS'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Damage(M): </td>";
echo "<td>" . $row['damageM'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Critical: </td>";
echo "<td>" . $row['critical'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Range Increment: </td>";
echo "<td>" . $row['rangeIncrement'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Weight: </td>";
echo "<td>" . $row['weight'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Weapon Type: </td>";
echo "<td>" . $row['weaponType'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Masterwork: </td>";
echo "<td>" . $row['masterwork'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Special Abilities: </td>";
echo "<td>" . $row['specialAbilities'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Additional Info: </td>";
echo "<td>" . $row['additionalInfo'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "</center>";
mysqli_close($con);
?>
I have created a search function. It can find address by the full text but how do I go about to make the query search by parts of the address ? For e.g. the full address is paya lebar Road Blk27, how do I make it so that the user can just type in paya and it would still show up ?
SearchForm
<h2>View Patient Records</h2>
<body>
<form action="display_patient.php" method="post">
<p>Select:
<select name="patient_var" >
<?php
$value = array(view_all, name, address);
foreach ($value as $option)
{
echo '<option value="'.$option.'"' . (isset($_POST['patient_var']) && $_POST['patient_var'] == $option ? ' selected' : '') . '>' . $option . '</option>';
}
?>
</select>
<input type="text" name="typed" value="" />
<input type ="submit" value="submit" />
</form>
</p>
<p>
<?php
if (isset($_POST['patient_var'])) {
$type = $_POST['typed'];
$select = $_POST['patient_var'];
if ($select == 'view_all') {
echo "<table border='1'>";
echo "<tr>\n";
echo "<th>ID</th>\n";
echo "<th>Patient Name</th>\n";
echo "<th>Age</th>\n";
echo "<th>NRIC</th>\n";
echo "<th>Birth Date</th>\n";
echo "<th>Medical Allergies</th>\n";
echo "<th>Medical History</th>\n";
echo "<th>Phone</th>\n";
echo "<th>Address</th>\n";
echo "<th>Doctor Assigned</th>\n";
echo "</tr>";
$pat_set = default_patient();
while ($mo = mysqli_fetch_array($pat_set)) {
echo "<tr>";
echo "<td>" . $mo['id'] . "</td>";
echo "<td>". $mo['name'] . "</td>";
echo "<td>". $mo['age'] . "</td>";
echo "<td>". $mo['nric'] . "</td>";
echo "<td>". $mo['birthdate'] . "</td>";
echo "<td>". $mo['medical_allergies'] . "</td>";
echo "<td>". $mo['medical_history'] . "</td>";
echo "<td>". $mo['phone'] . "</td>";
echo "<td>". $mo['address'] ."</td>";
echo "<td>". $mo['doctor_assigned'] . "</td>";
echo "</tr>";
}
}
else {
echo "<table border='1'>\n";
echo "<tr>\n";
echo "<th>ID</th>\n";
echo "<th>Patient Name</th>\n";
echo "<th>Age</th>\n";
echo "<th>NRIC</th>\n";
echo "<th>Birth Date</th>\n";
echo "<th>Medical Allergies</th>\n";
echo "<th>Medical History</th>\n";
echo "<th>Phone</th>\n";
echo "<th>Address</th>\n";
echo "<th>Doctor Assigned</th>\n";
echo "</tr>";
$patients_set =
find_patients($select, $type);
while ($row = mysqli_fetch_array($patients_set))
{ echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>". $row['name'] . "</td>";
echo "<td>". $row['age'] . "</td>";
echo "<td>". $row['nric'] . "</td>";
echo "<td>". $row['birthdate'] . "</td>";
echo "<td>". $row['medical_allergies'] . "</td>";
echo "<td>". $row['medical_history'] . "</td>";
echo "<td>". $row['phone'] . "</td>";
echo "<td>". $row['address'] ."</td>";
echo "<td>". $row['doctor_assigned'] . "</td>";
echo "</tr>"; }
}
}//end of if post submit
?>
</p>
In Mysql For searching whether a column has specific string use LIKE
Example
SELECT * FROM table WHERE column LIKE '%somestring%';
In your case just try this
$typed = $_POST['typed'];
and make Mysql query like this
$query = "select * from table where Address LIKE '%".$typed."%' ";
Use LIKE '%$searchParam%' instead of = $searchParam
You forgot to post your function: find_patients($select, $type);
But I guess you need a partial string query for an address varchar field which looks something like this:
select * from MyTable where myColumn like '%myPartialString%';
This type of query will return all rows that have "MyPartialString" within.