Id from PHP not being passed to URL - php

I have some data displayed from SQL to PHP, when the user clicks the eye icon, he is redirected to another page with id on the URL, I did the following code
<tr>
<td><?php echo $record['id']; ?></td>
<td><?php echo $record['firstname'];?></td>
<td><?php echo $record['Email'];?></td>
<td><?php echo $record['mobilenumber']?></td>
<td><?php echo $record['company']?></td>
<td><?php echo $record['designation']?></td>
<td><?php echo $record['state']?></td>
<td><i class="fa fa-eye" aria-hidden="true"></i></td>
</tr>
<?php } ?>
Instead of the id, some special characters are coming in the URL, how can I fix it?

Below is how your anchor tag should be.
<i class="fa fa-eye" aria-hidden="true"></i>
You need to enclose the $record variable inside php tags and echo it.

You should echo it, like you did with another values:
<?php echo $record['id']; ?>
Full code:
<tr>
<td><?php echo $record['id']; ?></td>
<td><?php echo $record['firstname'];?></td>
<td><?php echo $record['Email'];?></td>
<td><?php echo $record['mobilenumber']?></td>
<td><?php echo $record['company']?></td>
<td><?php echo $record['designation']?></td>
<td><?php echo $record['state']?></td>
<td><i class="fa fa-eye" aria-hidden="true"></i></td>
</tr>
<?php } ?>

You should echo ID
as below
<a href="detail.php?id=<?= $record['id'] ?>\">

Related

How to show image in table using PHP

I tried the following code to show my SQL database data in a table in my dashboard
<tbody>
<?php
while ($row = $result->fetch_assoc()):?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><img src="<?php echo $row['image']; ?>" width=100px height=100px></td>;
<td><?php echo $row['class']; ?></td>
<td><?php echo $row['reg_no']; ?></td>
<td><?php echo $row['capacity']; ?></td>
<td><?php echo $row['oname']; ?></td>
<td><?php echo $row['province']; ?></td>
<td><?php echo $row['district']; ?></td>
<td><?php echo $row['contact']; ?></td>
<td><a href="#" class="btn btn-warning btn-circle editbtn">
<i class="fas fa-edit"></i></a></td>
<td><a href="#" class="btn btn-info btn-circle viewbtn">
<i class="fas fa-eye"></i></a></td>
<td><a href="#" class="btn btn-danger btn-circle deletebtn">
<i class="fas fa-trash"></i></a></td>
</tr>
<?php endwhile; ?>
</tbody>
But that image column image does not show has an image
Result show like this:
my result
How to solve that problem
To me it seems your are inserting to the src attribute the context of the file rather then the URL of the image.
you are saving the image content it self in the DB,
check this out :
https://www.codexworld.com/upload-store-image-file-in-database-using-php-mysql/

How can i use the a tag

I have some code and would like to add an hyperlink to each entry on my database
tried using the 'a' tag
<tr>
<td><?php echo $row['id']; ?></td>
<td><a href='details.php'><?php echo $row['game_name']; ?></a></td>
<td><?php echo $row['game_year']; ?></td>
<td><?php echo $row['system']; ?></td>
<td style="text-align: center; color:green"><?php echo $row['owned']; ?></td>
<td style="text-align: center; color:blue"><?php echo $row['completed']; ?></td>
<td><?php echo $row['media']; ?></td>
<td><?php echo $row['launcher']; ?></td>
<tr>
would like to be able to link to a details page
<a href='details.php?gameID=<?=$row['id']?>'>
And in your details.php page you could fetch your DB:
$gameID = (int)$_GET['gameID'] and a bit more error handling

Use variables in PHP foreach loop

I use a foreach loop in php to fill a table, after that I use id and data-id to work with the line of the table.
The problem is that I can't figured how to increment a variable during the loop and add it in the id like this :
id='addr0' data-id="0",
id='addr1' data-id="1"
// etc.
Here is my loop :
foreach($result as $key => $value): ?>
<tr id='addr0' data-id="0">
<td><?php echo $value['Nom']; ?></td>
<td><?php echo $value['Prenom']; ?></td>
<td><?php echo $value['Adresse']; ?></td>
<td><?php echo $value['Date de naissance']; ?></td>
<td><?php echo $value['Numero de telephone']; ?></td>
<td data-name="del">
<button nam"del0" class='btn btn-danger glyphicon glyphicon-remove row-remove'></button>
</td>
</tr>
<?php endforeach; ?>
Try the following.
$counter = 0;
foreach($result as $key => $value): ?>
<tr id='addr<?php echo $counter?>' data-id="<?php echo $counter?>">
<td><?php echo $value['Nom']; ?></td>
<td><?php echo $value['Prenom']; ?></td>
<td><?php echo $value['Adresse']; ?></td>
<td><?php echo $value['Date de naissance']; ?></td>
<td><?php echo $value['Numero de telephone']; ?></td>
<td data-name="del">
<button name = "del<?php echo $counter?>" class='btn btn-danger glyphicon glyphicon-remove row-remove'></button>
</td>
</tr>
<?php
$counter++;
endforeach;
?>
You can get auto increment in two way.
Case 1 : If your $result is indexed array.
foreach($result as $key => $value): ?>
<tr id="addr<?php echo $key ?>" data-id="<?php echo $key ?>">
<td><?php echo $value['Nom']; ?></td>
<td><?php echo $value['Prenom']; ?></td>
<td><?php echo $value['Adresse']; ?></td>
<td><?php echo $value['Date de naissance']; ?></td>
<td><?php echo $value['Numero de telephone']; ?></td>
<td data-name="del">
<button nam"del<?php echo $key ?>" class='btn btn-danger glyphicon glyphicon-remove row-remove'></button>
</td>
</tr> <?php endforeach; ?>
Case 2 : If your $result is associative array.
<?php
$i = 0;
foreach($result as $key => $value): ?>
<tr id="addr<?php echo $i ?>" data-id="<?php echo $i ?>">
<td><?php echo $value['Nom']; ?></td>
<td><?php echo $value['Prenom']; ?></td>
<td><?php echo $value['Adresse']; ?></td>
<td><?php echo $value['Date de naissance']; ?></td>
<td><?php echo $value['Numero de telephone']; ?></td>
<td data-name="del">
<button nam"del<?php echo $i ?>" class='btn btn-danger glyphicon glyphicon-remove row-remove'></button>
</td>
</tr>
<?php
$i++;
endforeach;
?>

Bootstrap table not cropping for tablet devices

I'm using Twitter-Bootstrap for a table. The table works fine for bigger screens and for mobile. For tablet it doesn't work. What I want is the following:
The image above is how it is on mobile. I want this too for tablet, but when I select tablet resolution on Chrome I get this:
It's not responsive. How can I fix this?
Code:
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Breedte</th>
<th>Hoogte</th>
<th>Doekkleur</th>
<th>Omkastingkleur</th>
<th>Bedieningtype</th>
<th>Bedieningkant</th>
<th>Uitvoer</th>
<th>Geleider links</th>
<th>Geleider rechts</th>
<th>Opvulling</th>
<th>Onderlat-type</th>
<th>Extra</th>
<th>Prijs</th>
<th>Actie</th>
</tr>
</thead>
<tbody>
<?php foreach ($result as $offer) { ?>
<tr>
<td><?php echo $offer['width'] ?></td>
<td><?php echo $offer['height'] ?></td>
<td><?php echo $offer['clothingcolor'] ?></td>
<td><?php echo $offer['housingcolor'] ?></td>
<td><?php echo $offer['controltype'] ?></td>
<td><?php echo $offer['controlside'] ?></td>
<td><?php echo $offer['output'] ?></td>
<td><?php echo $offer['conductorleft'] ?></td>
<td><?php echo $offer['conductorright'] ?></td>
<td><?php echo $offer['stuffing'] ?></td>
<td><?php echo $offer['underlattype'] ?></td>
<td><?php echo $offer['extra'] ?></td>
<td><?php echo $offer['price'] ?></td>
<td><button type="submit" class="btn btn-link" name="getValue" data-toggle="modal" data-target=".editProduct<?php echo $offer['id']; ?>" data-id="<?php echo $offer['id']; ?>"><i class="fa fa-pencil" aria-hidden="true" style="color: red;"></i></a></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>

Replace buttons with image in PHP code

I am trying to display images in place of buttons for various activities like Edit Record, Delete Record, Download, Save, Reset. I am able to show the image but the result is very output is looks very childish and nonprofessional. Actually images are coming on button as shown in image
But I want image to display like this
Here is the code which gives the 1st image output.
<tr style="background-color: rgb(253, 253, 183); color: rgb(42, 16, 179);font-size: 13px;" >
<td><?php echo $row->eq_application_no; ?></td>
<td><?php echo $row->eq_class; ?></td>
<td><?php echo $row->eq_name;?></td>
<td><?php echo $row->mid_name; ?></td>
<td><?php echo $row->last_name; ?></td>
<td><?php echo $row->eq_sex; ?></td>
<td><?php echo $row->father_name; ?></td>
<td><?php echo $row->eq_dob; ?></td>
<td><?php echo $row->age.",".$row->month.",".$row->day;?></td>
<td><?php echo $row->scat_id;?></td>
<td><?php echo $row->parent_cate_id;?></td>
<td><?php echo $row->no_of_transfer;?></td>
<td><?php echo $tc_case; ?></td>
<td><?php echo$row->last_school_type; ?></td>
<td><?php echo $row->eq_prv_acdmic;?></td>
<td><?php if($row->kv_tc_date=="1970-01-01"){echo "-";}else{echo $row->kv_tc_date;}?></td>
<td><?php echo $row->kv_tc_no;?></td>
<td><?php echo $row->last_class_cgpa;?></td>
<!--value="Edit"-->
<td><input type="button" id="<?php echo $row->es_enquiryid;?>" onclick="edit_record(<?php echo $row->es_enquiryid;?>)" style="background-image:url(images/edit24.png);width:24px;height:24px;"></td><td>
<!--value="Delete"-->
<input type="button" id="<?php echo $row->es_enquiryid;?>" onclick="delete_record(<?php echo $row->es_enquiryid;?>)" style="background-image:url(images/delete24.png);width:24px;height:24px;" ></td><td><?php
if($eligible=="Y")
{?><input type="checkbox" class="app" name="app[]" d="
<?php echo $row->es_enquiryid;?>" value="<?php echo $row->es_enquiryid;?>">
<?php }
else
{
echo"-";
}
?></td>
</tr>
<?php } ?>
</tbody>
</table>
<table>
<tr>
Add image directly then:
<img src="images/delete24.png" id="<?php echo $row->es_enquiryid;?>" onclick="delete_record(<?php echo $row->es_enquiryid;?>)" style="cursor:pointer;width:24px;height:24px;" />

Categories