PDO query() or fetch() not working - php

I have this code that I made for showing comments in my website from the database
but the comment is not shown.
I think maybe PDO query() or fetch() is not working but the problem is that I don't get any error.
This is the code that i use :
<?php
$showcom1 = $db->query("select * from comments where pc_active='no' order by p_id asc") or die (mysql_error());
$gpid = $_GET['p_id'];
$dcid = $_GET['dc_id'];
$ecpid = $_GET['ec_id'];
$hcpid = $_GET['hc_id'];
$scpid = $_GET['sc_id'];
echo "
<table width='100%' align='center' cellpadding='10' cellspacing='10'>
<tr>
<td class='bodymenu' style='color: #4276a1' align='center'>
الفئات <text style='color: #555'>::</text>
1 = القرآن الكريم
<text style='color: #555'>||</text>
2 = أدعية
<text style='color: #555'>||</text>
3 = قصص
<text style='color: #555'>||</text>
4 =مقالات
<text style='color: #555'>||</text>
5 = فتاوى
<text style='color: #555'>||</text>
6 = رمضانيات
<text style='color: #555'>||</text>
7 = اسلاميات
</td>
</tr>
</table>
<table width='100%' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td class='tbl' colspan='7'>التعليقات</td>
</tr>
<tr align='center' >
<td class='tblbb2' >الفئة</td>
<td class='tblbb2' >اسم المعلق</td>
<td class='tblbb2' >بريد المعلق</td>
<td class='tblbb2' >اي بي المعلق</td>
<td class='tblbb2' >تاريخ التعليق</td>
<td class='tblbb2' >رابط الصفحة</td>
<td class='tblrlb' >الخيارات</td>
</tr>";
// TABLE comments = pc_id,pc_name,pc_mail,pc_ip,pc_date,pc_text,pc_active,p_id
while ($rcom1 = $showcom1->fetch(PDO::FETCH_OBJ)) {
echo "
<tr>
<td align='center' class='tblr' >".$rcom1->pc_cat."</td>
<td align='center' class='tblr' >".$rcom1->pc_name."</td>
<td align='center' class='tblr' >".$rcom1->pc_mail."</td>
<td align='center' class='tblr' >".$rcom1->pc_ip."</td>
<td align='center' class='tblr' >".$rcom1->pc_date."</td>
<td align='center' class='tblrl' ><a target='_blank' href='../pages.php?p_id=".$rcom1->p_id."'>مشاهدة</a></td>
<td align='center' class='tbll' >
<a href='index.php?cpages=comments&dc_id=".$rcom1->pc_id."'>حذف</a> -
<a href='index.php?cpages=comments&p_id=".$rcom1->pc_id."'>معاينة</a> -
<a href='index.php?cpages=comments&hc_id=".$rcom1->pc_id."'>اخفاء</a>
</td>
</tr>
";
}
echo " <tr colspan='7'>
<td colspan='7' class='tblb'>
</td>
</tr>";
?>

you want to show the comments but here in your query
$showcom1 = $db->query("select * from comments where pc_active='no' order by p_id asc") or die (mysql_error());
you have pc_active as no i guess no means the comment is hidden maybe and the other words that you set in your database means visible so .. maybe you dont have hidden comments in your database so try changing no to the other word or change pc_active in your database to be no
other thing i noticed that you use or die (mysql_error()); and that wont work with pdo you may want to change it to use the caught function :D
it works like this :
placing your query in a
try {
}
then placing the caught after the try like this :
catch(PDOException $e){
echo 'ERROR: '.$e->getMessage();
}
you should learn more about pdo error handling on here : PHP Oficcial Site For Error Handling

If you are using PDO then why are you handling error using or die(mysql_error()) at the end of this query???
$showcom1 = $db->query("select * from comments
where pc_active='no' order by p_id asc") or die
(mysql_error());
Anyway, I don't know your aim is, but error handling is done using try/catch blocks like this:
try{
$showcom1 = $db->query("select * from comments
where pc_active='no' order by p_id asc");
}catch(PDOException $e){
echo 'ERROR: '.$e->getMessage();
}
The above method, in-conjunction with your query will work/give you a human-readable error

Related

Create specific hyperlinks on search results

i'm doing a little web application that works like a little booking.com.
I've written the code for searching the city and I can see the results in a table, how can I make linkable all the results (the name of the hotels for example) and have the redirection to the right hotel page for each result?
I've already tried with but I had some problem to redirecting to the right page and it gave me some code errors too
<?php
$con= new mysqli("localhost","root","","registration");
$name = $_POST['search'];
//$query = "SELECT * FROM hotels
// WHERE city LIKE '%{$name}%'";
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con, "SELECT * FROM hotels
WHERE city LIKE '%{$name}%'");
echo "
<table border='1' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='532' height='23' id='AutoNumber1'>
<tr>
<td width='120' height='23' align='center'>Name</td>
<td width='179' height='23' align='center'>Address</td>
<td width='100' height='23' align='center'>Phone number</td>
<td width='150' height='23' align='center'>E-mail</td>
<td width='50' height='23' align='center'>Stars</td>
<td width='100' height='23' align='center'>Price single room</td>
<td width='100' height='23' align='center'>Price double room</td>
</tr>";
while ($row = mysqli_fetch_array($result))
{
echo "
<tr>
<td width='120' height='23'>$row[namehotel]</td>
<td width='179' height='23'>$row[address]</td>
<td width='100' height='23'>$row[phonenumber]</td>
<td width='150' height='23'>$row[email]</td>
<td width='50' height='23'>$row[stars]</td>
<td width='100' height='23'>$row[pricesingle]</td>
<td width='100' height='23'>$row[pricedouble]</td>
</tr>";
echo "<br>";
}
mysqli_close($con);
?>
In the meanwhile I couldn't create the link, if I have as result for example Hilton, the name should be clickable and it should redirect to the page of the Hilton hotel (created by me in html)
Thank you!
Im not sure if im understand right.. you need a html hyperlink?
echo '<tr>
<td width="120" height="23">
<a href="your/target/with'.$row[hotelID].'" >'.$row[namehotel].'</a>
</td>
<td width="179" height="23">'.$row[address].'</td>
<td width="100" height="23">'.$row[phonenumber].'</td>
...
...
</tr>';
ok i was able to create the hyperlink but is it possible to create a different link for every result?
I created the hyperlink with
when I create this page I cannot be able to bring the $_POST['namehotel'], I have Undefined error
I post the code:
<?php
session_start();
$con= mysqli_connect("localhost","root","","registration");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con, "SELECT * FROM hotels
WHERE namehotel LIKE '%{$_POST['namehotel']}%'");
mysqli_close($con);
?>
How can I have $_POST['namehotel'] from the previous search?

Images Not Showing in a table when PHP echo but will show if just in html

I am using the following code on a PHP page. When I load the page, the data shows up but the tag will not show anything other than a dot. If I add style="height:11px; width:16px", it shows a very very thin line (same goes if I just add height="11px" width="16px"
I can view the rendered html code and the img src is correct, it will display no problems. I can add, outside of my PHP script, an
as an example, and it displays just fine. So I am missing something within this snippet of code which is causing my grief?
I've looked in the Inspector tool in Chrome and I don't have any obvious errors other than a javascript error but I don't think that should be causing the issue.
The test page witho nly the two css. It works when I only have bootstrap.css but goes away when I add on the style.css
http://cronkflies.com/test5.php
<!-- Top Routes -->
<div class="col-lg-3" style="background:white;">
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col" colspan="2"><span style="font-size:18px; font-weight:bold; text-transform:uppercase"><?php echo $lang_top_routes ?></span></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<?php
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/includes/connections/mysqli.php";
require($path);
$sql = "SELECT vertrekluchthaven, lh.luchthavencode AS vertrek, lh.luchthavennaam AS vnaam, lh.countryflag AS vflag, aankomstluchthaven, lh2.luchthavennaam AS anaam, lh2.luchthavencode AS aankomst, lh2.countryflag AS aflag, COUNT(*) AS count
FROM tbl_vluchtgegevens vg
INNER JOIN tbl_luchthaven lh
ON vg.vertrekluchthaven = lh.luchthavenID
INNER JOIN tbl_luchthaven lh2
ON vg.aankomstluchthaven = lh2.luchthavenID
WHERE vg.vertrekdatum2 <=Now()
GROUP BY vertrekluchthaven, aankomstluchthaven
ORDER BY count DESC
LIMIT 10;";
$result = $result = $link->query($sql);
if ($result->num_rows > 0) {
echo" <table class='table'>";
echo " <tbody>";
while($row = $result->fetch_assoc()) {
$vflag = $row['vflag'];
$aflag = $row['aflag'];
echo " <tr>";
echo " <td align='center'><img src='http://cronkflies.com/img/flags/" . $vflag . "'></td>";
echo " <td ><div class='top10_luchthaven' data-tooltip=\"".htmlspecialchars($row['vnaam'])."\" >".$row['vertrek']."</div></td>";
echo " <td ><strong class='home_statistieks_label'> -</strong></td>";
echo " <td ><img src='http://cronkflies.com/img/flags/".$aflag."'></td>";
echo " <td ><div class='top10_luchthaven' data-tooltip=\"".htmlspecialchars($row['anaam'])."\" >".$row['aankomst']."</div></td>";
echo " <td ><strong class='home_statistieks_label'><div align='center'>".$row['count']."</div></strong></td>";
echo " </tr>";
}
echo " </tbody>";
echo "</table>";
}
$link->close();
?>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
It seems that you should have the same amount of columns in the header <th></th> as in the row <td></td>

Select an sql field from html field and show it in another page

I have displayed sql table in html table, made a hyperlink near all fields, when i click it the whole field details should be shows in other page(ie; i show only 2 fields of sql in the table and want to show rest in another page).
admin.php
<?php
$con= mysql_connect("localhost","root","");
mysql_select_db("main",$con);
echo"<form action=\"post\" class=\"form-horizontal\" role=\"form\">";
echo "<table width='700' height='150' onclick='myFun(event)'>";
echo" <tr>
<td width='100' align='center'></td>
<td width='100' align='center'><b><u>NAME</u></b></td>
<td width='100' align='left'><b><u>E-MAIL</u></b></td>
</tr>
";
$result=mysql_query("select NAME,EMAIL from admin order by AID");
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo"<td width='100' align='center'><a href='viewadmin.php?name=".$row['NAME']."'>Select</a></td>";
echo"<td width='100' align='center'>".$row['NAME']."</td>";
echo"<td width='100' align='left'>".$row['EMAIL']."</td>";
echo"</tr>";
}
echo"</table>";
echo"</form> ";
?>
viewadmin.php
<?php
$name = $_GET['name'];
$result=mysql_query("SELECT NAME,DOB,MOB,EMAIL, FROM admin WHERE NAME = $name");
if (false === $result) {
echo mysql_error();
}
else {
$row=mysql_fetch_row($result);
}
echo" <form class=\"form-horizontal\" role=\"form\">
<table width='400'>
<tr>
<td align='left'>Name</td>
<td align='left'>".$row['NAME']."</td>
</tr>
<tr>
<td align='left'>E-mail</td>
<td align='left'>".$row['EMAIL']."</td>
</tr>
<tr>
<td align='left'>D.O.B</td>
<td align='left'>".$row['DOB']."</td>
</tr>
<tr>
<td align='left'>Mobile</td>
<td align='left'>".$row['MOBILE']."</td>
</tr>
<tr>
<td align='left'>Photo</td>
<td ><img src='uploads/grumpy.jpg' height='200' width='200'></td>
</tr>
</table>";
echo"</form> ";
?>
do something like this:
admin.php
$result=mysql_query("select NAME,EMAIL from admin order by AID");
while($row=mysql_fetch_array($result)) {
echo "<tr>";
echo"<td width='100' align='center'><a href='viewadmin.php?name=".$row['NAME']."'>Select</a></td>";
echo"<td width='100' align='center'>".$row['NAME']."</td>";
echo"<td width='100' align='left'>".$row['EMAIL']."</td>";
echo"</tr>";
}
echo"</table>";
and in viewadmin.php
$name = $_GET['name'];
$result=mysql_query("SELECT * FROM admin WHERE name = $name");
$row=mysql_fetch_row($result);
echo " <form class=\"form-horizontal\" role=\"form\">
<table width='400'>
<tr>
<td align='left'>".$row['NAME']."</td>
<td align='left'></td>
</tr>
<tr>
<td align='left'>".$row['EMAIL']."</td>
<td align='left'>...";
first rename the html page by php page, then you can pass the primary key or any key of the row from first page to admin page with the help of GET.
for eg:
first.php
<?php
$result=mysql_query("select ID,NAME,EMAIL from admin order by AID"); while($row=mysql_fetch_array($result)){
?><a hre='admin.php?id="$id=<?php $row[0] ?>"'></a>
<?php
}
?>
and in the admin.php page
you can access the value like
echo $_GET['id'];
stop using MySQL and use MySQLi, this code should work
<?php
$db_connect = mysqli_connect('localhost', 'root', 'pass', 'database');
if (mysqli_connect_errno($db_connect)) {
die('Some error occurred during connection to the database');
}
$name = mysqli_real_escape_string($db_connect,$_REQUEST['name']);
if($stmt = mysqli_prepare($db_connect, 'SELECT * FROM admin WHERE name = ?')){
mysqli_stmt_bind_param($stmt, 's', $name);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if(mysqli_num_rows($result) !== 0){
$row = mysqli_fetch_assoc($result);
echo "<form class=\"form-horizontal\" role=\"form\">
<table width='400'>
<tr>
<td align='left'>".$row['NAME']."</td>
<td align='left'></td>
</tr>
<tr>
<td align='left'>".$row['EMAIL']."</td>
<td align='left'>..."
}
else{
echo 'not found';
}
}
else{
trigger_error('error:' . mysqli_errno($db_connect) . mysqli_error($db_connect));
}
?>

ORDER BY one ID when there are more of the same ID's in one table

I have 4 tables:
Users
Forums
Discussies (discussions)
Forumberichten (messages)
The table Forumberichten (messages) contains the id's of the Discussion (discussions) table as a reference to reactions on a discussion. If there are 5 reactions to a discussion, there are 5 id's in the table with the same value.
How do I display an echo of one discussion of every different discussion with the latest reaction on it?
I've tried ORDER BY, DISTICT, GROUP BY and other things but I can't get it to work. I keep getting more outputs of the same discussion or one discussion with the original input and not the latest reaction to it.
<?php
// DISCUSSIES FORUM SCHRIJVEN
$sql="SELECT forumberichten.discussieid,forumberichten.datum,discussies.discussieid,discussies.titel,discussies.forumid,discussies.highlight,forums.forumid,forums.forumnaam,users.userid,users.userimage,users.username FROM forumberichten,discussies,forums,users WHERE forumberichten.discussieid=discussies.discussieid AND discussies.forumid=forums.forumid AND forumberichten.userid=users.userid AND forums.forumid=1 ORDER BY forumberichten.bericht_id DESC LIMIT 3";
$result = $conn->query($sql) or die ("The query could not be completed. try again");
if ($result->num_rows > 0) {
echo "
<br>
<table id='forumschrijvenklein'>
<tbody>
<tr>
<td bgcolor='#1E1E1E'></td>
<td nowrap bgcolor='#1E1E1E'> </td>
<td nowrap bgcolor='#1E1E1E' class='sterrenkleur'>Discussie</td>
<td nowrap bgcolor='#1E1E1E' class='sterrenkleur'>Laatste reactie</td>
<td nowrap bgcolor='#1E1E1E' class='sterrenkleur'>Datum</td>
<td nowrap bgcolor='#1E1E1E' class='sterrenkleur'></td>
</tr>
";
// output data of each row
while ($row = $result->fetch_assoc()) {
echo"
<tr>";if ($row["highlight"] == '1') {
echo " <td bgcolor='#FC6'></td>";
} else {
echo "<td bgcolor='#1E1E1E'></td>";
}
echo"
<td nowrap bgcolor='#1E1E1E'>";if ($row["userimage"] == '') {
echo "
<a href='user.php? id=" . $row['userid'] . "'</a><img src='Images/users/nopicture.png' alt='nopicture' class='userimage-tooltip-small' title='".$row['username']."''></a>";
} else {
echo "<a href='user.php? id=" . $row['userid'] . "'</a><img src='Images/users/".$row['userimage']."' class='userimage-tooltip-small' title='".$row['username']."''></a>";
}
echo"</td>
<td bgcolor='#1E1E1E'><a href='discussie.php? id=" . $row['discussieid'] . "'>".$row["titel"]."</a></td>
<td bgcolor='#1E1E1E'><a href='user.php? id=" . $row['userid'] . "'</a>".$row["username"]."</a></td>
<td nowrap bgcolor='#1E1E1E'>"; echo date("d-m-y H:i",strtotime($row["datum"]));"
";
echo"
</td>
<td nowrap bgcolor='#1E1E1E'></td>
</tr>
";
}
}
echo "
<tr>
<td bgcolor='#1E1E1E'> </td>
<td bgcolor='#1E1E1E'> </td>
<td bgcolor='#1E1E1E'><img src='Images/lijntransparant.png' width='315' height='2'></td>
<td bgcolor='#1E1E1E'><img src='Images/lijntransparant.png' width='140' height='2'></td>
<td bgcolor='#1E1E1E'> </td>
<td bgcolor='#1E1E1E'> </td>
</tr>
</tbody>
</table>
";
}
?>
I tried the following, but it still doesn't work...:
$sql = "SELECT *
FROM (((forumberichten
JOIN discussies
ON discussies.discussieid = forumberichten.discussieid)
JOIN users
ON users.userid = forumberichten.userid)
JOIN forums
ON forums.forumid=forumberichten.forumid)
GROUP BY discussies.discussieid
HAVING forumberichten.forumid = 3 AND forumberichten.bericht_id = max(forumberichten.bericht_id)
ORDER BY forumberichten.bericht_id DESC";
We want the newest post on each unique thread, we can do that by...
Using GROUP BY and HAVING.
SELECT *
FROM Posts
JOIN Discussions
on Discussions.discussion_id = Posts.discussion_id
GROUP BY Discussions.discussion_id
HAVING Posts.post_time = max(Posts.post_time)
ORDER BY Posts.post_time DESC
This is an example! Make sure you use it to modify your own, it's quite simple though. I don't have a database to test this, but I am tested with my own data and different columns and it worked.
Note: This assumes that each Id is identical in both tables. It also assumes that post_time is some time value that increases the more recent the post is (i.e. SQL Timestamp).

retrieve id of table rows?

i have this script bellow to open table2 when clicking on the buttom 'more details'
<script>
$(document).ready(function() {
$('#Table1 tr').click(function(event){
$('#Table2').show();
alert($(this).attr('id'));
});
});
</script>
and this my code
<table id= "Table1" width='100%' border='1' cellspacing='0' cellpadding='0'>
$sql2=..
$sql3 = blabla ;
while($row3 =mysql_fetch_array($sql3)){
$sql4 = mysql_query (" SELECT $ww as place FROM data WHERE $ww =".$row3[$ww]." and id_user = ".$userid." ");
$row4 = mysql_fetch_array($sql4) ;
$string = "<blink > here </blink>" ;
$wnumber = $row3[$ww] ;
echo "<tr id= '".$wnumber."'><td style= 'text-align : center ;'>Week ".$row3[$ww]."
</td>" ;
echo "<td >".(int) $row3["percent"] ."% </td>";
echo "<td > "?><?php if($row4['place'] ==
$row3[$ww] and $row2['id'] == $userid ){ echo $string ; } else { echo "";} ;?><?php
"</td>";
echo "<td ><button class='showr'>More Details</button> </td></tr>";
//More Details when clicking on this buttom it open the table2
}
</tr>
</table>
this is second table
<?php
echo "<div id= 'Table2' style= 'display:none;'>";
echo "<table width='100%' border='1' cellspacing='0' cellpadding='0'>";
echo "<th> Week ".$wnumber."</th>";
echo "<th>try2</th>";
echo "<tr ><td>day</td>";
echo "<td>fff</td></tr>";
echo "</table></div>";
?>
*what i have now 5 rows with 5 buttoms .
*what it happen now is when clicking on every bottom it echo same '$wnumber' lets say 6.
however it defers from row to row ,
- script works good with alert of the id of which row is clicked.
- only the last buttom who works with the last id of row.
*what i want is every bottom works with its row id which echo the right '$wnumber'
* what i have tried is (make variable in the div)
echo "<div id= '".$wnumber."' style= 'display:none;'>";
instead of
echo "<div id= 'Table2' style= 'display:none;'>";
but didnt work.
hope its clear and there is solution of it.
EDIT : this source code
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function() {
$('#Table1 tr').click(function(event){
$('#Table2').show();
alert($(this).attr('id'));
});
});
</script>
<br />
<table id= "Table1" width='100%' border='1' cellspacing='0' cellpadding='0'>
<th >Weeks</th>
<th ><p></p></th>
<th > Your place</th>
<th > More Details</th>
<tr>
<tr id= '1'><td style= 'text-align : center ;'>Week 1</td><td style= 'text-align :
center ;'>33% </td><td style= 'text-align : center ;'> <td style= 'text-align :
center ;'><button class='showr'>More Details</button></td></tr><tr id= '6'><td
style= 'text-align : center ;'>Week 6</td><td style= 'text-align : center ;'>33%
</td><td style= 'text-align : center ;'> <td style= 'text-align : center
;'><button
class='showr'>More Details</button></td></tr><tr id= '13'><td style= 'text-align:
center ;'>Week 13</td><td style= 'text-align : center ;'>33% </td><td style=
'text-align : center ;'> <blink style= 'color:#990000 ;font-weight: bolder;' > 69
here </blink><td style= 'text-align : center ;'><button class='showr'>More
Details</button></td></tr></tr>
</table>
<br />
<div id= 'Table2' style= 'display:none;'><table width='100%' border='1'
cellspacing='0' cellpadding='0'><th> Week 13</th><th>try2</th><tr ><td>day</td>
<td>fff</td></tr></table></div>
<br /><br /> <br />
I tried your html code after correcting the missing td, tr.
And then clicking on each row / button displays the div.
Ensure you form proper html code in your php echo
Try something like this:
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function() {
$('#Table1 tr').click(function(event){
$('#details').find('#week' + $(this).attr('id')).show();
// alert($(this).attr('id'));
});
});
</script>
<?php
$result = mysql_query($sql);
// save the results to an array so you can loop them twice
while($row = mysql_fetch_array($result)) :
$rows[] = $row;
endwhile;
?>
<table id="table1">
<tr>
<th>heading</th>
<th>heading</th>
<th>heading</th>
<th>heading</th>
</tr>
<?php foreach ($rows as $row) : // loop #1 to output the main table ?>
<tr id="<?php echo $row['ww'] ?>">
<td>value</td>
<td>value</td>
<td>value</td>
<td><button type="button">More details</button></td>
</tr>
<?php endforeach; ?>
</table> <!-- end table 1 -->
<div id="details">
<?php foreach ($rows as $row) : // loop #2 to output a table for each set of details ?>
<table id="week<?php echo $row['ww'] ?>" style="display: none">
<tr>
<th>Week <?php echo $row['ww'] ?></th>
<th>try2</th>
</tr>
<tr>
<td>value</td>
<td>value</td>
</tr>
</table>
<?php endforeach; ?>
</div> <!-- end details -->
I copy / pasted your code into a jsFiddle and it seems to work as expected. Clicking on the row sends an alert with the correct ID.
http://jsfiddle.net/JeeNN/
Is there something I'm missing in your intent here?
Note : Best practice would be to skip the inline CSS and add external styling for your tables. Also, valid HTML is a must.
Update:
I went ahead and formatted the php code you posted so it's a bit easier to read. There's some variables that aren't defined and a couple other issues, but I'm sure you have it correct in your php file.
I think that you're going to want to run the loop a second time to create the second table. In this second loop, echo out the second table once per loop - you'll end up with a bunch of tables (one per row plus the first table). Then simply swap the visibility of the tables as user's click each id.
Is that what you're looking for? If not, perhaps try to rephrase your question.
Here's that formatted code:
<table id="Table1" width='100%' border='1' cellspacing='0' cellpadding='0'>
<?php
$sql2 = [..];
$sql3 = [..];
$ww = ?;
while($row3 = mysql_fetch_array($sql3)){
$sql4 = mysql_query ("SELECT $ww as place FROM data WHERE $ww =".$row3[$ww]." and id_user = ".$userid." ");
$row4 = mysql_fetch_array($sql4) ;
$string = "<blink> here </blink>" ;
$wnumber = $row3[$ww];
echo "<tr id='".$wnumber."'>";
echo "<td style='text-align:center;'>Week ".$row3[$ww]."</td>";
echo "<td>".(int) $row3["percent"] ."% </td>";
echo "<td>":
if($row4['place'] == $row3[$ww] and $row2['id'] == $userid ){
echo $string;
} else {
echo " ";
}
echo "</td>";
//More Details when clicking on this buttom it open the table2
echo "<td ><button class='showr'>More Details</button></td>";
echo "</tr>";
} ?>
</table>
<div id= 'Table2' style= 'display:none;'>
<table width='100%' border='1' cellspacing='0' cellpadding='0'>
<tr>
<th> Week <?php echo $wnumber; ?></th>
<th>try2</th>
</tr>
<tr>
<td>day</td>
<td>fff</td>
</tr>
</table>
</div>

Categories