basically I've written the following but I'm wondering what the best way to get $message_id = to the $row['id'] you click on to view an inbox message. If I just statically set $message_id = to say 39 and click on the row that's $row['id'] is 39 it'll open the message.
Basically what it does is list inbox messages I have, and anchor tag them with its row id to be used in the header to show the full contents of that message.
<p>
<?php
$message_id = "39";
if (isset($_GET[$message_id]) && empty($_GET[$message_id])) {
$username = $user_data['username'];
$get_message = mysql_query("SELECT * FROM `users_inbox` WHERE `id` = '$message_id' AND `send_to` = '$username'");
$get_message_result = mysql_fetch_array($get_message);
echo '<h1><u>' . $get_message_result['subject'] . '</u></h1>';
echo $get_message_result['sent_from'] . '<br />';
echo $get_message_result['body'] . '<br />';
echo 'Back';
}
$username = $user_data['username'];
$result = mysql_query("SELECT * FROM `users_inbox` WHERE `send_to` = '$username'");
?>
<table border="1">
<tr>
<td>From</td>
<td>Subject</td>
<td>Date</td>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
echo
'<tr>' .
'<td>' . $row['sent_from'] . '</td>' .
'<td>' . $row['subject'] . '</td>' .
'<td>' . $row['post_date'] . '</td>' .
'</tr>';
}
?>
</table>
</p>
Anyone know if this is even possible, as I know code is read from top to bottom and as far as I'm aware you cant go back upwards at all.
I assume that the $user_data['username'] is set or available,if yes then you could pass a variable name of you choice which points the message id instead of sending only the id (eg: i am setting it as msg_id ), Now you can access the message id via $_GET['msg_id']
<p>
<?php
$username = $user_data['username'];
if ( isset( $_GET['msg_id'] ) ) {
$get_message = mysql_query("SELECT * FROM `users_inbox` WHERE `id` = '$message_id' AND `send_to` = '$username'");
$get_message_result = mysql_fetch_array($get_message);
echo '<h1><u>' . $get_message_result['subject'] . '</u></h1>';
echo $get_message_result['sent_from'] . '<br />';
echo $get_message_result['body'] . '<br />';
echo 'Back';
}else{
$result = mysql_query("SELECT * FROM `users_inbox` WHERE `send_to` = '$username'");
?>
<table border="1">
<tr>
<td>From</td>
<td>Subject</td>
<td>Date</td>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
echo
'<tr>' .
'<td>' . $row['sent_from'] . '</td>' .
'<td>' . $row['subject'] . '</td>' .
'<td>' . $row['post_date'] . '</td>' .
'</tr>';
}
?>
</table>
</p>
Related
I've been trying to create a web application that functions like a library system, and I am currently working on building the table that will display all books in the system. However, after I close the first echo statement to start building the table in HTML, the app seems to just stop seeing it as code and prints the rest of the PHP code to the screen.
Here is the code in question:
<?php
$db = mysqli_connect('34.224.99.227','root','opendoor','library')
or die ('Could not connect to database');
$result = mysqli_query($db,'SELECT * FROM book');
echo '<table id="table_id" class="display">
<thead>
<tr>
<th>ISBN</th>
<th>Title</th>
<th>Author</th>
<th>Description</th>
<th>Status</th>
</tr>
</thead>
<tbody>';
while($row = mysqli_fetch_array($result)) {
echo '<tr>';
echo '<td>' . $row['isbn'] . '</td>';
echo '<td>' . $row['title'] . '</td>';
echo '<td>' . $row['author'] . '</td>';
echo '<td>' . $row['description'] . '</td>';
echo '<td>' . $row['status'] . '</td>';
echo '</tr>';
}
echo '</tbody></table>';
mysqli_close($db);
?>
And here is the corresponding web page output:
ISBN Title Author Description Status '; while($row = mysqli_fetch_array($result)) { echo ''; echo '' . $row['isbn'] . ''; echo '' . $row['title'] . ''; echo '' . $row['author'] . ''; echo '' . $row['description'] . ''; echo '' . $row['status'] . ''; echo ''; } echo ''; mysqli_close($db); ?>
I'm obviously not too well-versed in PHP, so I'm at a loss as to what the problem could be.
After playing around with the settings of my LAMP stack, I realized that I had apparently configured it with PHP 5 in mind, while I had downloaded PHP 7. Once I fixed the discrepancy, everything worked as intended. Thanks for help nonetheless.
I have a PHP page where user can select a province (ex. A, B) then click search. The output will be coming from the database. Now how can I group the data and add BR in between? example:
user choose province: prov_A
output:
program name: FLOOD CONTROL-prov_A-ALLOCATION
FLOOD CONTROL-prov_A-ALLOCATION
ROADS-prov_A-ALLOCATION
ROADS-prov_A-ALLOCATION
I want to separate flood control from roads. Btw, I'm using Wordpress for this. A line break between will do. Also, the field 'allocation' from my excel file contain amounts like 7,000,000.00 or 1,000,000.00 but after importing to phpmyadmin it becomes 7.0 and 1.0. What data field should I use?
CODE:
$sql = "SELECT * FROM projects where province = '$province'";
//select database
mysql_select_db('pdmu');
//query for counting
$query="SELECT COUNT(proj_id) AS 'cnt' FROM `projects` WHERE province = '$province'";
$result=mysql_query($query);
$row2 = mysql_fetch_assoc($result, MYSQL_ASSOC);
print_r($row2['cnt']); print_r('Records Found');
//echo $row2['cnt'] . 'RECORDS FOUND!';
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
echo "<table>";
echo "<tr>";
echo "<th>";
echo "PROGRAM NAME";
echo "</th>";
echo "<th>";
echo "PROVINCE";
echo "</th>";
echo "<th>";
echo "MUNICIPALITY/CITY";
echo "</th>";
echo "<th>";
echo "NO. OF PROJECT";
echo "</th>";
echo "<th>";
echo "PROJECT NAME";
echo "</th>";
echo "<th>";
echo "ALLOCATION";
echo "</th>";
echo "<th>";
echo "PHYSICAL STATUS";
echo "</th>";
echo "<th>";
echo "FINANCIAL STATUS";
echo "</th>";
echo "<th>";
echo "REMARKS";
echo "</th>";
echo "</tr>";
echo $count . $row2;
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
echo '<tr>' . '<td>' . $row['prog_name'] . '</td>' . '<td>' . $row['province'] . '</td>' . '<td>' . $row['municipality'] . '</td>' . '<td>' . $row['proj_no'] . '</td>' . '<td>' . $row['proj_name'] . '</td>' . '<td>' . $row['allocation'] . '</td>' . '<td>' . $row['ph_status'] . '</td>' . '<td>' . $row['fin_status'] . '</td>' . '<td>' . $row['remarks'] . '</td>' .'</tr>';}
mysql_close($conn);
<?php
$sql = "SELECT * FROM projects where province = '$province'";
//select database
mysql_select_db('pdmu');
//query for counting
$query="SELECT COUNT(proj_id) AS 'cnt' FROM `projects` WHERE province = '$province'";
$result=mysql_query($query);
?>
<?php $row = mysql_fetch_assoc($result);
while($row_result = mysql_fetch_array($retval, MYSQL_ASSOC))
{
?>
<tr>
<td><?=$row_result['your fields'];?></td>
</tr>
<?php } ?>
So i've been trying to get one record and edit it by pressing the button that is created in that table, but honestly, i have no idea how to do that. Dx Can anyone help me with this? (Yes, i want the button created for each record. You know, so at the end of every row in the table, every record will have it's own button.)
while($rArt = mysqli_fetch_array($sql)){
echo '<tr><td>' . $rArt['ArtID'] . '</td>';
echo '<td>' . $rArt['FiliaalID'] . '</td>';
echo '<td>' . $rArt['Productnaam'] . '</td>';
echo '<td>' . $rArt['Inkoopprijs'] . '</td>';
echo '<td>' . $rArt['Voorraad'] . '</td>';
echo '<td>' . $rArt['Min_voorraad'] . '</td>';
$voo = $rArt['Voorraad'];
$minvoo = $rArt['Min_voorraad'];
$nodig = $minvoo * 2 - $voo;
$chosen = $rArt['ArtID'];
echo '<td>' . $nodig . '</td>';
echo '<td><input type="submit" name="bestel" value="Bestel"></td></tr>';
if(isset($_GET['bestel'])){
$query = mysqli_query($mysql, "
UPDATE artikel a, voorraad v
SET v.voorraad = v.voorraad + '$nodig'
WHERE a.artid = v.artid
AND v.voorraad = '$chosen'");
}
}
I wouldn't use submit in this case, but just a suggestion:
Why don't you try it this way:
<table>
<tr>
<td>Artikel ID</td>
<td> **<a href="bestelpagina/edit/id/1">** </td>
</tr>
</table>
So you can create an action called Edit in which you can do the changes.
Read the comment in the solution as they are important.
while($rArt = mysqli_fetch_array($sql)){
// echo '<tr><td>' . $rArt['ArtID'] . '</td>';
//The above line i removed and added the line below
echo '<tr><td>' .'<a href=\'admin.php?ArtID='.$rArt['ArtID'].'\'>'.$rArt['ArtID'] .'</td>';
echo '<td>' . $rArt['FiliaalID'] . '</td>';
echo '<td>' . $rArt['Productnaam'] . '</td>';
echo '<td>' . $rArt['Inkoopprijs'] . '</td>';
echo '<td>' . $rArt['Voorraad'] . '</td>';
echo '<td>' . $rArt['Min_voorraad'] . '</td>';
$voo = $rArt['Voorraad'];
$minvoo = $rArt['Min_voorraad'];
$nodig = $minvoo * 2 - $voo;
$chosen = $rArt['ArtID'];
echo '<td>' . $nodig . '</td>';
//echo '<td><input type="submit" name="bestel" value="Bestel"></td></tr>';
//removed this as you dont need input button here.
}///Your while loop should close here not in the ent
if(isset($_GET['bestel'])){
$query = mysqli_query($mysql, "
UPDATE artikel a, voorraad v
SET v.voorraad = v.voorraad + '$nodig'
WHERE a.artid = v.artid
AND v.voorraad = '$chosen'");
}
//} I remove this tag as your while loop should close before isset function
I have extracted hundreds of data from MYSQL database then populated them to a table. Each table has a column name "Preview" which will generate preview button. When we click on that preview button it has to pass Application ID of that row to genpdf.php but I could pass the Application ID of that specific row.
<form id="genpdf" action="genpdf.php" method="POST">
<h3 style="padding:10px;">List of Application Submitted</h3>
<table width="100%" style="padding: 10px;">
<tr>
<td><strong>S. No.</strong></td>
<td><strong>Application ID</strong></td>
<td><strong>Name</strong></td>
<td><strong>Date of Birth</strong></td>
<td><strong>Telephone</strong></td>
<td><strong>Email</strong></td>
<td><strong>Preview</strong></td>
</tr>
<?php
$i = 1;
while($row = mysql_fetch_array($record))
{
echo '<tr><td>' . $i . '</td>';
echo '<td>' . $row['applicationid'] . '</td>';
echo '<td>' . $row['title'] . ' ' . $row['firstname'] . ' ' . $row['middlename'] . ' ' . $row['familyname'] . '</td>';
echo '<td>' . $row['dobmonth'] . '/' . $row['dobday'] . '/' . $row['dobyear'] . '</td>';
echo '<td>' . $row['telephonet4'] . '</td>';
echo '<td>' . $row['emailt4'] . '</td>';
echo '<td><input type="submit" value "Preview" /></td>';
$i += 1;
}
?>
</table>
</form>
You have to replace the form submit button with a regular link that calls the genpdf.php page and adds the applicationId as a HTTP GET parameter.
Preview
In PHP MYSQL_FETCH_ASSOC is omitting Last Row. This never happened. But this time it put me into soup at the last moment.
Even I've put up mysql_num_rows the result is 14 records -- but on list it shows only 13 records and the 14th record is omitted.
Any kind of help is Appreciated.
$uno = $_GET["uno"];
$xtc1 = 'select * from rform where uno="' . $uno . '" order by rno DESC';
$xtc = mysql_query($xtc1) or die('User Reservation Retrival Error : ' . mysql_error());
$trno = mysql_fetch_assoc($xtc);
$trow = mysql_num_rows($xtc);
echo '<p>List of Onlilne Reservations made by <strong style="font-weight:bold; color:red;">' . ucwords($trno["cname"]) . ' (' . $trow . ')</strong></p>';
echo '<table cellpadding="5" cellspacing="0" border="1">';
echo '<tr>';
echo '<td colspan="5" style=" font-size:14px; text-align:center; font-weight:bold; color:red;">' . ucwords($trno["cname"]) . '</td>';
echo '</tr>';
echo '<tr>';
echo '<th>R.NO</th>';
echo '<th>From</th>';
echo '<th>To</th>';
echo '<th>Date & Time of<Br>Travel</th>';
echo '<th>Reserved On</th>';
echo '</tr>';
while($mtn = mysql_fetch_assoc($xtc)){
$dt = $mtn["csdate"] . ' ' . $mtn["ctime"];
echo '<tr>';
echo '<td>' . $mtn["rno"] . '</td>';
echo '<td>' . $dt . '</td>';
echo '<td>' . $mtn["caddr"] . '</td>';
echo '<td>' . $mtn["cdest"] . '</td>';
echo '<td>' . date('d-M-Y',strtotime($mtn["tstamp"])) . '</td>';
echo '</tr>';
}
echo '</table>';
You have an extra $trno = mysql_fetch_assoc($xtc) that you sem to be discarding. This is your missing row. Just remove that line.
deleting the first $trno = mysql_fetch_assoc($xtc); will solve this problem.
In case you need to read the first line of $xtc before the loop. You can change while loop to do-while, without deleted the first $mtn = mysql_fetch_assoc($xtc);
do{
//whatever
}while($mtn = mysql_fetch_assoc($xtc));