I am not sure if this is possible. What i want to do is create a new table every time a user submits a form. So far i have created my form and also insert these values into a database. I am able to echo a table of what was submitted. However, every time this form is submitted i want it to create a separate table with the new info. So it would show the previous form submission in one table and the newly submitted form data in another. How do i do this? Thank you
This is my PHP code for inserting and selecting the table:
$connect=mysql_connect('localhost','root','');
$db=mysql_select_db('dialogue');
if($connect)
{
$sql="INSERT INTO dialogue(english1,english2,english3,english4,english5,english6,english7,english8,english9,english10,english11,english12,english13,english14,english15,english16,english17,english18,english19,english20,sanskrit1,sanskrit2,sanskrit3,sanskrit4,sanskrit5,sanskrit6,sanskrit7,sanskrit8,sanskrit9,sanskrit10,sanskrit11,sanskrit12,sanskrit13,sanskrit14,sanskrit15,sanskrit16,sanskrit17,sanskrit18,sanskrit19,sanskrit20) VALUES($english1,$english2,$english3,$english4,$english5,$english6,$english7,$english8,$english9,$english10,$english11,$english12,$english13,$english14,$english15,$english16,$english18,$english19,$english20,$sanskrit1,$sanskrit2,$sanskrit3,$sanskrit4,$sanskrit5,$sanskrit6,$sanskrit7,$sanskrit8,$sanskrit9,$sanskrit10,$sanskrit11,$sanskrit12,$sanskrit13,$sanskrit14,$sanskrit15,$sanskrit16,$sanskrit18,$sanskrit19,$sanskrit20)";
$query=mysql_query($sql);
if($query)
{
$sql="SELECT * FROM dialogue";
$query=mysql_query($sql);
if($query)
{
echo "<table border=1>";
echo "<tr><th>English</th><th>Sanskrit</th><th>Root</th></tr>";
while($row=mysql_fetch_array($query))
{
{
echo "<tr>";
echo "<td>" . $row['english1'] . "</td>";
echo "<td>" . $row['sanskrit1'] . "</td>";
echo "<td>" . $row['english11'] . "</td>";
echo "<td>" . $row['sanskrit11'] . "</td>";
echo "<td>" . $row['english2'] . "</td>";
echo "<td>" . $row['sanskrit2'] . "</td>";
echo "<td>" . $row['english12'] . "</td>";
echo "<td>" . $row['sanskrit12'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
}
}
}
}
?>
Related
I have created a database in phpMyAdmin and I have 10 rows of data and each row has a column to show its website address. I want to make the website address clickable.
I used the below array method to show my website address link, but it doesn't work
$website = array(
array("Google","https://code.tutsplus.com"),
array("Bing","https://weatherstack.com"),
array("W3","https://www.w3schools.com")
);
foreach ($website as $urlitem){
echo "<a href='".$urlitem[1]."'></a>";
}
// this gets an associative array (ie the keys can be used as well as the indicies)
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
// The below code displays my table
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['type'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['street'] . "</td>";
echo "<td>" . $row['city'] . "</td>";
echo "<td>" . $row['region'] . "</td>";
echo "<td>" . $row['code'] . "</td>";
echo "<td>" . $row['phone'] . "</td>";
echo "<td><a href='".$urlitem[0]."'>" .$row["website"] ."</td>";
echo "</tr>";
}
}
In the foreach loop, the issue is you are not print out anything to be displayed for anchor tag. Means you anchor tag exists but it does not have any content to be shown on html;
YOUR CONTENT MISSING PART
After that in your while loop, you are using the variable $urlitem which does not exists. You either need to declared it outside your foreach or need to use the $website variable to get the url.
Here is a little demonstration of what I want achieved.
What I want, is a clickable row with additional information fetched from the database.
I've seen some examples with Jquery, but those have some kind of static information in the expanded area. I want to load in this additional information, only after the row is clicked - so I wont have to load in too much information that might not be used.
Now, inside the expanded area, I need the additional information to be fetched like:
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['manufacturer'] . "</td>";
echo "<td>" . $row['describtion'] . "</td>";
echo "<td>" . $row['rdate'] . "</td>";
echo "<td>" . $row['locked'] . "</td>";
echo "</tr>";
}
But only if a specific row is clicked.
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("phone", $con);
$result = mysql_query("SELECT * FROM info");
echo "<table border='1'>
<tr>
<th>Model</th>
<th>Software</th>
<th>Carrier</th>
<th>Price</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['model'] . "</td>";
echo "<td>" . $row['os'] . "</td>";
echo "<td>" . $row['carrier'] . "</td>";
echo "<td>" . $row['price'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
I have really done extensive searching, but that didn't get me closer to a solution.
Would it be better if I added HTML to the code, and somehow fetched the data inside the td tags?
I ended up using Datagrid.
It has the exact functionality I was looking for, and alot of tutorials to get you started.
http://www.jeasyui.com/tutorial/datagrid/datagrid21.php
I have no idea how to explain myself which is why the question isn't even a question. I need to have a table dynamically created from data on mysql (which I've done) but I need to be able to have input in the cells under some of the headings (responsibility, organization, independent work...) When this data is submitted, I need it to be student specific. In other words, when I pull up Johnny Rotten's data, I need to be able to see all the comments under those headings that were submitted (yes this is for teaching). The number of students can vary which is why i need the whole thing to be dynamic. If this is not possible, please let me know. AND if you haven't figured it out already, I am brand new and self-taught!
Here's what I have...
<?php
include 'connect.php';
if ($db_found) {
$SQL = "SELECT * FROM studentlist WHERE teacher1='smith' OR teacher2 ='smith' OR
teacher3='smith' ORDER by homeroom";
$result = mysql_query($SQL);
echo "<table border='1'>
<tr>
<th>Student</th>
<th>Homeroom</th>
<th>Responsibility</th>
<th>Organization</th>
<th>Independent Work</th>
<th>Collaboration</th>
<th>Initiative</th>
<th>Self Regulation</th>
</tr>";
while ($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['student'] . "</td>";
echo "<td>" . $row['homeroom'] . "</td>";
echo "<td>" . "" . "</td>";
echo "<td>" . "" . "</td>";
echo "<td>" . "" . "</td>";
echo "<td>" . "" . "</td>";
echo "<td>" . "" . "</td>";
echo "<td>" . "" . "</td>";
echo "</tr>";
}
echo "</table>";
}
mysql_close($connect);
?>
I have a database table with student room assignments. Each student has a specific hall, floor, and apartment. I need to display each student in a specific table so the results look like a floor layout. Below is an example. The student ID needs to be in the correct Apartment slot. There could be several ID's per apartment. Right now it just lists them down the page.
Apartment 102 Apartment 101
Apartment 104 Apartment 103
Apartment 106 Apartment 105
$query = "select res.ID_NUM as ID, res.APARTMENT
From Residents res
Where res.sess_cde = '$pulledsession'
and res.ROOM_ASSIGN_STS = 'A'
and res.BLDG_CDE = '$pulledhall'
and res.FLOOR = '$pulledfloor'";
$result = odbc_exec($connect, $query);
echo "<table style='padding:25;'>
<tr>
<th>Apartment</th>
<th>ID</th>
</tr>";
while(odbc_fetch_row($result)){
$ID = odbc_result($result,ID);
$APARTMENT = odbc_result($result,APARTMENT);
if ($APARTMENT == $pulledfloor.'01')
{
echo "<tr >";
echo "<td>" . $pulledfloor.'01' . "</td>";
echo "<td>" . $ID . "</td>";
echo "</tr>";
}
else if ($APARTMENT == $pulledfloor.'02')
{
echo "<tr>";
echo "<td>" . $pulledfloor.'02' . "</td>";
echo "<td>" . $ID . "</td>";
echo "</tr>";
}
else if ($APARTMENT == $pulledfloor.'03')
{
echo "<tr>";
echo "<td>" . $pulledfloor.'03' . "</td>";
echo "<td>" . $ID . "</td>";
echo "</tr>";
}
else if ($APARTMENT == $pulledfloor.'04')
{
echo "<tr>";
echo "<td>" . $pulledfloor.'04' . "</td>";
echo "<td>" . $ID . "</td>";
echo "</tr>";
}
else if ($APARTMENT == $pulledfloor.'05')
{
echo "<tr>";
echo "<td>" . $pulledfloor.'05' . "</td>";
echo "<td>" . $ID . "</td>";
echo "</tr>";
}
else if ($APARTMENT == $pulledfloor.'06')
{
echo "<tr>";
echo "<td>" . $pulledfloor.'06' . "</td>";
echo "<td>" . $ID . "</td>";
echo "</tr>";
}
}
echo "</table>";
You would need to retrieve the room number as well. After that, one way to do it would be to load the results into an associated array:
$rooms[$row['roomNumber']] = $resName; // Example
Once you have the array built, then you can echo it back out into a table, either manually (build the full table and echo each one with
echo "<tr><td>".$rooms['102']."</td><td>".$rooms['101']."</td></tr>";
or similar, or do it dynamically by incrementing two room numbers in a loop.
If you have multiple students in a room, then tack on more depth to the array:
$rooms[$row['roomNumber']][] = $resName;
Then use a loop in each cell to echo it back out.
I'm a new member of StackOverflow, and although I've been using the website for a long time, it's my first time posting a question, in a hope that someone will be able to help me. I'll start by saying that my knowledge of PHP and MySQL is basic, but what I'm trying to do isn't too complex in my opinion, so hopefully I won't be asking for much. I've done a lot of prior research, but I just couldn't find the right answer.
In short, this is what I'm trying to do:
I've got an html form, which upon submission writes data to a database, and then publishes a table on a separate html page. With each successful submission a new table gets generated and published, while the old one gets pushed underneath. This all works fine, and I've also implemented pagination so that only 5 tables are visible per page.
What I'd like to be able to do is allow people to ONLY view/display results (tables) based on a specific criteria, in this case "rating", by selecting a rating from a drop-down on the page where tables are published. Rating is one of the fields in my form which gets submitted to a database and then published in one of the rows in a table.
Below is the code which publishes tables. Thanks in advance for your help!
<?php
include('dbconnect.php');
mysql_select_db("vtracker", $con);
$result = mysql_query("SELECT * FROM userdata");
$age = "Age:";
$rating = "Rating:";
$country = "From:";
$name = "Name:";
while($row = mysql_fetch_array($result))
{
echo "<table id='mft_table' cellspacing='0'>";
echo "<tbody>";
echo "<tr>";
echo "<td class='row1'>" .$name . " " . $row['personsname'] . "</td>";
echo "<td rowspan='4'>";
echo "<div class='mft_column'>" . $row['mft'] . "</div>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td class='row2'>" . $country . " " . $row['nationality'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td class='row3'>" . $age . " " . $row['personsage'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td class='row4'>" . $rating . " " . $row['rating'] . "</td>";
echo "</tr>";
echo "</tbody>";
echo "<br>";
echo "</table>";
}
?>
for both true and false use can add thid in your code:
if($_POST['rating_dropdown']!='')
{
$temp_rating = $_POST['rating_dropdown'];
$query=mysql_query("SELECT * FROM userdata WHERE rating = '$temp_rating'");
}
else
{
$query=mysql_query("SELECT * FROM userdata");
}
Dunno if this works, it's just a hinch. haha.
It will see if the rating is true(not null), if it's true it will echo the results.
while($row = mysql_fetch_array($result))
{
if ($rating)
echo "<table id='mft_table' cellspacing='0'>";
echo "<tbody>";
echo "<tr>";
echo "<td class='row1'>" .$name . " " . $row['personsname'] . "</td>";
echo "<td rowspan='4'>";
echo "<div class='mft_column'>" . $row['mft'] . "</div>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td class='row2'>" . $country . " " . $row['nationality'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td class='row3'>" . $age . " " . $row['personsage'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td class='row4'>" . $rating . " " . $row['rating'] . "</td>";
echo "</tr>";
echo "</tbody>";
echo "<br>";
echo "</table>";
}
}
Once the dropdown gets selected and posted to your display page, use this code:
$temp_rating = $_POST['rating_dropdown'];
mysql_query("SELECT * FROM userdata WHERE rating = '$temp_rating'");
Keep in mind, however, that you should be using PDO or mysqli extension, not the mysql extension. According to PHP's website:
This extension is deprecated as of PHP 5.5.0, and will be removed in
the future. Instead, the MySQLi or PDO_MySQL extension should be used.
See also MySQL: choosing an API guide and related FAQ for more
information.