PHP - View The Date With Other Mysql Data
this is my query
Code: [Select] SELECT SUM(no_Yards) AS 'yards', AVG(no_yards) AS 'avg', MAX(no_Yards) AS 'max', MIN(no_Yards) AS 'min' FROM swimming WHERE Season = '$ws' and when i display the data i want to display the date that the max and the min happened (from the database in the column Day_Swam) something like this Code: [Select] <?php echo "<tr>"; echo "<td style='background-color:#F90'>Max Length:</td>"; echo "<td>" . number_format($wsi_row['max']) . "</td>"; echo "<td>" . DATE WOULD GO HERE . "</td>"; echo "</tr>"; echo "</tr><tr>"; echo "<td style='background-color:#F90'>Min Length:</td>"; echo "<td style='background-color:#FF9'>" . number_format($wsi_row['min']) . "</td>"; echo "<td>" . DATE WOULD GO HERE . "</td>"; echo "</tr>"; ?> Similar TutorialsHello im new to php and i cant seems to view my database in my php
<?php include('../connect.php'); $sds=$_SESSION['SESS_FIRST_NAME']; $result = mysql_query("SELECT * FROM paymentdetails WHERE idnumber='$sds'"); while($row = mysql_fetch_array($result)) { echo '<tr class="record">'; echo '<td style="border-left: 1px solid #C1DAD7"><div align="left">'.$row['date'].'</div></td>'; echo '<td><div align="left">'.$row['amount'].'</div></td>'; echo '</tr>'; } ?> </tbody> </table>Here my database im really confuse on what to do CREATE TABLE IF NOT EXISTS `paymentdetails` ( `id` int(11) NOT NULL AUTO_INCREMENT, `idnumber` varchar(30) NOT NULL, `date` varchar(30) NOT NULL, `amount` varchar(30) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; -- -- Dumping data for table `paymentdetails` -- INSERT INTO `paymentdetails` (`id`, `idnumber`, `date`, `amount`) VALUES (1, 'SID-YWU49JU', '2014-08-07', '50000'); SELECT * FROM `booking_tbl` WHERE booking_status = 'Check In' AND departure_date_time = NOW()"I use the datetime datatype for the departure_date_time so i can get data from that data because it checking the date and time but i want it to check on the date from the datetime datatype So how can i get the data only with that date without the time in the mysql datetime datatype hi there..im new to php mysql and im having trouble inserting a string data to mysql from a php date() function. here's my code: Code: [Select] $year = date('Y'); echo $year; $insertSQL = sprintf("INSERT INTO tbl_elections (election_id=$year)"); mysql_select_db($database_organizazone_db, $organizazone_db); $Result1 = mysql_query($insertSQL, $organizazone_db) or die(mysql_error()); when i try to output the $year variable on a webpage, it returns "2012" but when i try to insert this data into my database table, it returns an error like this: check the manual that corresponds to your MySQL server version for the right syntax to use near '=2012)' is there a way to convert "2012" into a normal string data type? Hi all. How can i see all the difference between two dates in a column. I know to see a single date difference we can do: $stmt = $pdo->query("SELECT DATEDIFF(date_paid, next_due) AS diffdate FROM table_name"); while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo $row['diffdate']; } but i want all the difference to show in a table along with other details. thanks Hi, I'm looking for a code to view the date of the past weekdays. Forexample, if it's thursday, I want it to view the dates for wednesday, tuesday, monday, Friday before. Thank you in advance. Please help! how can i query data from different tables? I've tried so many codes already but it won't work.
Attached Files
Untitled1.png 39.93KB
0 downloads I have a page that lists the available records in the database and has links that allow one to view details, edit existing details and delete the data. when i click the view details link, i dont get the correct details for the person but for another person in the database . the link to edit existing details is also not working. following is my code. help!!!! //list available records <? $CONTENT=" <form name=\"form1\" method=\"post\" action=\"\"> <table width=\"100%\" border=\"0\"> <tr> <td width=\"19%\" align=\"right\"><font size='-1px'>Search for : </font></td> <td width=\"61%\" colspan=\"2\"><label> <select name=\"select\" id=\"select\"> <option value=\"std\">Student Name</option> <option value=\"class\">Class Name</option> <option value=\"std_id\">Student ID</option> </select> </label> <label> <input type=\"text\" name=\"textfield\" id=\"textfield\"> <input type=\"submit\" name=\"button\" id=\"button\" value=\"Submit\"> </label></td> <td width=\"10%\"> </td> </tr> </table> <table width=\"100%\" border=\"0\"> <tr bgcolor=\"#666666\"> <td align=\"center\"> </td> <td align=\"center\"> </td> <td colspan=\"2\" align=\"center\"><font size='-1px'>Pages x of xn</font></td> <td align=\"center\"> </td> <td align=\"center\"> </td> <td align=\"center\"> </td> <td colspan=\"3\" align=\"center\"> </td> </tr> <tr bgcolor=\"#999999\"> <td align=\"center\" width='2%'> </td> <td align=\"center\" width='2%'><font size='-1px'>#</font></td> <td align=\"center\" width='11%'><font size='-1px'>Class</font></td> <td align=\"center\" width='23%'><font size='-1px'>Names</font></td> <td align=\"center\" width='13%'><font size='-1px'>Fees Status</font></td> <td align=\"center\" width='21%'><font size='-1px'>Guardian</font></td> <td align=\"center\" width='18%'><font size='-1px'>Teacher</font></td> <td colspan=\"3\" align=\"center\"> </td> </tr>"; /*$query = "SELECT * FROM `student`, `payment`, `class`, `parent_details`, `teacher` WHERE `payment`.`student_id`=`student`.`student_id` and `student`.`class_id` = `class`.`class_id` and `student`.`guardian_id`=`parent_details`.`parent_id` and `teacher`.`class_id` = `class`.`class_id`";*/ //$student_id = $_GET['std_id']; /* $query= "SELECT `student`.`student_id` FROM `student` FULL JOIN `payment` ON `student`.`student_id` = `payment`.`student_id` ORDER BY `student`.`student_id`";*/ $query = "select * from `student`, `payment`, `class`, `parent_details`, `teacher` where payment.student_id = student.student_id and student.class_id = class.class_id and student.guardian_id = parent_details.parent_id"; $result = mysql_query($query); //$numstudents = mysql_num_rows($result); $count=1; //if($count = 0; $count<=$num_students; $count++) //{ while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $CONTENT.="<tr bgcolor=\"#CCFFFF\"> <td><label> <input type=\"checkbox\" name=\"checkbox\" id=\"checkbox\"> </label></td> <td><font size='-1px'>".$count."</font></td> <td><font size='-1px'>".$row["class_name"]."</font></td> <td><font size='-1px'>".$row["first_name"]." ".$row["last_name"]."</font></td> <td><font size='-1px'>".$row["amount"]."</font></td> <td><font size='-1px'>".$row["fname"]."</font></td> <td><font size='-1px'>".$row["tr_name"]."</font></td> <td width=\"2%\"><a href=\"student_details.php?std_id=".$row["student_id"]."\"><img src=\"images/b_browse.png\" height=\"12\" alt=\"Details\"></a></td> <td width=\"2%\"><a href=\"student_edit.php?action=edit&std_id=".$row["student_id"]."\"><img src=\"images/b_edit.png\" height=\"12\" alt=\"Edit\"></a></td> <td width=\"2%\"><a href=\"student_edit.php?action=del&std_id=".$row["student_id"]."\"><img src=\"images/b_drop.png\" height=\"12\" alt=\"Delete\"></a></td> </tr> "; $count++; } $CONTENT.="</table> </form>"; ?> //view details <? $query = "SELECT * FROM `student`, `academic_background`, `class` WHERE `academic_background`.`student_id`=`student`.`student_id` "; //and `student`.`class_id` = `class`.`class_id`"; //`academic_background`.`student_id`=`student`.`student_id` and `student`.`class_id` = `class`.`class_id`"; $result = mysql_query($query); //$count = 0; //$num_students = mysql_num_rows($result); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { //$student_id = $_GET['std_id']; //$bg_id = $_GET['bg_id']; $CONTENT=" <form> <table width=\"100%\" border=\"0\"> <tr> <td width=\"38%\"><img src=\"images/images1.jpg\" /></td> <td width=\"62%\"></td> </tr> <tr> <td><font size='+2px'>Student ID:</font></td> <td><font size='+2px'>".$row["student_id"]."</font></td> </tr> <tr> <td><font size='+2px'>Student Name:</font></td> <td><font size='+2px'>".$row["first_name"]." ".$row["last_name"]."</font></td> </tr> <tr> <td><font size='+2px'>Date of Birth:</font></td> <td><font size='+2px'>".$row["dob"]."</font></td> </tr> <tr> <td><font size='+2px'>Current Class:</font></td> <td><font size='+2px'>".$row["class_name"]."</font></td> </tr> <tr> <td><font size='+2px'>Primary School:</font></td> <td><font size='+2px'>".$row["pschool"]."</font></td> </tr> <tr> <td><font size='+2px'>K.C.P.E Marks:</font></td> <td><font size='+2px'>".$row["total_marks"]."</font></td> </tr> </table> </form> "; // $count += 1; } ?> edit details <? if($_GET['action']=="edit") { $std_id = $_GET['std_id']; $query= "SELECT * FROM `mackenzie`.`student` WHERE std_id = '$student_id'"; $result= mysql_query($query); //assign student info to variablea list($student_id, $first_name,$last_name,$date_of_birth,$class_id,$picture,$home,$guardian_id) = mysql_fetch_array($result, MYSQL_ASSOC); include("/modify.php"); } ?> Hi I will try and explain this as best I can, as I am not sure if the "include" is causing the problem. What I am trying to achieve is count the total number of vehicles in the "vehicles" db table and pass it to views (I have recently moved over to MVC so still learning so please be kind and keep it simple for me please) I have a folder in views called "vehicletracker" , within this folder I have 2 files "index.php" and "widget.php".........The "widget.php" file is an "include" within "index php". The problem I am having is passing data from the controller to the view, I keep getting an "Undefined index: total" error and wonder if someone can help and show me where I am going wrong. This is my Model
<?php class Widget { private $db; public function __construct(){ $this->db = new Database; } public function countVehicles(){ $this->db->query("SELECT * FROM vehicles"); return $this->db->rowCount(); } } This is my controller
<?php class Widgets extends Controller{ public function __construct(){ $this->widgetModel = $this->model('Widget'); public function widget (){ $data['total'] = $this->widgetModel->countVehicles(); $this->view('vehicletracker/widget', $data); } } And my view
<h2 class="text-white"><?php echo $data['total']; ?></h2>
Thanks in advance for any help you can give I have tried a large number of "solutions" to this but everytime I use them I see 0000-00-00 in my date field instead of the date even though I echoed and can see that the date looks correct. Here's where I'm at: I have a drop down for the month (1-12) and date fields (1-31) as well as a text input field for the year. Using the POST array, I have combined them into the xxxx-xx-xx format that I am using in my field as a date field in mysql. <code> $date_value =$_POST['year'].'-'.$_POST['month'].'-'.$_POST['day']; echo $date_value; </code> This outputs 2012-5-7 in my test echo but 0000-00-00 in the database. I have tried unsuccessfully to use in a numberof suggested versions of: strtotime() mktime Any help would be extremely appreciated. I am aware that I need to validate this data and insure that it is a valid date. That I'm okay with. I would like some help on getting it into the database. Hi Guys, I am trying to use a script that is available on the net to upload an image into a mysql using BLOB. However it wont upload it keep getting Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/theacidf/public_html/attendance/upload.php on line 17 Here is the code... <?php // Connect to database $errmsg = ""; if (! @mysql_connect("localhost","theacidf_admin","password")) { $errmsg = "Cannot connect to database"; } @mysql_select_db("theacidf_attendanc"); // Insert any new image into database if ($_REQUEST[completed] == 1) { move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img"); $instr = fopen("latest.img","rb"); $image = addslashes(fread($instr,filesize("latest.img"))); if (strlen($image) < 149000) { mysql_query ("insert into pix (title, imgdata) values (\"". $_REQUEST[whatsit]. "\", \"". $image. "\")"); } else { $errmsg = "Too large!"; } } // Find out about latest image $gotten = @mysql_query("select * from pix order by pid desc limit 1"); if ($row = @mysql_fetch_assoc($gotten)) { $title = htmlspecialchars($row[title]); $bytes = $row[imgdata]; } else { $errmsg = "There is no image in the database yet"; $title = "no database image available"; // Put up a picture of our training centre $instr = fopen("../images/logo_png.png","rb"); $bytes = fread($instr,filesize("../images/logo_png.png")); } // If this is the image request, send out the image if ($_REQUEST[gim] == 1) { header("Content-type: image/jpeg"); print $bytes; exit (); } ?> <html><head> <title>Upload an image to a database</title> <body bgcolor=white><h2>Here's the latest picture</h2> <font color=red><?= $errmsg ?></font> <center><img src=?gim=1><br> <?= $title ?></center> <hr> <h2>Please upload a new picture and title</h2> <form enctype=multipart/form-data method=post> <input type=hidden name=MAX_FILE_SIZE value=150000> <input type=hidden name=completed value=1> Please choose an image to upload: <input type=file name=imagefile><br> Please enter the title of that pictu <input name=whatsit><br> then: <input type=submit></form><br> <hr> </body> </html> Why wont it run properly? Thanks in advance... S Hi there,
I'm new to all this so I've been following instructions from various sites and books. So far I have installed Apache, PHP and mysql, however when I browse to localhost/test.php (created to view phpinfo() through the browser) i can't see mysql or mysqli only the mysqlnd.
Here is an overview of software I've installed, OS and things I've added so far;
OS ver Windows7 Professional 32-bit VM This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=314265.0 I have a form that submits a record and saves it to the database, I've got that working already, I'm trying to figure out if there is a cleaner way to delete a record with a button that gets a value from the unique key, in this case 'id' here is how the delete button looks like: // get info from table $query = "SELECT id, Title, Message FROM table_name"; $result = mysql_query($query); //displaying all data while($row = mysql_fetch_assoc($result)) { echo" <div class='status'><h3>{$row['Title']} <br></h3>" . " <h5>{$row['Message']} <br><br></h5>"; $id = $row['id']; //trying to get unique key from database //delete button echo "</div> <form action='delete.php' method='post' /> <input type='hidden' name='delete' value='yes' /> <input type='hidden' name='id' value='$id' /> <input type='submit' value='remove' /></form>"; } As you can see, i'm trying to give $id a unique value but for some reason i'm not getting it. The delete.php code looks like this: if (isset($_POST['delete']))// check if delete was clicked { $query = "DELETE FROM table_name WHERE id='$id'"; echo "$id Deleted successfully"; } elseif(!mysql_query($query, $db_server)) { echo "DELETE failed: $query<br />" . myql_error() . "<br /><br />"; } mysql_close(); I'm new to php and still learning so, if you think there are other ways to do this, please let me know, the button won't do anything to the data. Thanks in advance Hi there, I have a string '12/04/1990', that's in the format dd/mm/yyyy. I'm attempting to convert that string to a Date, and then insert that date into a MySQL DATE field. The problem is, every time I try to do so, I keep getting values like this in the database: 1970-01-01. Any ideas? Much appreciated. Hi all: I have been going nuts trying to get this to work. I have gone through many attempts based on internet searches and examples that simply do not work. I have files stored in my MySQL db. The files cna be of any type and are being displayed in a listed report. The files are hyperlinked and clickable, but here is the issue: When I click on a file in: http://development.products-and-services.ca/cms/test.php I get: http://development.products-and-services.ca/cms/test2.php?content=DHall_CV_webdev_eng.pdf as a blank page result. The objective is to get a file download alert or to see the file in the browser. Any ideas? Does anybody know how to take the queried standard date format - 2012-04-02 for example - and print it to the page as April 2, 2012? Or at the very least, to switch to 04-02-2012? Trying to find some tutorials online. Hello to all, I have problem figuring out how to properly display data fetched from MySQL database in a HTML table. In the below example I am using two while loops, where the second one is nested inside first one, that check two different expressions fetching data from tables found in a MySQL database. The second expression compares the two tables IDs and after their match it displays the email of the account holder in each column in the HTML table. The main problem is that the 'email' row is displayed properly while its while expression is not nested and alone(meaning the other data is omitted or commented out), but either nested or neighbored to the first while loop, it is displayed horizontally and the other data ('validity', 'valid_from', 'valid_to') is not displayed.'
Can someone help me on this, I guess the problem lies in the while loop? <thead> <tr> <th data-column-id="id" data-type="numeric">ID</th> <th data-column-id="email">Subscriber's Email</th> <th data-column-id="validity">Validity</th> <th data-column-id="valid_from">Valid From</th> <th data-column-id="valid_to">Valid To</th> </tr> </thead> Here is part of the PHP code:
<?php while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo ' <tr> <td>'.$row["id"].'</td> '; while ($row1 = $stmt1->fetch(PDO::FETCH_ASSOC)) { echo ' <td>'.$row1["email"].'</td> '; } if($row["validity"] == 1) { echo '<td>'.$row["validity"].' month</td>'; }else{ echo '<td>'.$row["validity"].' months</td>'; } echo ' <td>'.$row["valid_from"].'</td> <td>'.$row["valid_to"].'</td> </tr>'; } ?>
Thank you. This could be PHP or MySql so putting it in PHP forum for now... I have code below (last code listed) which processes a dynamically created Form which could have anywhere from 0 to 6 fields. So I clean all fields whether they were posted or not and then I update the mySQL table. The problem with this code below is that if, say, $cextra was not posted (i.e. it wasnt on the dynamically created form), then this code would enter a blank into the table for $cextra (i.e. if there was already a value in the table for $cextra, it gets overwritten, which is bad). What is the best way to handle this? I'm thinking i have to break my SQL query into a bunch of if/else statements like this... Code: [Select] $sql = "UPDATE cluesanswers SET "; if (isset($_POST['ctext'])){ echo "ctext='$ctext',"; } else { //do nothing } and so on 5 more times.... That seems horribly hackish/inefficient. Is there a better way? Code: [Select] if (isset($_POST['hidden']) && $_POST['hidden'] == "edit") { $cimage=trim(mysql_prep($_POST['cimage'])); $ctext=trim(mysql_prep($_POST['ctext'])); $cextra=trim(mysql_prep($_POST['cextra'])); $atext=trim(mysql_prep($_POST['atext'])); $aextra=trim(mysql_prep($_POST['aextra'])); $aimage=trim(mysql_prep($_POST['aimage'])); //update the answer edits $sql = "UPDATE cluesanswers SET ctext='$ctext', cextra='$cextra', cimage='$cimage', atext='$atext', aextra='$aextra', aimage='$aimage'"; $result = mysql_query($sql, $connection); if (!$result) { die("Database query failed: " . mysql_error()); } else { } hi guys, im new to this forum I'm new also to php, I need help from you guys: I want to display personal information from a certain person (the data is on the mysql database) using his name as a link: example: (index.php) names 1. Bill Gates 2. Mr. nice Guy i want to click Bill Gates (output.php) Name: Bill Gates Country:xxxx Age: xx etc. How can i make this or how to learn this? Hi I am trying to select and order data/numbers from a colum in a mysql data base however i run the code and it returns no value just a blank page no errors or any thing so i think the code is working right but then it returns no result? Please help thanks Here is the code: <?php $host= "XXXXXX"; $mysql_user = "XXXXXX"; $mysql_password = "XXXXXX"; $mysql_database = "XXXXXXX"; $connection = mysql_connect("$host","$mysql_user","$mysql_password") or die ("Unable to connect to MySQL server."); mysql_select_db($mysql_database) or die ("Unable to select requested database."); $row = mysql_fetch_assoc( mysql_query( "SELECT XP FROM Game ORDER BY number DESC LIMIT 1" ) ); $number = mysql_result(mysql_query("SELECT XP FROM Game ORDER BY number DESC LIMIT 1"), 0); echo "The the highest XP is $number"; ?> |