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
}
?>
Related
I have a table for saving details including logging time.Just as soon as a new record is inserted I want the column 'Countdown' to start an automatic time countdown from 30min until it gets to zero(0).How do I go about it?Thanks.
Here is the table php code
`<?php $results = mysqli_query($db, "SELECT
Vehicle_name,Vehicle_make,Vehicle_color,Number_plate,Date,Time FROM
vehicle"); ?>
<div class="table">
<table>
<thead>
<tr>
<th>Vehicle name</th>
<th>Vehicle make</th>
<th>Vehicle color</th>
<th>Reg Number</th>
<th>Date</th>
<th>Time</th>
<th>Countdown</th>
<th colspan="4">Action</th>
</tr>
</thead>
<?php while ($row = mysqli_fetch_array($results)) { ?>
<tr>
<td><?php echo $row['Vehicle_name']; ?></td>
<td><?php echo $row['Vehicle_make']; ?></td>
<td><?php echo $row['Vehicle_color']; ?></td>
<td><?php echo $row['Number_plate']; ?></td>
<td><?php echo $row['Date']; ?></td>
<td><?php echo $row['Time']; ?></td>
<td><?php echo $row['Time']; ?></td>
<td>
<a href="php_code.php?del=<?php echo $row['Number_plate']; ?>"
class="del_btn">Delete</a>
</td>
</tr>
<?php } ?>
`
I have a foreach in the table. I foreach a row for every row in my database. So my database has got 10 records, I and my table is showing all those records underneath eachother. So far so good.
I want to number them, from 1 to 10, displayed in front of every row.
This is my table:
<table class="table table-striped mt-3">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Team</th>
<th scope="col">Player</th>
<th scope="col">P</th>
<th scope="col">W</th>
<th scope="col">D</th>
<th scope="col">L</th>
<th scope="col">GF</th>
<th scope="col">GA</th>
<th scope="col">GD</th>
<th scope="col">P</th>
</tr>
</thead>
<tbody>
<?php $count = count($table); ?>
<?php foreach($table as $t): ?>
<tr>
<td><?php for($i = 1; $i < $count; $i++;)
{
echo $i; ?>}
</td>
<td><?php echo $t['team']; ?></td>
<td><?php echo $t['speler']; ?></td>
<td><?php echo $t['gw']; ?></td>
<td><?php echo $t['w']; ?></td>
<td><?php echo $t['g']; ?></td>
<td><?php echo $t['v']; ?></td>
<td><?php echo $t['dv']; ?></td>
<td><?php echo $t['dt']; ?></td>
<td><?php echo $t['ds']; ?></td>
<td><?php echo $t['points']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
This is my method
public function fifaLeagueTable() {
$getTable = "SELECT * FROM fifa_league ORDER BY points DESC";
$table = $this->model->readAll($getTable);
$count = count($table);
include('app/views/fifaLeagueTable.php');
}
If I var_dump the $count, I receive int(10). So it's counting the amount of rows and I have access to the 10. I am getting a white page, so there might be something wrong in the for loop or something. What did I do wrong?
You just need to create one more variable and its done. Here is updated code :
<table class="table table-striped mt-3">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Team</th>
<th scope="col">Player</th>
<th scope="col">P</th>
<th scope="col">W</th>
<th scope="col">D</th>
<th scope="col">L</th>
<th scope="col">GF</th>
<th scope="col">GA</th>
<th scope="col">GD</th>
<th scope="col">P</th>
</tr>
</thead>
<tbody>
<?php $count = count($table); $num = 1; ?>
<?php foreach($table as $t): ?>
<tr>
<td><?php echo $num; ?>
</td>
<td><?php echo $t['team']; ?></td>
<td><?php echo $t['speler']; ?></td>
<td><?php echo $t['gw']; ?></td>
<td><?php echo $t['w']; ?></td>
<td><?php echo $t['g']; ?></td>
<td><?php echo $t['v']; ?></td>
<td><?php echo $t['dv']; ?></td>
<td><?php echo $t['dt']; ?></td>
<td><?php echo $t['ds']; ?></td>
<td><?php echo $t['points']; ?></td>
</tr>
<?php $num++ ; endforeach; ?>
</tbody>
</table>
I wrote code to retrieve data from database and to print in form of tables on my web. I have stored 4 columns of data in my database but while retrieving it's only showing one column.
My database image
My webpage
My code:
<?php
$con = mysqli_connect("localhost", "root", "", "project");
if(!$con)
{
die('not connected');
}
$result= mysqli_query($con, "SELECT name, stay, food, travel,
SUM(stay + food + travel) AS totalamount,doj
FROM placedetails ");
?>
<div class="container">
<table class="table table-hover">
<thead>
<tr>
<th>place</th>
<th>stay cost</th>
<th>food cost</th>
<th>flight cost</th>
<th>Date of journey</th>
<th>Total cost</th>
</tr>
</thead>
<?php
while($row =mysqli_fetch_array($result))
{
?>
<tbody>
<tr>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['stay']; ?></td>
<td><?php echo $row['food'] ;?></td>
<td><?php echo $row['travel'] ;?></td>
<td><?php echo $row['doj'] ;?></td>
<td><?php echo $row['totalamount'] ;?></td>
</tr>
</tbody>
<?php
}
?>
</table>
</div>
</div>
Can anyone can tell where the mistake is?
And one more question: I want to diplay only the recent uploaded data on my web page. Suppose I have 4 names as mumbai, but uploaded at different times, I want to display the most recently added mumbai name on my web page
Can anyone help me out in this matter? I will be very thankful..
update your code as move tbody from php loop
<div class="container">
<table class="table table-hover">
<thead>
<tr>
<th>place</th>
<th>stay cost</th>
<th>food cost</th>
<th>flight cost</th>
<th>Date of journey</th>
<th>Total cost</th>
</tr>
</thead>
<tbody>
<?php
while($row = mysqli_fetch_assoc($result))
{
?>
<tr>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['stay']; ?></td>
<td><?php echo $row['food'] ;?></td>
<td><?php echo $row['travel'] ;?></td>
<td><?php echo $row['doj'] ;?></td>
<td><?php echo $row['totalamount'] ;?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
1) <tbody> should be outside of while loop
2) if you want show only one record means no need to use while loop
3) if you want show recent record means just do descending sort by date column or id column
Query :
SELECT name, stay, food, travel, SUM(stay + food + travel) AS totalamount,doj FROM placedetails order by doj desc limit 1;
Table :
<tbody>
<?php
$row = mysqli_fetch_assoc($result); //fetch first record set only
?>
<tr>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['stay']; ?></td>
<td><?php echo $row['food']; ?></td>
<td><?php echo $row['travel']; ?></td>
<td><?php echo $row['doj']; ?></td>
<td><?php echo $row['totalamount'];?></td>
</tr>
</tbody>
I display the table from db. and i have checkbox for each row,I want to move the selected rows from one table to another "selected table" from the page without page refresh. ? the current selection has to be removed from current table. I can do the query like select * from tab-1 where id=$selected. and also can move it to another table with insert into tab_name and so on. but dont know how to do it without refresh and with some nice effects ? may be with jquery any pointers or help.
<table id="tab-1">
<thead>
<tr>
<th scope="col">Select</th>
<th scope="col">ID</th>
<th scope="col">A</th>
<th scope="col">B</th>
<th scope="col">C</th>
<th scope="col">D</th>
<th scope="col">E</th>
<th scope="col">E</th>
<th scope="col">F</th>
<th scope="col">G</th>
<th scope="col">H</th>
<th scope="col">I</th>
<th scope="col">J</th>
<th scope="col">k</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox" name="checkbox[]" id="checkbox[]" value="<?php echo $row['ID']; ?>" /></td>
<td><?php echo $row['ID']; ?></td>
<td><?php echo $row['A']; ?></td>
<td><?php echo $row['B']; ?></td>
<td><?php echo $row['D']; ?></td>
<td><?php echo $row['E']; ?></td>
<td><?php echo $row['F']; ?></td>
<td><?php echo $row['G']; ?></td>
<td><?php echo $row['H']; ?></td>
<td><?php echo $row['I']; ?></td>
<td><?php echo $row['J']; ?></td>
<td><?php echo $row['K']; ?></td>
<td><?php echo $row['L']; ?></td>
<td><?php echo $row['M']; ?></td>
</tr>
</tbody>
<table>
using jQuery , Ajax you can do this .
<script>
$('.checkBox').change(function() {
var selected = $(this).val();
$.post('yourfile.php' , {
selected : selected
} , function(data){
alert(data);
});
});
$('.checkBox').mousedown(function() {
if (!$(this).is(':checked')) {
$(this).trigger("change");
}
});
</script>
in yourfile.php you can execute SELECT and INSERT queries
I have been working on this script that should get the value of an id field in a database through a checkbox that will be used by a link to edit a page. I know there are topics relating to this but non deals with using the value of the checkbox in a link. The checkbox is actually getting the value of the id from the database i know this because i used inspect element in firefox to view the value of the checkbox. The issue I'm having is using this value in a link to edit a page. Any help will be appreciated. My script is displayed below.
<td width="341" height="73"><h1><strong><span class="style2">EVENTS </span></strong></h1></td>
<td width="59" align="right"><div align="right"><strong>New</strong></div></td>
<td width="66" align="right"><div align="right"><strong><a href="edit_event.php?id=<?php
if (isset ($chek)) {
echo urlencode($chek);
}
?>"/>Edit</a></strong></div></td>
<td width="82" align="right"><div align="right"><strong>Archive</strong></div></td>
<td width="79" align="right"><div align="right"><strong>Unarchive</strong></div></td>
<td width="70" align="right"><div align="right"><strong>Delete</strong></div></td>
<td width="71" align="right"><div align="right"><strong>Exit</strong></div></td>
</tr>
</table>
<p> </p>
<table width="786" border="1">
<tr valign="top">
<th width="46">Event Title</th>
<th width="27"><input type="checkbox" name="checkbox1" value="checkbox" /></th>
<th width="37">Start Date</th>
<th width="36">End Date</th>
<th width="43">Start Time</th>
<th width="38">End Time</th>
<th width="43">Venue</th>
<th width="45">Event Type</th>
<th width="94">Event Description</th>
<th width="152">Event Program</th>
<th width="79">Reminder Date</th>
<th width="70">Reminder Time</th>
</tr>
<?php foreach($events as $event): ?>
<tr valign="top">
<td><?php echo $event->event_title; ?></td>
<td> <form id="form1" name="form1" method="post" action="">
<?php echo "<input type=\"checkbox\" name=\"chek[]\" value= $event->event_id id=\"chek\"/>"; ?>
</form>
</td>
<td><?php echo $event->start_date; ?></td>
<td><?php echo $event->end_date; ?></td>
<td><?php echo $event->start_time; ?></td>
<td><?php echo $event->end_time; ?></td>
<td><?php echo $event->venue; ?></td>
<td><?php echo $event->event_type; ?></td>
<td><?php echo $event->event_description; ?></td>
<td><?php echo $event->event_program; ?></td>
<td><?php echo $event->reminder_date; ?></td>
<td><?php echo $event->reminder_time; ?></td>
</tr>
<?php endforeach; ?>
<?php
$check = $_POST['chek'];
if(empty($check)){
$$check="";
}else{
$N = count($check);
for($i=0; $i < $N; $i++){
$chek =($check[$i]);
}
}
?>
I don't know if my question is understood, what i meant is that I want the value of my check box to display after (http://localhost/emgt/admin/edit_event.php?id=) id so i can edit that particular row.
You can check with the below link. It may be helpful for you.
As far I see you need to add class, and id to your checkbox and use a jquery/javascript function to call the value in your href.
Pass checkbox value to Edit (using href)
Hope it would be of some help to you.
I'm sorry, i found your code to be a little unclear. If you mean calling a url with the checkbox value as a parameter you can do so by adding an "id" property to the checkbox element, and then calling the page like:
var chk = document.getElementById("checkbox_id");
var url = "http://localhost/emgt/admin/edit_event.php?id=" + chk.value;
location.href = url;