The thing is that I have made application form which saves in db. And I want on other page to display just some rows of the mysql table in php table where the first column is hyperlink to the single application as it is in the form. My question is how it can automatically make hyperlinks and pages for each form?
This is my code for now
mysql_connect("host", "user", "password") or die(mysql_error());
mysql_select_db("dbname") or die(mysql_error());
$data = mysql_query("SELECT * FROM applications ") or die(mysql_error());
echo ' <table width="760" border=1>
<tr>
<th>Заявление<br>От дата:</th>
<th>От/До</th>
<th>Статус</th>
</tr>';
while($info = mysql_fetch_array( $data ))
{
echo '
<tr>
<td>'.$info['today'] .'</td>
<td>От '.$info['data1data'] .'.'.$info['data1mesec'] .'.'.$info['data1god'] .' до '.$info['data2data'] .'.'.$info['data2mesec'] .'.'.$info['data2god'] .' </td>
<td>';
if($info['status'] == 1) {
echo '<img src="Images/approved.jpg" />';
}
else {
echo '<img src="Images/declined.jpg" />';
}
echo ' </td>
</tr> ';
}
echo '</table>';
The result I am trying to get is a table with 3 columns and rows for every application and from the first column of the application I get redirected to a single webpage for that application form and this link to be auto made by code something like "applications.php?id=[application id]"
I don't understand so much but:
<?php
$query = mysql_query("SELECT * FROM applications");
while($t = mysql_fetch_array($query)){
echo ''.$t['name'].'<br/>';
}
?>
Don't know what's the problem.
Related
sorry, I'm still very novice with server-side (back-end) development, thank you for helping in advance.
Recently, I've been developing a web page which you can choose which table you want to display from the mySQL server, then it will create an editable table in HTML using the mySQL table data.
So far, I'm only able to fetch which table to get from mySQL and display it using in the form of an array, which doesn't really look that great.
I wonder if you can display the array in a form of an editable table without knowing the how many columns, column names as it is different for every different table.
Later on, I have to upload the cell that is updated back to mySQL database and I've no idea how to do that as well.
Sorry for the trouble, this website had been a great help for me and the community is great. Thanks a lot!
Image of what I have so far:
Code I have so far:
SelectTable:
<div class="table-responsive">
<b>List of Tables</b>
<table class="table table-condensed selection_table">
<tbody>
<tr>
<?php
if ($tableResult = mysqli_query($conn,"show tables")){
while($table = mysqli_fetch_array($tableResult)) {
echo("<tr> <td>". "<a class = 'list_tables' href = ?clickedTable=$table[0]>". $table[0] . "</a>" ."</td> </tr>");
}
}else{
die("<b>"."No Table in Database!"."</b>");
}
if (isset($_GET['clickedTable'])){
$selectedTable = $_GET["clickedTable"];
}
?>
</tr>
</tbody>
</table>
</div>
Fetch array from selected table:
<?php
if (isset($_GET['clickedTable'])){
echo("<b> Current Table is: </b> ".$selectedTable. "<br/>");
$query = "SELECT * FROM $selectedTable";
if ($result = mysqli_query($conn , $query)) {
while ($row = mysqli_fetch_array($result)){
print_r($row);
}
}
}else{
echo("Please select a table");
}
?>
I have a mysql database with some data.here i display data on one page Now I want to display this data on next page please give me suggestion how I can do this .........
I need some modifications in this code like
I want to display table this table on next page(book.php page that is populated with the database)......
Second thing that I need to know is it possible to store the value of calendar in session variable (is it ???than how?)
<?php
if(isset($_POST['search'])){
$from = $_POST['from'];
$to = $_POST['to'];
$query = mysql_query("select * from schedule where Destinatio='$from' AND Arriva ='$to'");
$c = mysql_num_rows($query);
if (!$query) {
die('Invalid query: ' . mysql_error());
}
if($c>0)
{
?>
<table>
<tr align="center"><td width="120"><span class="style23">Destination</span> </td>
<td width="57"><span class="style23">Arrival</span></td>
<td width="121"><span class="style23">Departure time</span></td>
<td width="98"><span class="style23">Arrival Time</span></td>
<td width="44"><span class="style23">Fare</span></td>
<td width="85"><span class="style23">Bus_type</span></td>
<td width="84"><span class="style23">Total_Seats</span></td>
<td width="81"><span class="style23">Available</span></td>
<td width="52"> </td>
</tr>
</section>
<?php
while($r1 = mysql_fetch_array($query))
{
$schedule= $r1['id'];
$Destinatio = $r1['Destinatio'];
$Arriva= $r1['Arriva'];
$Departure_time = $r1['Departure_time'];
$Arrival_time = $r1['Arrival_time'];
$Fare = $r1['Fare'];
$Bus_type = $r1['Bus_type'];
$Total_Seats = $r1['Total_Seats'];
$bust = $schedule.'schedule';
$query1 = mysql_query("SELECT * from $bust where status='Available'");
echo $query1;
if (!$query1) {
die('Invalid query: ' . mysql_error());
}
$c = mysql_num_rows($query1);
?>
<tr align="center"><td><?php echo $Destinatio;?></td><td><?php echo $Arriva;?></td><td><?php echo $Departure_time;?></td><td><?php echo $Arrival_time;?></td><td><?php echo $Fare;?></td><td nowrap="nowrap"><?php echo $Bus_type;?></td><td><?php echo $c;?></td><td>Book
</td>
</tr></table>
</form>
There are three main ways to pass variables:
Using a form button using $_POST variables to pass the content
(generally best when you also have user input).
Using an HTML anchor link to pass the variables through $_GET
Using a SESSION variable that can be accessed on all pages on your site.
Using SESSION variables is the more secure way, but it the data isn't secret use the $_GET method.
To store something in a SESSION variable you need to use:
start_session();
$_SESSION['varname'] = value;
on the following page, you can read your SESSION variable just by using it's name. For example:
start_session();
echo $_SESSION['varname'];
I am trying to build a staff page, which quesries the MySQLi database holding registered users, and displays only moderators, admins, and super admins. This is the code I have. For some reason, nothing shows up in the table on the page. I have no fatal erros, so the code is "technically" correct, however the logic isn't outputting what I want.
The code below should query the database, fetch the row of info as an array, output the username and registration date into the table, and keep looping until there are now more rows left. Though, as I said, nothing is output. I have no idea what I am doing wrong.
If it makes a difference, this is a custom page in myBB forum software. I know the page is setup correctly because everything displays, except the info I am attempting to pull form the database.
<?php
global $headerinclude, $header, $theme, $footer, $lang;
if(!$mybb->user['uid'])
{
error_no_permission();
}
$lang->load('modcp');
$mysqli = new mysqli("XXXXXXXXX","XXXXXXXXXXX","XXXXXXXXX","XXXXXXXX");
$query_result = $mysqli->query("SELECT uid,username,usergroup,regdate FROM mybb_users ORDER BY regdate ASC");
if ($db->num_rows($query_result) > 0)
{
$usertablerows = "";
while($users = mysqli_fetch_row($query_result))
{
if($users['usergroup'] != 3 || $users['usergroup'] != 4 || $users['usergroup'] != 6)
{
$pass = "true";
}
else
{
$staffuseruid = $users['uid'];
$rawregdate = $users['regdate'];
$usergroupvalue = $users['usergroup'];
$staffusername = $users['username'];
$staffuser = get_user($staffuserid);
$usertablerows .= ' <tr>
<td class="trow1">' . build_profile_link($staffusername, $staffuserid). '</tf>
<td class="trow2">' . my_date($mybb->settings['dateformat'], $rawregdate). '</td>
</tr>';
}
}
}
$template='<html>
<head>
<title>'.$pages['name'].'</title>
{$headerinclude}
</head>
<body>
{$header}
<table border="0" cellspacing="1" cellpadding="2" class="tborder">
<tr><td class="thead" colspan="4"><strong>The Staff</strong></td></tr>
<tr>
<td class="tcat"><span class="smalltext"><strong>Username</strong></span></td>
<td class="tcat"><span class="smalltext"><strong>Registered</strong></span></td>
</tr>
{$usertablerows}
</table>
{$footer}
</body>
</html>';
mysqli_close($mysqli);
$template=str_replace("\'", "'", addslashes($template));
add_breadcrumb($pages['name']);
eval("\$page=\"".$template."\";");
output_page($page);
?>
You can check by appending database name to table name in mysql query.
Im not sure if a similar question has been asked before, but here goes anyway. (I did do a search and found nothing relating to my question).
I am developing a website in which videos are played using the HTML5 video player. I have a connection to my database, a "watch" page that pulls all the correct data using a variable linked to the id (watch.php?v=1). I would like to have an index page where the most recent videos are pulled. They are ordered by the column "id" and everything works when I try and pull one result from the query. How would I go about getting multiple values? Here is my php code (server details hidden):
<?php
$mysqli = new mysqli("HIDDEN", "HIDDEN", "HIDDEN", "HIDDEN");
$sql = "
SELECT id, title, imgsrc, description
FROM videos
ORDER BY id DESC
LIMIT 2
";
$result = $mysqli->query($sql);
$video = mysqli_fetch_array($result, MYSQLI_ASSOC);
mysqli_close($mysqli);
?>
And here is my HTML code for the table.
<table>
<tr>
<td><h2><? echo $video['title']; ?></h2></td>
</tr>
</table>
That isn't the full code, but once I know the procedure I can apply it where needed!
I'm quite new to php and mysql, I can connect to databases but that's about it so a full walkthrough about what does what would be great!
Many Thanks,
James Wassall
You can iterate in for or while loop by calling mysqli_fetch_array($result, MYSQLI_ASSOC):
<table>
<?php
$mysqli = new mysqli("HIDDEN", "HIDDEN", "HIDDEN", "HIDDEN");
$sql = "
SELECT id, title, imgsrc, description
FROM videos
ORDER BY id DESC
LIMIT 2
";
$result = $mysqli->query($sql);
while($video = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
?>
<tr>
<td><h2><? echo $video['title']; ?></h2></td>
</tr>
<?php
}
mysqli_close($mysqli);
?>
</table>
Note that you should consider checking error statements, null controls etc.
try this
while($video = $result->fetch_array(MYSQLI_ASSOC))
{
?>
<tr>
<td><h2><?php echo $video['title']; ?></h2></td>
</tr>
<?php
}
?>
Each time you call mysqli_fetch_array, only one row is fetched.
You need to do something like
while ($video = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
// output $video['title']
}
(according to: http://www.php.net/manual/en/mysqli-result.fetch-array.php)
Try this,
<table>
<?php while($row = $result->fetch_array(MYSQLI_ASSOC)){ ?>
<tr>
<td><h2><? echo $row['title']; ?></h2></td>
<td><h2><? echo $row['description']; ?></h2></td>
</tr>
<?php } ?>
</table>
I am beginner to PHP and mySQL. I am creating a navigation trough my database. I have two tables set up one is the main nav items and one is the sub nav items. They are connected by the subject_id. I am using a loop to display them. The first table displays and the second table leaves space for where the information should be but it does not show up. I think it must be something in the SQL settings but I have no idea. Here is my code(i know the database is connected):
<?php require_once("includes/connection.php") ?>
<?php require_once("includes/functions.php") ?>
<?php include("includes/headder.php") ?>
<table id="structure">
<tr>
<td id="navigation">
<ul class="subjects">
<?php
$subject_set = mysql_query("SELECT * FROM subjects", $connection);
if(!$subject_set){
die("database query failed: " . mysql_error());
}
while ($subject = mysql_fetch_array($subject_set)) {
echo "<li>" . $subject["menu_name"] . "</li>";
$page_set = mysql_query("SELECT * FROM pages WHERE subject_id = {$subject["id"]}", $connection);
if(!$page_set){
die("database query failed: " . mysql_error());
}
echo "<ul class=\"pages\">";
while ($page = mysql_fetch_array($page_set)) {
echo "<li>" . $page["menu_name"] . "</li>";
}
echo "</ul>";
}
?>
</ul>
</td>
<td id="page">
<h2>Content Area</h2>
</td>
</tr>
</table>
<?php include("includes/footer.php") ?>
Since you mentioned that white space is showing where the data should be, it appears that rows are indeed found. Consequently, your select statement should be ok. This most likely means that the index "menu_name" can't be found on the $page record.
Check to make sure that "menu_name" is indeed a column of the pages table.
To test what valid columns the $page record has you can use the following inside the while $page loop:
var_dump($page);
If the subject id is an integer you do not need single quotes in the where clause. However, if the subject_id contains any non-integer characters, your select statement would need to be:
$page_set = mysql_query("SELECT * FROM pages WHERE subject_id = '{$subject["id"]}'", $connection);