Welcome to Egypt Forums Mark forums read | Egypt Main Page
Egypt Forums
Arabic Movies



Web Technology Web Design Tools Photoshop,Dreamweaver,Flash,Etc.Tutorials , References , Examples.

Web Technology Thread, PHP cannot get data from (only)1 field of several in MySQL database in Programming , WebDesign & Development; *Problem: cannot get data from (only)1 field of several in MySQL database* *Executive Summary: * There are 6 fields in ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=22596


Reply
LinkBack Thread Tools Display Modes
PHP cannot get data from (only)1 field of several in MySQL database
 
 
Senior Member

Reply With Quote
 
Join Date: Dec 2008
Posts: 18,122
28-01-2009, 10:50 PM
 
*Problem: cannot get data from (only)1 field of several in MySQL database* *Executive Summary: * There are 6 fields in the database. I can populate a form on a PHP page with date from 5 of the 6 fields. One field won't 'come across' to the...

Problem: cannot get data from (only)1 field of several in MySQL database

Executive Summary:
There are 6 fields in the database.
I can populate a form on a PHP page with date from 5 of the 6 fields.
One field won't 'come across' to the form

The questions:
1) why can't I retrieve data from column 'editd' - type timestamp(14)
2) what code will it take to retrieve that data?
3) when can I stop beating my head against the wall?

// the database

Code:
mysql> desc main;
+---------+-------------------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------------------------+------+-----+---------+----------------+
| id | smallint(4) unsigned zerofill | | PRI | NULL | auto_increment |
| fname | varchar(35) | YES | | NULL | |
| lname | varchar(35) | YES | | NULL | |
| title | varchar(35) | YES | | NULL | |
| editd | timestamp(14) | YES | | NULL | |
| editb | varchar(13) | YES | | NULL | |
+---------+-------------------------------+------+-----+---------+----------------+
6 rows in set (0.00 sec)
// a select statement from database

Code:
mysql> select id,fname,lname,title,editd,editb from main where id=941;
+------+------------+-------+--------------------+----------------+-----------------+
| id | fname | lname | title | editd | editb |
+------+------------+-------+--------------------+----------------+-----------------+
| 0941 | ZZ | Top | ***-kicking R & R | 20090128115610 | deus ex machina |
+------+------------+-------+--------------------+----------------+-----------------+
1 row in set (0.00 sec)
// use above to populate a form (see below)

// connect to server and open db

Code:
$connection = mysql_connect("localhost:3306","username","passwor d") or die("Darn! I couldn't connect to the server");
$db=mysql_select_db("roster",$connection) or die("Uh-oh! Connected to server but unable to open the database");
// run query (same as MySQL query above)

Code:
$query8=mysql_query("select fname,lname,title,editd,editb from main where id=$id", $connection);
// create an array from result set

Code:
$query9=mysql_fetch_assoc($query8);

$fname=$query9[fname];
$lname=$query9[lname];
$title=$query9[title];
$editd=$query9[editd];
$editb=$query9[editb];
// create form and populate fields

// ( all fields populate as expected except one):

// .... display data from columns 2-4 - get data from array

// .... display 5th field and data from array (display only, no edit)
Code:
echo "Last Edited Date:
".$editd."";
// sanity check - is the editd field passing a NULL value
Code:
if (is_null($editd))
{
$editd="Value passed is 'NULL'";
echo "Last Edited Date:
".$editd."";
}
// .... display 6th field and data from array - correctly

// ... end ...
 
 
 
Reply

Web Technology Thread, PHP cannot get data from (only)1 field of several in MySQL database in Programming , WebDesign & Development; *Problem: cannot get data from (only)1 field of several in MySQL database* *Executive Summary: * There are 6 fields in ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=22596


Bookmarks

Tags
data, database, field, mysql, only1, php


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump