I use table to fetch cars information from my database and each column in this table contain car information's but in the last column i want to view in it car picture which is save in my database, i already have my code to fetch picture from my database and can view it in the browsers directly. but how i can view the picture directly in the table column without open the picture in new windows.
view code
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td class="style1"><?php echo $rows['branch']; ?></td>
<td class="style1"><?php echo $rows['model']; ?></td>
<td class="style1"><?php echo $rows['doors']; ?></td>
<td class="style1"><?php echo $rows['fuel']; ?></td>
<td class="style1"><?php echo $rows['engine']; ?></td>
<td class="style1"><?php echo $rows['colo']; ?></td>
<td class="style1"><?php echo $rows['wheel']; ?></td>
<td class="style1"><?php echo $rows['condit']; ?></td>
<td class="style1"><?php echo $rows['warranty']; ?></td>
<td class="style1" style="width: 47px"><?php echo $rows['price']; ?></td>
<td class="style1"><?php echo $rows['CarOwner']; ?></td>
<td align="center" class="style3"><?php echo $rows['CarOwner']; ?></td>
<td align="center" class="style3"><?php echo "download.php"; ?></td>
and this download image from MySQL
<?php
//$id = $_GET['id'];
include_once 'D_B.php';// Connect to server and select database.
$query = "SELECT `name`, `type`, `size`, `content` FROM `upload` WHERE `id`='1'";
$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content) =mysql_fetch_array($result);
header("Content-length: $size");
header("Content-type: $type");
echo $content;
exit;
?>
Just use the address of your link as src attribute of <img> tag, like this:
<td><img src="image.php?id=<?php echo $rows['imageId']; ?>"/></td>
Related
The html table rows aren't displayed properly. I want to combine the two while loops in the table row but sadly the Update and Delete button are not arranged properly.
here's my code I used two queries that's why it has two while loops
$sql_sel=mysql_query("SELECT students.stud_id, students.fname, students.lname, students.gender, subjects.sub_code, subjects.subject_name FROM students, enrollments, subjects WHERE students.stud_id = enrollments.stud_id and subjects.sub_code = enrollments.sub_code");
$sql_sel1=mysql_query("SElECT * FROM enrollments");
while($row=mysql_fetch_array($sql_sel)) //for the first query
{
$i++;
$color=($i%2==0)?"lightblue":"white";
?>
<tr bgcolor="<?php echo $color?>">
<td><?php echo $i;?></td>
<td><?php echo $row['stud_id'];?></td>
<td><?php echo $row['fname']." ".$row['lname'];?></td>
<td><?php echo $row['gender'];?></td>
<td><?php echo $row['sub_code'];?></td>
<td><?php echo $row['subject_name'];?></td>
<?php
while($row=mysql_fetch_array($sql_sel1)) //for the second query
{ <!-------The Update and Delete Button are not displayed properly------>
?>
<td align="center"><img src="picture/update.png" /></td>
<td align="center"><img src="picture/delete.png" /></td>
<?php
}
?>
</tr>
<?php
}
?>
Here is the visual scenario of the problem:
The desired output must be like this:
In table header use colspan='4' for the last column.
Also be sure that you fill the table with empty columns, where you don't have information to fill with.
Edit 1:
Sorry, I haven't seen what's really the problem was. Here should be the working code:
while($row=mysql_fetch_array($sql_sel))
{
$i++;
$color=($i%2==0)?"lightblue":"white";
?>
<tr bgcolor="<?php echo $color?>">
<td><?php echo $i;?></td>
<td><?php echo $row['stud_id'];?></td>
<td><?php echo $row['fname']." ".$row['lname'];?></td>
<td><?php echo $row['gender'];?></td>
<td><?php echo $row['sub_code'];?></td>
<td><?php echo $row['subject_name'];?></td>
<!-- You were already in a while loop -->
<td align="center"><img src="picture/update.png" /></td>
<td align="center"><img src="picture/delete.png" /></td>
</tr>
<?php
}
?>
As you can see you were already in a while loop, and the second one was unnecesary.
Edit 2:
There is a single SQL query now:
<?php
// UPDATED SQL QUERY
$sql_sel = mysql_query("SELECT students.stud_id, students.fname, students.lname, students.gender, subjects.sub_code, subjects.subject_name, enrollments.enroll_num
FROM students, enrollments, subjects
WHERE students.stud_id = enrollments.stud_id and subjects.sub_code = enrollments.sub_code");
while($row = mysql_fetch_array($sql_sel)){
$i++;
$color=($i%2==0)?"lightblue":"white";
?>
<tr bgcolor="<?php echo $color?>">
<td><?php echo $i;?></td>
<td><?php echo $row['stud_id'];?></td>
<td><?php echo $row['fname']." ".$row['lname'];?></td>
<td><?php echo $row['gender'];?></td>
<td><?php echo $row['sub_code'];?></td>
<td><?php echo $row['subject_name'];?></td>
<td align="center"><img src="picture/update.png" /></td>
<td align="center"><img src="picture/delete.png" /></td>
</tr>
<?php
}
?>
Why it didn't worked?
You were reading the whole informations for every student. Then you were reading the whole informations in enrollments table.
You started writing the first row with student information, and inside it you told the server to start writing all the information he had regarding enrollments (without even be linked to that student's id).
When the server reached the second row, all the information available for enrollments were depleted.
Now you have them linked in your first query. Please ask in comments if you need further explanations.
Try this,
$sql= "SELECT sts.stud_id, sts.fname, sts.lname, sts.gender, sub.sub_code, sub.subject_name, ets.enroll_num
FROM students sts
JOIN enrollements ets ON(sts.stud_id = ets.stud_id)
JOIN subjects sub ON (sub.sub_code = ets.sub_code)
GROUP BY sts.stud_id, sub.sub_code";
$sql_sel=mysql_query($sql);
while($row=mysql_fetch_array($sql_sel)) //for the first query
{
$i++;
$color=($i%2==0)?"lightblue":"white";
?>
<tr bgcolor="<?php echo $color?>">
<td><?php echo $i;?></td>
<td><?php echo $row['stud_id'];?></td>
<td><?php echo $row['fname']." ".$row['lname'];?></td>
<td><?php echo $row['gender'];?></td>
<td><?php echo $row['sub_code'];?></td>
<td><?php echo $row['subject_name'];?></td>
<td align="center"><img src="picture/update.png" /></td>
<td align="center"><img src="picture/delete.png" /></td>
</tr>
<?php
}
?>
I have added enroll_num column in select, And you dont need two queries for this. One query with proper join will be fine.
This is the delete page where i want to view the mysql stored data in table but I am unable view. I have created 7 columns for table name registration but I can't fetch the data from database.
<div id="main">
<div id="formainsupport"></div>
<div id="forreg">
<?Php
$tbl_name="registration"; // Table name
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("examonline.", $con);
// select record from mysql
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
?>
<table width="900" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td colspan="8" bgcolor="#FFFFFF"><strong>Delete data in mysql</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF"><strong>intakeid</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>firstname</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>lastname</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>password</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>confirmpassword</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>homeaddress</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>email</strong></td>
<td align="center" bgcolor="#FFFFFF"> </td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td bgcolor="#FFFFFF"><? echo $rows['intakeid']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['firstname']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['lastname']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['password']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['confirmpassword']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['homeaddress']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['email']; ?></td>
<td bgcolor="#FFFFFF">delete</td>
</tr>
<?php
// close while loop
}
?>
</table>
<?php
// close connection;
mysql_close();
?>
Here is code for the to delete the data from database. My sql delete query is here but I think it's not working although it's a fine code. I am unable to find the problem.
<h1>delq.php</h1>
<?php
$tbl_name="registration"; // Table name
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("examonline.", $con);
// get value of id that sent from address bar
$intakeid=$_GET['intakeid'];
// Delete data in mysql from row that has this id
$sql="delete from $tbl_name where intakeid='$intakeid'";
$result=mysql_query($sql);
// if successfully deleted
if($result){
echo "Deleted Successfully";
echo "<BR>";
echo "<a href='Delete.php'>Back to main page</a>";
}
else {
echo "ERROR";
}
?>
<?php
// close connection
mysql_close();
?>
I load a xml file and loop on this to generate an html table. On each line of the table, I have two icones update and delete.
When I click on the icone delete (for example), I want to get the index of the line or any information of the line in order to process delete the node in my xml file.
I try with echo $number by passing parameter to php function but the GET is empty in the php file.
Do you know how can I get it please ? Thank in advance.
<table>
<?php
foreach($participants as $participant)
{
$number = $participant->number;
$name = $participant->name;
$note = $participant->note;
$sexe = $participant->sexe;
$group = $participant->group;
$adjust = $participant->adjust;
?>
<tr>
<td align="center"><?php echo($number) ?></td>
<td align="left" style="padding-left:10px"><?php echo($name) ?></td>
<td align="center"><?php echo($note) ?></td>
<td align="center"><?php echo($sexe) ?></td>
<td align="center"><?php echo($group) ?></td>
<td></td>
<td>
<img src="images/migatiEditUser20x20.jpg">
<img src="images/migati_cancel16x16.png">
</td>
</tr>
<?php }?>
</table>
deleteParticipant.php
<?php
echo ($_GET['number']);
?>
Try this:
<table>
<?php
foreach($participants as $participant)
{
$number = $participant->number;
$name = $participant->name;
$note = $participant->note;
$sexe = $participant->sexe;
$group = $participant->group;
$adjust = $participant->adjust;
?>
<tr>
<td align="center"><?php echo $number; ?></td>
<td align="left" style="padding-left:10px"><?php echo $name; ?></td>
<td align="center"><?php echo $note; ?></td>
<td align="center"><?php echo $sexe; ?></td>
<td align="center"><?php echo $group; ?></td>
<td></td>
<td>
<img src="images/migatiEditUser20x20.jpg">
<img src="images/migati_cancel16x16.png">
</td>
</tr>
<?php }?>
</table>
and on your deleteParticipant.php use:
<?php echo $_GET['number']; ?>
You have to know how get works. Adjust the code as deleteParticipent.php?number= <?php echo $number; ?> then from that file. You will recieve it as $_GET['number']
hey guys i am new in codeigniter and i am working on an application in which i have database and many records in database..i make a search form in which i make a text field in which user can fill any field value and search records.but here is a small problem..when i fill a name in textbox and click on search button no record display on view . . pls help me . . thanks ..
my controller is:
function search()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('inputsearch', 'Search Your Text Here','required');
if ($this->form_validation->run() == TRUE)
{
$this->load->helper('form');
$this->load->helper('html');
$search_this=$this->input->post('inputsearch');
$this->load->model('mod_user');
$searchmember=$this->mod_user->search_member($search_this);
$data['searchmember'] = $searchmember;
var_dump($searchmember);
$this->load->view('view_home',$data);
$this->load->view('view_homemember',$data);
}
else
{
redirect('ctl_home');
}
}
view is:
<form class="userinfo" action="" method="post">
<table border="1" cellpadding="2" cellspacing="0">
<tr>
<td width="5%;"> </td>
<td width="5%;"> </td>
<td width="15%;">Name</td>
<td width="15%;">Moderator Name</td>
<td width="20%;">KCC Branch</td>
<td width="15%;">Father/Husband Name</td>
<td width="15%;">Address</td>
<td width="10%;">Date</td>
</tr>
<?php foreach ($rows as $row):?>
<tr>
<td><?php echo anchor("Ctl_Home/edit_member/" . $row->member_id, 'Edit'); ?></td>
<td>Delete</td>
<td><?php echo $row->member_name; ?></td>
<td><?php echo $row->moderator_name; ?></td>
<td><?php echo $row->branch_name; ?></td>
<td><?php echo $row->father_name; ?></td>
<td><?php echo $row->address; ?></td>
<td><?php echo $row->date; ?></td>
</tr>
<?php endforeach; ?>
</table>
</form>
my model is:
function search_member($search_this)
{
$query=$this->db->query("SELECT tbl_members.* , tbl_moderators.member_id AS moderator_id, tbl_moderators.member_name AS moderator_name, tbl_moderators.member_no AS moderator_no, tbl_branches.branch_name FROM tbl_members, tbl_members AS tbl_moderators, tbl_branches WHERE tbl_members.moderator_id = tbl_moderators.member_id AND tbl_branches.branch_id = tbl_members.kcc_branch
AND CONCAT(tbl_members.member_name, ' ', tbl_moderators.member_name, ' ',tbl_members.moderator_id, ' ', tbl_moderators.member_id, ' ',tbl_branches.branch_name, ' ',tbl_members.father_name, ' ',tbl_members.address, ' ',tbl_moderators.address, ' ',tbl_members.date, ' ',tbl_moderators.date) like '%".$search_this."%'");
if ($query->num_rows >= 0)
{
foreach($query->result_array() as $row)
{
$data[]=$row;
}
return $data;
}
}
Your loop should have been like this
<?php foreach ($searchmember as $row):?>
<tr>
<td><?php echo anchor("Ctl_Home/edit_member/" . $row->member_id, 'Edit'); ?></td>
<td>Delete</td>
<td><?php echo $row->member_name; ?></td>
<td><?php echo $row->moderator_name; ?></td>
<td><?php echo $row->branch_name; ?></td>
<td><?php echo $row->father_name; ?></td>
<td><?php echo $row->address; ?></td>
<td><?php echo $row->date; ?></td>
</tr>
<?php endforeach; ?>
It is $searchmember as $row instead of $rows as $row in foreach
If $data['searchmember'] contains value in controller,
you can access the varibale in view as $searchmember
I'm at lost. What I wanted to do is, I want my website to allow the users to select a certain row(records) in my database and then redirect them to another webpage that will show them the full information about that certain record.. I don't know how could I connect those two web pages together using dynamic table/text..
Below is a portion of my code: ( This is the first webpage: )
mysql_select_db($database_rfq_portal, $rfq_portal);
$query_rfqrecord = "SELECT tblrfq.`RFQ_ID`, tblrfq.`Company_Name`, tblrfq.Service,
tblrfq.`Kind_of_Request`, tblrfq.Status, tblrfq.`Date` FROM tblrfq";
$rfqrecord = mysql_query($query_rfqrecord, $rfq_portal) or die(mysql_error());
$row_rfqrecord = mysql_fetch_assoc($rfqrecord);
$totalRows_rfqrecord = mysql_num_rows($rfqrecord);
<form id="viewform" name="viewform" method="get" action="ViewSpecificRFQ.php">
<table width="716" border="1" align="center" cellpadding="5">
<tr>
<td>RFQ ID</td>
<td>Company Name</td>
<td>Service</td>
<td>Kind of Request</td>
<td>Status</td>
<td>Date</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_rfqrecord['RFQ_ID']; ?></td>
<td><?php echo $row_rfqrecord['Company_Name']; ?></td>
<td><?php echo $row_rfqrecord['Service']; ?></td>
<td><?php echo $row_rfqrecord['Kind_of_Request']; ?></td>
<td><?php echo $row_rfqrecord['Status']; ?></td>
<td><?php echo $row_rfqrecord['Date']; ?></td>
</tr>
<?php } while ($row_rfqrecord = mysql_fetch_assoc($rfqrecord)); ?>
</table>
}
</form>
This is the webpage that will get the form..(portion of my code)
$RFQID = $_GET['RFQ_ID'];
mysql_select_db($database_rfq_portal, $rfq_portal);
$query_rfqrecord = "SELECT * FROM tblrfq WHERE $RFQID";
$rfqrecord = mysql_query($query_rfqrecord, $rfq_portal) or die(mysql_error());
$row_rfqrecord = mysql_fetch_assoc($rfqrecord);
$totalRows_rfqrecord = mysql_num_rows($rfqrecord);
mysql_select_db($database_rfq_portal, $rfq_portal);
$query_user = "SELECT tbluser.Username, tbluser.Password FROM tbluser";
$user = mysql_query($query_user, $rfq_portal) or die(mysql_error());
$row_user = mysql_fetch_assoc($user);
$totalRows_user = mysql_num_rows($user);
<table width="716" border="0" align="center">
<tr>
<th colspan="2" scope="row">RFQ ID:</th>
<td><?php echo $row_rfqrecord['RFQ_ID']; ?></td>
</tr>
<tr>
<th colspan="2" scope="row">Company Name:</th>
<td width="511"><?php echo $row_rfqrecord['Company_Name']; ?></td>
</tr>
<tr>
<th width="101" rowspan="2" scope="row">Address:</th>
<th width="90" scope="row">Site A:</th>
<td><?php echo $row_rfqrecord['Address_A']; ?></td>
</tr>
<tr>
<th scope="row">Site B:</th>
<td><?php echo $row_rfqrecord['Address_B']; ?></td>
</tr>
<tr>
<th colspan="2" scope="row">Contact Number:</th>
<td><?php echo $row_rfqrecord['Contact_Number']; ?></td>
</tr>
<tr>
<th colspan="2" scope="row">Contact Person:</th>
<td><?php echo $row_rfqrecord['Contact_Person']; ?></td>
</tr>
<tr>
<th colspan="2" scope="row">Service:</th>
<td><?php echo $row_rfqrecord['Service']; ?></td>
</tr>
<tr>
<th colspan="2" scope="row">Bandwidth:</th>
<td><?php echo $row_rfqrecord['Bandwidth']; ?></td>
</tr>
<tr>
<th colspan="2" scope="row">Telco:</th>
<td><?php echo $row_rfqrecord['Telco']; ?></td>
</tr>
<tr>
<th colspan="2" scope="row">Account Manager:</th>
<td><?php echo $row_rfqrecord['Account_Manager']; ?></td>
</tr>
<tr>
<th colspan="2" scope="row">Status:</th>
<td><?php echo $row_rfqrecord['Status']; ?></td>
</tr>
<tr>
<th colspan="2" scope="row">Kind of Request:</th>
<td><?php echo $row_rfqrecord['Kind_of_Request']; ?></td>
</tr>
<tr>
<th colspan="2" scope="row">Date:</th>
<td><?php echo $row_rfqrecord['Date']; ?></td>
</tr>
<tr>
<th colspan="2" scope="row">Remarks:</th>
<td><?php echo $row_rfqrecord['Remarks']; ?></td>
</tr>
</table>
</form>
this redirects the user to the next page but my problem is it keeps on showing the same record, which is the first record in my database.
1- Consider page1.php is the first page that user selects a record and then in page2.php you show full detail.
for page1.php
you need to send some parameters like record id or any other key in order to be able to identify the record and select the detail in database.
for example:
Record 1 once user clicked on this link you have to do something like this in page2.php, remember our parameter is record_id
<?php
$id = $_GET['record_id'];
//we have to check it for validity
//if id is an integer (numbers) then simply we can check it
//if(!is_numeric($id)) { die("invalid id") }
// now the id is there
//lets build query
$query = "SELECT * from tablename where id= '$id' ";
?>
for your code it must be like this:
//adding where clause
$query_rfqrecord = "SELECT * FROM tblrfq where RFQ_ID = '$id' ";
$rfqrecord = mysql_query($query_rfqrecord, $rfq_portal) or die(mysql_error());
$row_rfqrecord = mysql_fetch_assoc($rfqrecord);
$totalRows_rfqrecord = mysql_num_rows($rfqrecord);
If you want your users to get to load a specific record when they click a specific row, you have to be sure you're redirecting them to a specific url. In your sample you have <a href="ViewSpecificRFQ.php"> in your do-while, so every row in your table will have the same link and then the same destination page.
You probably want something like <a href="ViewSpecificRFQ.php?recordId=<?php echo $row_rfqrecord['RFQ_ID'] ?>"> and then in your landing page the query will be performed against the key you will have in $_GET['recordId'].
EDIT: The do-while problem
You use a do-while, and so in your first iteration you have no record loaded, because the fetch instruction is located at the bottom of the code block, so you should change it to:
<?php
while ($row_rfqrecord = mysql_fetch_assoc($rfqrecord)) {
?>
<tr>
<td><?php echo $row_rfqrecord['RFQ_ID']; ?></td>
<td><?php echo $row_rfqrecord['Company_Name']; ?></td>
<td><?php echo $row_rfqrecord['Service']; ?></td>
<td><?php echo $row_rfqrecord['Kind_of_Request']; ?></td>
<td><?php echo $row_rfqrecord['Status']; ?></td>
<td><?php echo $row_rfqrecord['Date']; ?></td>
</tr>
<?php
}
?>