| | |
php mysql question
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Nov 2007
Posts: 10
Reputation:
Solved Threads: 0
<form action="book_dive.php" method="post">
<input type="submit" value="Submit">
<table border="1" width="75%" cellpadding="2" cellspacing="2">
<tr>
<td align="center">BOOK</td>
<td align="center">DATE</td>
<td align="center">TIME</td>
<td align="center">LEAVING FROM</td>
<td align="center">BOAT</td>
<td align="center">DEPTH</td>
<td align="center">DIVE SITE</td>
<td align="center">MIN QUAL</td>
</tr>
<?
include("conn.php");
$res=mysql_query("SELECT * FROM dives");
if(mysql_num_rows($res)==0) echo "No data in table";
for($i=0;$i<mysql_num_rows($res);$i++) {
$row=mysql_fetch_assoc($res); //mysql_fetch_assoc STORES A ROW IN A ARRAY AND MOVES ON TO THE NEXT ROW Each subsequent call to mysql_fetch_assoc() returns the next row in the recordset.
?>
<tr>
<td align="center"><input type="checkbox" value=<?=$row[id]?>/></td>
<td align="center"><?=$row[date]?></td>
<td align="center"><?=$row[time]?></td>
<td align="center"><?=$row[leaving_from]?></td>
<td align="center"><?=$row[boat]?></td>
<td align="center"><?=$row[depth]?></td>
<td align="center"><?=$row[dive_site]?></td>
<td align="center"><?=$row[min_qual]?></td>
</tr>
<?
}
Hi I am using this code to display a mysql database of dates etc on my web page. The problem with it is the dates in the database are in a random order but it would be better if they would be displayed on the webpage in date order. It would cause too many complications to change the order in the database. Is there an easy way to do this please?
<input type="submit" value="Submit">
<table border="1" width="75%" cellpadding="2" cellspacing="2">
<tr>
<td align="center">BOOK</td>
<td align="center">DATE</td>
<td align="center">TIME</td>
<td align="center">LEAVING FROM</td>
<td align="center">BOAT</td>
<td align="center">DEPTH</td>
<td align="center">DIVE SITE</td>
<td align="center">MIN QUAL</td>
</tr>
<?
include("conn.php");
$res=mysql_query("SELECT * FROM dives");
if(mysql_num_rows($res)==0) echo "No data in table";
for($i=0;$i<mysql_num_rows($res);$i++) {
$row=mysql_fetch_assoc($res); //mysql_fetch_assoc STORES A ROW IN A ARRAY AND MOVES ON TO THE NEXT ROW Each subsequent call to mysql_fetch_assoc() returns the next row in the recordset.
?>
<tr>
<td align="center"><input type="checkbox" value=<?=$row[id]?>/></td>
<td align="center"><?=$row[date]?></td>
<td align="center"><?=$row[time]?></td>
<td align="center"><?=$row[leaving_from]?></td>
<td align="center"><?=$row[boat]?></td>
<td align="center"><?=$row[depth]?></td>
<td align="center"><?=$row[dive_site]?></td>
<td align="center"><?=$row[min_qual]?></td>
</tr>
<?
}
Hi I am using this code to display a mysql database of dates etc on my web page. The problem with it is the dates in the database are in a random order but it would be better if they would be displayed on the webpage in date order. It would cause too many complications to change the order in the database. Is there an easy way to do this please?
•
•
Join Date: Nov 2007
Posts: 10
Reputation:
Solved Threads: 0
No that hasn't worked I think that it would but I have got the date field of my database as varchar.
I am trying to change the field but the date format needs to have a YYMMDD format and i want a DDMMYY format. Is there an easy way around this or do i need to write php code to convert user input from DDMMYY to YYMMDD??
I am trying to change the field but the date format needs to have a YYMMDD format and i want a DDMMYY format. Is there an easy way around this or do i need to write php code to convert user input from DDMMYY to YYMMDD??
can't you set the date field to that format?
Anyways see this page:
http://www.php.net/manual/en/function.date-format.php
Sucks it doesn't work because I was counting on it since I too am going to have to do something similar soon....
Anyways see this page:
http://www.php.net/manual/en/function.date-format.php
Sucks it doesn't work because I was counting on it since I too am going to have to do something similar soon....
This is how you convert date strings from DDMMYY to YYMMDD:
php Syntax (Toggle Plain Text)
$userinput; //lets assume this variable has a date in DDMMYY format $format = "y/m/d"; //this is the format we are going to tell date to output the string in. y , d and m will output 2 digit representations of year day and month repectively (case sensitive). $timestamp = strtotime($userinput); //get a Unix timestamp from the user input so we can use it with the date function. $new_date = date($format, $timestamp); //$newdate is now a string formatted YY/MM/DD
Last edited by scru; Dec 9th, 2007 at 5:08 pm.
![]() |
Similar Threads
- Clean Previous Next Script for MySQL results (PHP)
- PHP/MySQL - Need help figuring out if this will work (MySQL)
- PHP and MySQL newbie introducing self (PHP)
- Dynamic Next/Prev Buttons in PHP/MySQL (MySQL)
- PHP for large files (PHP)
- question about connecting odbc to sql through php script (PHP)
- PHP question i think! (Site Layout and Usability)
- How many clients can access a PHP script at a time? (PHP)
- Set up manually, php 5.0 with apache's compatible version (PHP)
- how can i convert utf-8 to big5 and write into MySQL?? (PHP)
Other Threads in the PHP Forum
- Previous Thread: Another teaser question
- Next Thread: Insert link button
| Thread Tools | Search this Thread |
apache api array beginner binary body broken cakephp checkbox class cms code computing cron curl database date date/time delete display dynamic echo email error file files filter folder form forms function functions gc_maxlifetime global google host href htaccess html image include insert ip javascript joomla limit link list login mail memmory memory menu mlm msqli_multi_query multiple mycodeisbad mysql navigation oop parameter parsing paypal pdf php problem query radio random recourse recursion regex remote script search seo server sessions sms snippet source space sql static syntax system table thesishelp trouble tutorial update upload url validator variable video web webdesign xml youtube






