I want to update the value in a certain row. But it seems impossible since this table (from database) doesn't have the primary key. It only have two foreign key in its column. What should I do ? please, any help ?
here is my code :
<table align= "center" border="1" cellspacing="0" cellpadding="2">
<?php
$strgettable="select tblUsrGrp.UsrGrpNama, tblmenu.MenuNama, tblmenuakses.MenuAkses
FROM tblUsrGrp
inner join tblMenuAkses
on tblUsrGrp.UsrGrpID = tblMenuAkses.usrgrpid
inner join tblMenu
on tblMenu.menuid = tblMenuAkses.menuid";
$varRecCount=0;
$rs=odbc_exec($dbconnVOT, $strgettable);
if($rs)
{
echo '<tr><td style=width:10%;>';
echo '<center><b> No. </b></center>';
echo '</td>';
echo '<td style=width:30%;>';
echo '<center><b> User Group </b></center>';
echo '</td>';
echo '<td style=width:20%;>';
echo '<center><b> Menu Name </b></center>';
echo '</td>';
echo '<td style=width:20%;>';
echo '<center><b> Menu Akses </b></center>';
echo '</td>';
echo '<td style=width:20%;>';
echo '<center><b> Update </b></center>';
echo '</td></tr>';
while (odbc_fetch_row($rs))
{
$varRecCount++;
echo '<tr><td>';
echo '<center> '.$varRecCount.'</center>';
echo '</td>';
echo '<td>';
echo '<center> '.odbc_result($rs,"UsrGrpNama").'</center>';
echo '</td>';
echo '<td>';
echo '<center> '.odbc_result($rs,"MenuNama").'</center>';
echo '</td>';
echo '<td>';
echo '<center> '.odbc_result($rs,"MenuAkses").'</center>';
echo '</td>';
echo '<td>';
echo '</td>';
echo '</td></tr>';
}
}
?>
</table>
<div style="text-align:center;">
<input type="button" name="btnUpdate" id="btnUpdate" onClick="javascript:sendData('updatedata');" value = "Update">
</div>
any help would be much appreciated . TQ
Related
I want to update my database by using checkbox. But it seems like the code doesn't loop in a foreach. Where did I go wrong ? Is there have anything wrong with my foreach ?
<?php
foreach($_POST['listMenu'] as $checkBox1){
$strUpdateData = "
update tblMenuAkses
set MenuAkses = 'N'
where MenuAksesID = $checkBox1
";
$rsUpdateData = odbc_exec($dbconnVOT,$strUpdateData);
if($rsUpdateData){
echo "Success";
} else {
echo "ERROR <br>";
echo odbc_errormsg($dbconnVOT);
}
}
//It loops here
var_dump($_POST['listMenu']);
?>
<form method="post" action="skrinMenu.php" enctype="multipart/form-data">
<table align= "center" border="1" cellspacing="0" cellpadding="2">
<?php
$strgettable="select * from tblMenuAkses";
$varRecCount=0;
$rs=odbc_exec($dbconnVOT, $strgettable);
if($rs){
while (odbc_fetch_row($rs)) {// loop a table from database and checkbox too
$varRecCount++;
echo '<tr><td>';
echo '<center> '.$varRecCount.'</center>';
echo '</td>';
echo '<td>';
echo '<center> '.odbc_result($rs,"UsrGrpNama").'</center>';
echo '</td>';
echo '<td>';
echo '<center> '.odbc_result($rs,"MenuNama").'</center>';
echo '</td>';
echo '<td>';
echo '<center> '.odbc_result($rs,"MenuAkses").'</center>';
echo '</td>';
echo '<td>';
echo '<center> <input type="checkbox" name="listMenu[]" id="listMenu" value='.odbc_result($rs,"MenuAksesID").'> </center>';
echo '</td>';
echo '</td></tr>';
}
}
?>
</table>
<input type="submit" name="btnMenu" id="btnMenu" value = "Kemaskini">
</form>
The result of the var_dump($_POST['listMenu']) : NULL
I have a account page on my website where it shows all information about a user but it does not show the username.
Database Name: df
Table to get info from: members
Column that stores all the usernames: user
Screenshot:
So I tried this code but it did not work. You may wonder how I came up with that code: I copied the other code that shows when user is registered.
echo '<tr>';
echo '<td align="left" class="padding_td" width="'.$td_width.'">';
echo 'Registrerad:';
echo '</td>';
echo '<td align="left" class="padding_td">';
echo members($user['user']);
echo '</td>';
echo '</tr>';
When I try this code on my site I get this error:
Fatal error: Call to undefined function members() in
C:\xampp\htdocs\account.php on line 328
Here's the code to show when user is registered (may or may not be helpful):
echo '<tr>';
echo '<td align="left" class="padding_td" width="'.$td_width.'">';
echo 'Registrerad:';
echo '</td>';
echo '<td align="left" class="padding_td">';
echo date_detailed($user['date_registred']);
echo '</td>';
echo '</tr>';
Try this:
echo '<tr>';
echo '<td align="left" class="padding_td" width="'.$td_width.'">';
echo 'Registrerad:';
echo '</td>';
echo '<td align="left" class="padding_td">';
echo $user['user'];
echo '</td>';
echo '</tr>';
I am working on a project in which a tutor can save its class timing. He can see his timing according to the days. I used the code
$qry = mysqli_query($con, 'select * from users left join time_slot on users.id=time_slot.u_id where users.id=' . $id);
echo '<table class="table_class" border="2">
<tr>
<th class="details">id</th>
<th class="details">Date</th>
<th class="details">start time</th>
<th class="details">End Time</th>
</tr>';
while ($row = mysqli_fetch_array($qry)) {
echo '<tr>';
echo '<td class="details">' . $row['id'] . '</td>';
echo '<td class="details">' . $row['name'] . '</td>';
echo '<td class="details">' . $row['day'] . '</td>';
echo '<td class="details">' . $row['time_from'] . '</td>';
echo '<td class="details">' . $row['time_to'] . '</td>';
echo '</tr>';
}
echo '</table>';
But It show the multiple time if a tutor have multiple class in same day.
I want to show if he has 2 or more class on similar day(Monday) then all time slot show in a single row. Same this for all days of the week. How can I do it?
You can use GROUP_CONCAT function for this. Assuming your ddl is something like that
create table users(id bigint, name varchar(50));
create table time_slot(id bigint, u_id bigint, day datetime, time_from time, time_to time);
the sql would be as follows:
select u.id,u.name, ts.day,
group_concat(ts.time_from, ' - ', ts.time_to ORDER BY ts.time_from, ts.time_to)
from users u left outer join time_slot ts on u.id = ts.u_id
group by u.id, u.name, ts.day
order by u.name, ts.day
See fiddle.
I have did with some temp values.
if you want in same way to impliment then it is usefull for you.
copy the code and check here http://phpfiddle.org/
$obj1['id']='1';
$obj1['name']='a1';
$obj1['day']='asdadh';
$obj1['time_from']='1';
$obj1['time_to']='1';
$obj2['id']='2';
$obj2['name']='a2';
$obj2['day']='asdad';
$obj2['time_from']='1';
$obj2['time_to']='1';
$obj3['id']='3';
$obj3['name']='a2';
$obj3['day']='asdad';
$obj3['time_from']='1';
$obj3['time_to']='1';
$arr = Array();
$arr[]=$obj1;
$arr[]=$obj2;
$arr[]=$obj3;
echo '<table class="table_class" border="2">';
echo '<tr>';
echo '<th class="details">id</th>';
echo '<th class="details">name</th>';
echo '<th class="details">day</th>';
echo '<th class="details">start time</th>';
echo '<th class="details">End Time</th>';
echo '</tr>';
foreach($arr as $row)
{
echo '<tr>';
echo '<td class="details">' . $row['id'] . '</td>';
echo '<td class="details">' . $row['name'] . '</td>';
echo '<td class="details">' . $row['day'] . '</td>';
echo '<td class="details">' . $row['time_from'] . '</td>';
echo '<td class="details">' . $row['time_to'] . '</td>';
echo '</tr>';
}
echo '</table>';
echo "<br><br><br><br><br><br><br>";
$dates=Array();
$count=0;
foreach($arr as $id=>$row){
$val = $row['day'];
$key = array_search($val,$dates);
if(is_numeric($key)){
$arr[$key]['day']=$dates[$key].','.$val;
unset($arr[$id]);
}else{
$dates[$count]=$val;
}
$count++;
}
// new table
echo '<table class="table_class" border="2">';
echo '<tr>';
echo '<th class="details">id</th>';
echo '<th class="details">name</th>';
echo '<th class="details">day</th>';
echo '<th class="details">start time</th>';
echo '<th class="details">End Time</th>';
echo '</tr>';
foreach($arr as $row)
{
echo '<tr>';
echo '<td class="details">' . $row['id'] . '</td>';
echo '<td class="details">' . $row['name'] . '</td>';
echo '<td class="details">' . $row['day'] . '</td>';
echo '<td class="details">' . $row['time_from'] . '</td>';
echo '<td class="details">' . $row['time_to'] . '</td>';
echo '</tr>';
}
echo '</table>';
I am fetching data from Mysql database and populating them in a table.
However, i cannot seem to make the cell autofit to contents. I have tried width as the property of the table but i cant get it to work
Would really appreciate your help. Thanks
Here's what i have done so far
<div id="page-content-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<table class="table table-bordered" style="width:100%">
<thead>
<tr>
<th><center>ID</center></th>
<th>Name</th>
<th><center>Email</center></th>
<th>Number</th>
<th>Package</th>
<th>Flexibility</th>
<th >Date</th>
<th>Departuring From</th>
<th>Departure Date</th>
<th>Destination</th>
<th>Arrival Date</th>
<th>Price</th>
<th>Consolidator</th>
</tr>
</thead>
<tbody>
<?php
$query = 'SELECT * FROM queries';
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
echo '<tr>';
echo '<td>'. $row['id'] . '</td>';
echo '<td>'. $row['name'] . '</td>';
echo '<td>'. $row['email'] . '</td>';
echo '<td>'. $row['contactnumber'] . '</td>';
echo '<td>'. $row['packagedetails'] . '</td>';
echo '<td>'. $row['flexibility'] . '</td>';
echo '<td>'. $row['datetoday'] . '</td>';
echo '<td>'. $row['departure'] . '</td>';
echo '<td>'. $row['dateofdeparture'] . '</td>';
echo '<td>'. $row['destination'] . '</td>';
echo '<td>'. $row['dateofarrival'] . '</td>';
echo '<td>'. $row['price'] . '</td>';
echo '<td>'. $row['vendor'] . '</td>';
echo '<td width=250>';
echo '<a class="btn btn-success" href="readquery.php?id='.$row['id'].'">Read</a>';
echo ' ';
echo '<a class="btn btn-success" href="updatequery.php?id='.$row['id'].'">Update</a>';
echo ' ';
echo '<a class="btn btn-danger" href="deletequery.php?id='.$row['id'].'">Delete</a>';
echo '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
I never see you echo </tr> or </td>. It would be helpful to give us an output of the HTML being generated by your while loop.
The problem was not with my table. To make it work, i increased the width of my container in which my table was inside, and it worked
I have this block of PHP and HTML:
<table width="57%" border="0" class="tabela_master" id="aps-cat">
<tr>
<?php
while ($row = $db->sql_fetchrow($result_1))
{
echo '<td width="33%" rowspan="12" align="center"><img src="../images/' . $row['picture'] . '" /></td>';
echo '<td width="20%" align="right" class="tabela_master" style="font-weight: bold">Emri / Mbiemri:</td>';
echo '<td width="1%"> </td>';
echo '<td width="46%" class="tabela_master">' . $row['firstname'] . " " . $row['lastname'] . '</td>';
echo '</tr>';
echo '<tr>';
echo '<td align="right" class="tabela_master" style="font-weight: bold">Gjinia:</td>';
echo '<td> </td>';
echo '<td class="tabela_master">' . $row['gender'] . '</td>';
echo '</tr>';
echo '<tr>';
echo '<td align="right" class="tabela_master" style="font-weight: bold">Datelindja:</td>';
echo '<td> </td>';
echo '<td class="tabela_master">' . $row['birthday'] . '</td>';
echo '</tr>';
echo '<tr>';
echo '<td align="right" class="tabela_master" style="font-weight: bold">Adresa / Lokacioni:</td>';
echo '<td> </td>';
echo '<td class="tabela_master">' . $row['location'] . '</td>';
echo '</tr>';
echo '<tr>';
echo '<td align="right" class="tabela_master" style="font-weight: bold">Telefoni:</td>';
echo '<td> </td>';
echo '<td class="tabela_master">' . $row['telephone'] . '</td>';
echo '</tr>';
echo '<tr>';
echo '<td align="right" class="tabela_master" style="font-weight: bold">Email adresa:</td>';
echo '<td> </td>';
echo '<td class="tabela_master">' . $row['email'] . '</td>';
echo '</tr>';
echo '<tr>';
echo '<td align="right" class="tabela_master" style="font-weight: bold">Interesi:</td>';
echo '<td> </td>';
echo '<td class="tabela_master">' . $row['occupation'] . '</td>';
echo '</tr>';
echo '<tr>';
echo '<td align="right" class="tabela_master" style="font-weight: bold"> </td>';
echo '<td> </td>';
echo '<td class="tabela_master"> </td>';
echo '</tr>';
echo '<tr>';
echo '<td align="right" class="tabela_master" style="font-weight: bold"> </td>';
echo '<td> </td>';
echo '<td class="tabela_master"> </td>';
echo '</tr>';
echo '<tr>';
echo '<td align="right" class="tabela_master" style="font-weight: bold"> </td>';
echo '<td> </td>';
echo '<td class="tabela_master"> </td>';
echo '</tr>';
echo '<tr>';
echo '<td align="right" class="tabela_master" style="font-weight: bold"> </td>';
echo '<td> </td>';
echo '<td class="tabela_master"> </td>';
echo '</tr>';
echo '<tr>';
echo '<td align="right" class="tabela_master" style="font-weight: bold"> </td>';
echo '<td> </td>';
echo '<td class="tabela_master"> </td>';
}
//$db->sql_freeresult($result_1);
?>
</tr>
</table>
Now what I want is multiple records shown in the page. The web currently looks like this:
And what I want would look like this:
So my table would provide all my results from my MySQL query which looks like this:
$sql_1 = 'SELECT id, firstname, lastname, birthday, location, occupation, gender, telephone, email, picture
FROM pinkmoon_users ORDER BY `id` DESC LIMIT 1';
$result_1 = $db->sql_query($sql_1) or die($db->sql_error());
Remove the LIMIT 1 in your SQL statement
$sql_1 = 'SELECT id, firstname, lastname, birthday, location, occupation, gender, telephone, email, picture
FROM pinkmoon_users ORDER BY `id` DESC ';
$result_1 = $db->sql_query($sql_1) or die($db->sql_error());
Your query retrieves only the last record from the database. If you want more, you should change the LIMIT 1 to (for example) LIMIT 10 or remove the limit contraint entirely.