Hi im new to php and have very little knowledge, in my where statement I have where Status='A' and z.zoneID=1, is there a way to give the page user control over the z.zoneID=1 so that they can change it to any zoneID that is available, maybe through a drop-down list?
////////Query & Data Display is here/////////
$q=mysql_query("select r.*, f.Functionname, m.Managername, z.Zonename from requests as r inner join functions as f on r.functionID = f.functionID inner join managers as m on r.managerID = m.managerID inner join zones as z on r.zoneID = z.zoneID where Status='A' and z.zoneID=1 order by Functionname");
echo "<table>
<tr>
<th>Function</th>
<th>Manager</th>
</tr>"
;
while($nt=mysql_fetch_array($q)){
echo"<b>Zone: $nt[Zonename]<br>Capacity: $nt[Zonecapacity]</b><br><br>";
echo "<tr><td>$nt[Functionname]</td><td>$nt[Managername]</td></tr>";
}
echo "</table>";
/////////////////////////////////////
This can help you out...
if( isset($_POST['zoneid']) ){
$zoneID = $_POST['zoneid'];
//Your extra code or processing here.
}
$q=mysql_query("select r.*, f.Functionname, m.Managername, z.Zonename from requests as r inner join functions as f on r.functionID = f.functionID inner join managers as m on r.managerID = m.managerID inner join zones as z on r.zoneID = z.zoneID where Status='A' and z.zoneID=1 order by Functionname");
echo "<table>
<tr>
<th>Function</th>
<th>Manager</th>
</tr>"
;
// Here we create a form
echo "<form method='post' >";
echo "<Search for ZoneID: <input type='number' name='zoneid' /><br>";
echo "<input type='submit' value='search' />";
echo "</form>";
while($nt=mysql_fetch_array($q)){
echo"<b>Zone: ".$nt['Zonename']."<br>Capacity: ".$nt['Zonecapacity']."</b><br><br>";
echo "<tr><td>$nt[Functionname]</td><td>$nt[Managername]</td></tr>";
}
echo "</table>";
?>
Related
I have at the moment 2 results in my MySQL Database with same user_id and I want echo all in my HTML table with PDO, but it shows everytime only 1 result, not all.
<?php
$querytest = "SELECT o.output_valu,
p.amount,
p.amount_all,
p.order_id,
p.datetime
FROM allusers a
INNER JOIN order_history o
ON a.account_number = o.account_number
INNER JOIN paymentall p
ON o.output_vl_id = p.output_vl_id
WHERE a.account_number = :account_num
ORDER BY p.datetime";
$statementtest = $conn->prepare($queryoutgo);
$statementtest->bindParam(':account_num', $account_num);
$statementtest->execute();
$test_result = $statementtest->fetchAll();
foreach ($test_result as $row) {
$outputtest = $row['output_valu'];
}
?>
<table>
<tr>
<th>Test</th>
</tr>
<tr>
<td><?php echo $outputtest; ?></td>
</tr>
</table>
With print_r($test_result); it shows my 2 results in array, but why not with my code?
I worked always with mysqli not PDO in the past, maybe someone here can help me :)
In your foreach block you overwrite $outputtest every iteration. This means only the last result will be displayed. Depending on if you want to show each result on a separate row or if you want all the results together in one cell, you should either create the cells in the foreach or concatenate all the results together.
EDIT:
What I think you want is this:
$querytest = "SELECT o.output_valu, p.amount, p.amount_all, " .
"p.order_id, p.datetime " .
"FROM allusers a inner join order_history o " .
"ON a.account_number = o.account_number " .
"INNER JOIN paymentall p " .
"ON o.output_vl_id = p.output_vl_id " .
"WHERE a.account_number =:account_num " .
"ORDER BY p.datetime ";
$statementtest = $conn->prepare($queryoutgo);
$statementtest->bindParam(':account_num', $account_num);
$statementtest->execute();
$test_result = $statementtest->fetchAll();
?>
<table>
<tr>
<th>Test</th>
</tr>
<?php foreach($test_result as $row) { ?>
<tr><td><?= $row['output_valu']; ?></td></tr>
<?php } ?>
</table>
I am busy creating a website that allows people to host dinners and allows users to join those dinners. I have two different database tables called gebruikers (users) and diner (dinner). I am working on a search page that makes it possible for a user to search on a woonplaats (city) and then shows the users living in that city. That works right now, but I want to make sure that only the users are shown who have added a dinner. There is a common key in both tables: diner.gebruikersid = gebruikers.id
So in other words, I only want the users with their ID in both the diner and the gebruikers table to be displayed in the search results. How can I do that?
I have this code at the moment:
$zoeken = $_POST['woonplaats'];
$sql = "SELECT id, voornaam, straatnaam FROM gebruikers WHERE woonplaats LIKE '$zoeken'";
$result = mysql_query($sql);
echo "<div class=res>";
echo "<h3>Resulaten voor " .$zoeken. "</h3>";
echo "<table>";
echo "<thead>";
echo "<tr>";
echo "<th>Voornaam</th>";
echo "<th>Straatnaam</th>";
echo "<th></th>";
echo "</tr>";
echo "</thead>";
while($row = mysql_fetch_assoc($result)) {
echo "<tbody>";
echo "<tr>";
echo "<td>".$row['voornaam']."</td>";
echo "<td>".$row['straatnaam']."</td>";
echo "<td>";
echo "<form action='eetprofiel.php' method='post'>";
echo "<input type='hidden' name='id' value='".$row['id']."'>";
echo "<input type='submit' value='Profiel bekijken'>";
echo "</form>";
echo "<td>";
echo "</tr>";
echo "</tbody>";
}
echo "</table>";
echo "</div>";
?>
Edit:
These are all the users in my database (in table gebruikers) with woonplaats Amersfoort
These are all the diners submitted by those users.
As you see, the user with gebruikers.id and diner.gebruikersid 23 has no dinner submitted, so I don't want him to be shown in the search results.
You should join the 2 tables. With JOIN take a look at this
https://www.tutorialspoint.com/mysql/mysql-using-joins.htm
example of a join
select tableA.user ,tableB.user from tableA JOIN tableB on tableA.id = tableB.id
note: don't use mysql it is deprecated use mysqli or PDO instead
I have this tables:
TABLE addonlist_final
TABLE addons
First, I have to JOIN the same addon_id so I can get all the needed details(which I've already done). Then I want to JOIN the column with the same identity(addon_id) in the table then add the quantity to each other.
So far I have this code:
<?php
include("conn.php");
echo "<table border='1' >";
echo "<tr>";
echo "<th>Description</th>";
echo "<th>Price</th>";
echo "<th>Qty</th>";
echo "<th>Total Cost</th>";
echo "</tr>";
$totaldue = 0;
$currentaddons = mysql_query("SELECT a.*, af.*
FROM addons AS a, addonlist_final AS af
WHERE a.addon_id = af.faddon_id and af.ftransac_id='2685'
ORDER BY af.timef DESC
");
while($rows = mysql_fetch_assoc($currentaddons)){
$desc = $rows['description'];
$price = $rows['price'];
$qty = $rows['quantity'];
$totalcost = $price * $qty;
$totaldue += $price * $qty;
echo "<tr>";
echo "<td>$desc</td>";
echo "<td>$price</td>";
echo "<td>$qty</td>";
echo "<td>$totalcost</td>";
echo "</tr>";
}
echo "</table>";
echo "<h3>Total Due: ".number_format($totaldue)."</h3>";
?>
This shows me this:
What I want to show is:
Is this possible with just one query? Thanks in advance :)
You uave to use group by
SELECT a.description, sum(af.quantity) as quantity,price
FROM addons AS a, addonlist_final AS af
WHERE a.addon_id = af.faddon_id and af.ftransac_id='2685'
group by a.description
ORDER BY af.timef DESC
I'm trying to connect a series of five select menus created on Dreamweaver to generate one result through this query below. I keep getting errors every time I run the query. This is the query I have on my PHP page:
enter code here
<?php
$connect= mysql_connect("localhost","root", "password");
// Check connection
if (!mysql_select_db('db_name', $connect)) {
echo 'Could not select database';
exit;
}
$sql = "SELECT SER_ID and ser_type FROM services
INNER JOIN service_type ST
ON s.SER_ID= st.SER_ID
inner join profile P
on st.P_ID = p.P_ID
inner join room_services rs
on rs.SER_ID = s.SER_ID
inner join room r
on r.R_ID = rs.R_ID
inner join room_sensor rse
on rse.R_ID = r.R_ID
inner join sensor sen
on sen.S_ID = rse.S_ID
inner join service_sensor ss
on ss.SER_ID = s.SER_ID
inner join services_conditions sc
on sc.SER_ID = s.SER_ID
inner join conditions c
on c.C_ID = sc.C_ID
where p.username = Adam
AND sen.sensor_type = motion detector";
$result= mysql_query($sql, $connect);
echo "<table border='1'>
<tr>
<th>ser_ID</th>
<th>service_Type</th>
</tr>";
while($row = mysql_query($result)) {
echo "<tr>";
echo "<td>" . $row['ser_ID'] . "</td>";
echo "<td>" . $row['service_Type'] . "</td>";
echo "</tr>";
}
echo "</table>";
if (!$result) {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
while ($row = mysql_fetch_assoc($result)) {
echo $row['ser_ID'];
echo $row['serice_Type'];
}
mysql_free_result($result);
mysql_close($connect);
?>
enter code here
enter code here
The error I keep receiving is:
DB Error, could not query the database MySQL Error: Query was empty
This is happening despite the fact that the query is running completely fine on phpMyAdmin.
Any help appreciated.
I am making the code of PHP-MySQL. But I gain have the 2 and more as the result of the left join in the MySQL. So I want to union the results in a cell of the result table as the captured picture.
Here is my real captured picture in my computer.
My php code is as like below.
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result))
{
echo "<table border='1' style='background:#dddddd;border-color:green;'>";
echo "<h2><p >진료과 (Subject) : ".$row['subject']."</p></h2>";
echo "<tr>";
echo "<th >"."<form action='search1.php' method='get'>"."<button type='submit'
name='code' value='".$row['code']."'>Code</th>";
echo "<th ><a href='".$row['ds_url']."'>"."한국병명</a></th>";
echo "<th ><a href='".$row['ds_url']."'>"."Disease name(En.)</a></th>";
echo "<th >"."<form action='search1.php' method='get'>"."<button type='submit'
name='code' value='".$row['family']."'>"." Family History</button> </th>";
echo "</tr>";
echo "<tr>";
echo "<td >" . $row['code'] . "</td>";
echo "<td >" .$row['disease_co']."</td>";
echo "<td >" .$row['disease_en']."</td>";
echo "<td >" .$row['family']."</td>";
echo "</tr>";
---
echo "<tr>";
echo "<th>소아과</th>";
echo "<th>내과</th>";
echo "<th>산과</th>";
echo "<th>정형외과</th>";
echo "</tr>";
echo "<tr>";
echo "<td>".$row['ped_content']."</td>";
echo "<td>".$row['im_content']."</td>";
echo "<td>".$row['ob_content']."</td>";
echo "<td>".$row['os_content']."</td>";
echo "</tr>";
----
echo "</table>";
}
The While phrase in the above php code is just 1, but the number of the result table depend on the number of im_content.
So, I want to union the result of im_content in a cell as the above captured picture.
But, I am short of ability.
Please give me a piece of advice.
Thank you for your concern.
My sql query sentence is as like below.
SELECT code_en.code, code_co.disease_co, code_en.disease_en , hx.family,
hx.personal, note.note, inclusion.inclusion, exclusion.exclusion, ds.ds_content,
------
subject.icd_category, subject.group_code, im.im_content
FROM code_en
LEFT JOIN subject ON code_en.code = subject.code
LEFT JOIN note ON code_en.code = note.code
-------
left join im on code_en.code = im.code
WHERE code_en.code = '".$code."'"
Thank you, Barmar!
I'm not totally sure I understand the question, but I think this is what you want:
SELECT code_en.code, code_co.disease_co, code_en.disease_en , hx.family,
hx.personal, note.note, inclusion.inclusion, exclusion.exclusion, ds.ds_content,
------
subject.icd_category, subject.group_code, GROUP_CONCAT(im.im_content) AS im_content
FROM code_en
LEFT JOIN subject ON code_en.code = subject.code
LEFT JOIN note ON code_en.code = note.code
-------
left join im on code_en.code = im.code
WHERE code_en.code = '".$code."'"