I'm trying to fetch and display all user information from mysql database but it doesn't able to show the time on row, but the rest information such as User ID and Username can be displayed. If I run the system in my windows localhost it's just working fine but when I run it using web hosting it doesn't show the date.
Database :
Database Record :
My current coding :
<?php
$sql_select = "SELECT * FROM tbluserinfo";
$result = $conn->query($sql_select);
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
echo "<tr>";
echo "<td>".$row['user_id']."</td>";
echo "<td>".$row['user_name']."</td>";
echo "<td>".$row['user_created_date']."</td>";
echo "</tr>";
}
}
else
{
echo "<td colspan='3' style='color: red;'>No record found.</td>";
}
?>
You could try :
echo date('j F, Y', strtotime($row['user_created_date']));
and make sure your $row['user_created_date'] is not null otherwise it will give you this date:
1 January, 1970
Related
I tried to echo rows from mysql database. So in my code user can enter a value, and then program echoes table around the entered value. That part of the code works fine, but when I tried to echo entered values and corresponding row to the value, it somehow gave me first row. While I needed exact row, which I previously entered.
Here is my code:
$density = $_POST["density"];
$t = $_POST["t"];
$query = $pdo->prepare ("SELECT * FROM mytable WHERE "
."(Density >= '$density'-0.05 AND Density <='$density' +0.05) AND "
."(Temp >='$t' -2 AND Temp <='$t' +2) ");
if (!$query->rowCount() == 0) {
$query -> execute();
while ($results = $query->fetch(PDO::FETCH_ASSOC)){
echo "<table>";
echo "<tr><td>";
echo $results['Temperature'];
echo "</td><td">";
echo $results['Density'];
echo "</td><td>";
echo $results['DensityValues'] + $delden;
echo "</td></tr>";
echo "</table>";
}
}
So currently it prints the first row which is: Temp=>10, Density=>600, DensityValues=>658;
While I need to get values I have enterd and coresponding density value: Temp=>12, Density=>650, DensityValues=>678;
Hello Fellow Stack Users, I have an issue. I am running a booking system and I'm in the process on changing some of the code to ajax so that the user does not have to be redirected. My database has colums. one date and the other one time. the code querys the database and gets one result for each date. december 1, december 2 etc and doesn't show the times. The issue i am having is that i can not run code which i can click the date and it will query the database to find all the time slots associated with that date.
some code below
index.php
$sql = "SELECT DISTINCT day, hour FROM availability WHERE booked='' and day >= CURDATE()";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$next = date("M jS ", strtotime("".$row["day"] .""));
echo "<a class='button' style='margin:10px;' href=fetch.php?pageid=" . $row["day"] . "> <p style='font-size:20px; margin:0px;'>$next</p> ". $row["hour"]. "</a>";
}
} else {
echo "You are booked up for the week";
}
$conn->close();
fetch.php
$sql = "SELECT DISTINCT day FROM availability WHERE booked='' and day >= CURDATE()";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<a class='button' style='margin:10px;' href=book_process.php?pageid=" . $row["id"] . "> <p style='font-size:20px; margin:0px;'>$next</p> ". $row["hour"]. "</a>";
}
} else {
echo "You are booked up for the week";
}
$conn->close();
in fetch you should click a time and then it should update the row in the process page i have not included. I am not very fluent coding ajax but i thought that now is the time to learn.
In mysql I have unix epoch time inserted and it needs to be displayed in calendar like table.
Every timedate should be echoed in row that represents that day.
Code that I have is this and it echoes 31 days in one column and all timestamps in one row. How to put them in correct day/row? Thank you.
<table>
<tr>
<td><strong>day</strong></td>
<td><strong>timestamp</strong></td>
</tr>
<?php
$sel = "select time from rv where id=$id";
$rez = mysql_query($sel) or die(mysql_error());
$n = mysql_num_rows($rez);
for($day=1; $day<32; $day++){
echo "<tr>";
echo "<td>$day.</td>";
while ($re = mysql_fetch_array($rez)){
$time_b = $re["time"];
$time_a = new DateTime("#$time_b");
echo "<td>";
echo $time_a->format('h:i:s');
echo "</td>";
}
echo "</tr>";
}
?>
</table>
Update:
Here is what I get now. And I need every date to be displayed in correct day/row
http://s3.postimg.org/nvmlf1mtv/test.jpg
Supposing you want your days from the database sorted from 1-31, your working the wrong way rond.
You first want to sort the values from the database, store by day and then display them.
Warning: I'm using your code for this answer, but DON'T USE mysql, use mysqli.
//make an array with all 31 days
$mydays=array_fill(1,31,array());
//loop the database results and fill the array
while ($re = mysql_fetch_array($rez)){
$day=date('d',$re["time"]);
//store the value in the $mydays array
$mydays[$day][]=$re["time"];
}
//now loop the days and display them
for($i=1;$i<32;$i++){
if(count($mydays[$i])<1)continue; //the is no data in this day
// else loop the data inside this day
foreach($mydays[$i] as $thisday){
echo "<tr>";
echo "<td>$i</td>";
echo "<td>";
echo date('h:i:s',$thisday);
echo "</td>";
echo "</tr>"
}
}
Attempting to display different data in a table, but am only gettting the most recent result. The only thing I have changed in my code is adding the >CURDATE rather than the most simple *. it has stopped displaying all of the results. can you help?
$result = mysqli_query($con,"SELECT * FROM tripdata WHERE date > CURDATE()");
while($row = mysqli_fetch_assoc($result))
{
echo "<table class='mainpics'>";
echo "<tr><td><a class='mainpic' href='". $row['pageurl'] ."'><img class='mainpic' src='" . $row['mainpic'] . "'/></a></td></tr>";
echo "</table>";
}
mysqli_close($con);
?>
i have this code that will display the items perfectly but having a error pop up that i have to click "OK" too view the page
i have searched the web and from what i understand this has something to do with that the header table has more column than the data itself, i have tried to troubleshot this and got nowhere fast as i am a novice (noob) :/
if anyone can shed some light on this it would be great! :)
The Error
DataTables warning (table id = 'example'): Requested unknown parameter '0'
from the data source for row 0
My Code
<?php
//include database connection
include 'db_connect.php';
//query all records from the database
$query = "select * from repair_jobs";
//execute the query
$result = $mysqli->query( $query );
//get number of rows returned
$num_results = $result->num_rows;
//this will link us to our add.php to create new record
if( $num_results > 0){ //it means there's already a database record
//start table
//creating our table heading
echo "<table id='example' cellpadding='0' cellspacing='0' border='0' class='display' >";
echo "<thead><tr>";
echo "<th>Client</th>";
echo "<th>Type</th>";
echo "<th>Labour</th>";
echo "<th>ourcosts</th>";
echo "</thead></tr><tbody><tr class=\"gradeX\">";
//loop to show each records
while( $row = $result->fetch_assoc() ){
//extract row
//this will make $row['firstname'] to
//just $firstname only
extract($row);
//creating new table row per record
echo "<tr>";
echo "<td>{$client}</td>";
echo "<td>{$type}</td>";
echo "<td>{$labour}</td>";
echo "<td>{$ourcosts}</td>";
echo "</td>";
echo "</tr>";
}
echo "</table>";//end table
}else{
//if database table is empty
echo "No records found.";
}
//disconnect from database
$result->free();
$mysqli->close();
?>
it displays ok but this error puzzling me.