| | |
php/mysql display data in row and column
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Dec 2007
Posts: 74
Reputation:
Solved Threads: 0
BTW this is the query which I am using just in case if it does make deference.
MySQL Syntax (Toggle Plain Text)
$result = mysql_query("SELECT * FROM bookings WHERE bookingID='$_POST[bookingID]'");
try using this:
sometimes when you don't encapsulate the second part of the where condition in speech marks it treats it like a search term when your saying "select * from bookings where bookingID like '%term%'
MySQL Syntax (Toggle Plain Text)
$result = mysql_query("SELECT * FROM bookings WHERE bookingID='".$_POST['bookingID']."'");
sometimes when you don't encapsulate the second part of the where condition in speech marks it treats it like a search term when your saying "select * from bookings where bookingID like '%term%'
Last edited by MaxMumford; Mar 1st, 2009 at 10:11 am.
Ill solve somebody's thread someday! xD
•
•
Join Date: Dec 2007
Posts: 74
Reputation:
Solved Threads: 0
This is my code
Thanks for your help
MySQL Syntax (Toggle Plain Text)
<?php // open database connection code AND THEN my code as follows $sql="UPDATE bookings SET startdate ='$_POST[startdate]',enddate='$_POST[enddate]',adults='$_POST[adults]',children='$_POST[children]',roomtype='$_POST[roomtype]', requirements='$_POST[requirements]' WHERE bookingID = '$_POST[bookingID]'"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } print "Your booking ID ".$bookingID; echo " has been changed"; $result = mysql_query("SELECT * FROM bookings WHERE bookingID='".$_POST['bookingID']."'"); $result_array = mysql_fetch_array($result); echo '<table border=1>'; foreach($result_array as $key => $value) { echo '<tr><td>Start Date</td><td>'.$result_array['startdate'].'</td></tr>'; echo '<tr><td>End Date</td><td>'.$result_array['enddate'].'</td></tr>'; echo '<tr><td>Adults</td><td>'.$result_array['adults'].'</td></tr>'; echo '<tr><td>Children</td><td>'.$result_array['children'].'</td></tr>'; echo '<tr><td>Roomtype</td><td>'.$result_array['roomtype'].'</td></tr>'; echo '<tr><td>Requirements</td><td>'.$result_array['requirements'].'</td></tr>'; } echo '</table>'; mysql_close($con); ?>
Thanks for your help
Ahhh i know whats going wrong. This bit:
is saying that for every piece of information saved inside the results array, write a table with the results. Take that out of the foreach function and have it on its own. Here how the whole code should look:
The query returned 9 pieces of information and stored them inside an array. Then the foreach function was going through all nine items in the array and printing your table of results
MySQL Syntax (Toggle Plain Text)
foreach($result_array as $key => $value) { echo '<tr><td>Start Date</td><td>'.$result_array['startdate'].'</td></tr>'; echo '<tr><td>End Date</td><td>'.$result_array['enddate'].'</td></tr>'; echo '<tr><td>Adults</td><td>'.$result_array['adults'].'</td></tr>'; echo '<tr><td>Children</td><td>'.$result_array['children'].'</td></tr>'; echo '<tr><td>Roomtype</td><td>'.$result_array['roomtype'].'</td></tr>'; echo '<tr><td>Requirements</td><td>'.$result_array['requirements'].'</td></tr>'; } echo '</table>';
is saying that for every piece of information saved inside the results array, write a table with the results. Take that out of the foreach function and have it on its own. Here how the whole code should look:
MySQL Syntax (Toggle Plain Text)
<?php // open database connection code AND THEN my code as follows $sql="UPDATE bookings SET startdate ='$_POST[startdate]',enddate='$_POST[enddate]',adults='$_POST[adults]',children='$_POST[children]',roomtype='$_POST[roomtype]', requirements='$_POST[requirements]' WHERE bookingID = '$_POST[bookingID]'"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } print "Your booking ID ".$bookingID; echo " has been changed"; $result = mysql_query("SELECT * FROM bookings WHERE bookingID='".$_POST['bookingID']."'"); $result_array = mysql_fetch_array($result); echo '<table border=1>'; echo '<tr><td>Start Date</td><td>'.$result_array['startdate'].'</td></tr>'; echo '<tr><td>End Date</td><td>'.$result_array['enddate'].'</td></tr>'; echo '<tr><td>Adults</td><td>'.$result_array['adults'].'</td></tr>'; echo '<tr><td>Children</td><td>'.$result_array['children'].'</td></tr>'; echo '<tr><td>Roomtype</td><td>'.$result_array['roomtype'].'</td></tr>'; echo '<tr><td>Requirements</td><td>'.$result_array['requirements'].'</td></tr>'; echo '</table>'; mysql_close($con); ?>
The query returned 9 pieces of information and stored them inside an array. Then the foreach function was going through all nine items in the array and printing your table of results
Ill solve somebody's thread someday! xD
•
•
Join Date: Dec 2007
Posts: 74
Reputation:
Solved Threads: 0
Hi MaxMumford
This did work; I just wanted to say a big thank you for solving my thread
My last problem is at the moment user will have to type date in this format (YYYY-MM-DD) as my phpMyadmin will only store date in this format any idea how I could make it to store date in this format (DD-MM-YYYY)
Once again thanks ever so much for your help.
Regards
HB25
This did work; I just wanted to say a big thank you for solving my thread
My last problem is at the moment user will have to type date in this format (YYYY-MM-DD) as my phpMyadmin will only store date in this format any idea how I could make it to store date in this format (DD-MM-YYYY)
Once again thanks ever so much for your help.
Regards
HB25
php Syntax (Toggle Plain Text)
<?php // open database connection code and then my code as follows $sql="UPDATE bookings SET startdate ='$_POST[startdate]',enddate='$_POST[enddate]',adults='$_POST[adults]',children='$_POST[children]',roomtype='$_POST[roomtype]', requirements='$_POST[requirements]' WHERE bookingID = '$_POST[bookingID]'"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } print "Your booking ID ".$bookingID; echo " has been changed"; $result = mysql_query("SELECT * FROM bookings WHERE bookingID='".$_POST['bookingID']."'"); if(mysql_num_rows($result) > 0 ) { //only print this if there is atleast 1 row. This will avoid a lot of problems which could arise from mysql_fetch_array if there are no rows in the table //I would also declare the table headers when I am sure at least 1 record exist. If there aren't any records, it wont print the html table echo '<table border=1> <tr><td>Start Date</td><td>End Date</td><td>Adults</td><td>Children</td><td>Roomtype</td><td>Requirements</td></tr>'; $result_array = mysql_fetch_array($result); echo '<td>'.$result_array['startdate'].'</td>'; echo '<td>'.$result_array['enddate'].'</td>'; echo '<td>'.$result_array['adults'].'</td>'; echo '<td>'.$result_array['children'].'</td>'; echo '<td>'.$result_array['roomtype'].'</td>'; echo '<td>'.$result_array['requirements'].'</td>'; echo '</tr>'; echo '</table>'; // this way it looks more neat } mysql_close($con); ?>
Also, php's date function is so vast, you can modify any of your date format to whatever format you want.
Check here.
http://in.php.net/date
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Dec 2007
Posts: 74
Reputation:
Solved Threads: 0
Hi
I have gathered from searching the net that I could use the code below to format the date as (DD-MM-YYYY)
The code below is the query which I am using, could you please let me know how I could embed the above code to this query?
Thanks for your help.
HB25
I have gathered from searching the net that I could use the code below to format the date as (DD-MM-YYYY)
MySQL Syntax (Toggle Plain Text)
INSERT INTO table ( FIELD ) VALUES ( STR_TO_DATE($date,'%d-%m-%Y') );
MySQL Syntax (Toggle Plain Text)
$sql="INSERT INTO bookings (clientID, roomID, startdate, enddate, adults, children, roomtype, requirements) VALUES ('$last_insert_client_id','NULL','$_POST[startdate]','$_POST[enddate]','$_POST[adults]','$_POST[children]','$_POST[roomtype]', '$_POST[requirements]')";
HB25
![]() |
Similar Threads
- Need Help...Please (MySQL)
- please help (MySQL)
- a little help (PHP)
- Insert Selected data In MySQL (PHP)
- Displaying images from mysql database (PHP)
- Display morethan one coulmn from mysql database in PHP (PHP)
- Selecting info from multiple mysql tables and display (PHP)
- AJAX generated <select> and FIREFOX (JavaScript / DHTML / AJAX)
- How to display rowspan format table? (PHP)
Other Threads in the MySQL Forum
- Previous Thread: MySql DB crashing:
- Next Thread: MySql Search using multiple input.
| Thread Tools | Search this Thread |
Tag cloud for MySQL
"use" 1 agplv3 alfresco amazon api artisticlicense aws bizspark changingprices communityjournalism contentmanagement contractors copyright count crm data database design developer development distinct drupal dui ec2 eliminate email enter enterprise error facebook form foss gartner gnu government gpl greenit groklaw groupware hiring hyperic images innerjoins insert ip join journalism keyword kickfire laptop legal license licensing linux maintenance mariadb matchingcolumns metron micromanage microsoft microsoftexchange mindtouch montywidenius mozilla multiple mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opengovernment opensource operand oracle pdf penelope php priceupdating query referencedesign remove results saas select sharepoint simpledb sourcecode spotify sql statement sugarcrm techsupport thunderbird update virtualization






