LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 01-26-2012, 06:44 AM   #1
sqn
Member
 
Registered: Apr 2002
Distribution: Ubuntu, Arch, freeBSD, Slackware
Posts: 210

Rep: Reputation: 30
Unhappy php after mysql_fetch_array i can't list array elements


so i'm trying to build a cv database and i have the following code:
PHP Code:
function getUserEducation($username){

       
$q "SELECT cv.cvtitle, cv.cvdate, cv.cvdescr,education.institution_name, education.from_to, education.description FROM cv inner JOIN cvedu ON cv.id = cvedu.cvid inner JOIN education ON education.id = cvedu.eduid WHERE cv.userid = '$username'";

       
$result mysql_query($q$this->connection);

       
/* Error occurred, return given name by default */

      
if(!$result || (mysql_numrows($result) < 1)){

         return 
NULL;

      }

            
/* Return result array */
      
$dbarray = array();
      while (
$row mysql_fetch_array($result)) {
        
$dbarray[] = $row;
      }
    
      return 
$dbarray;

   } 
and
PHP Code:
include("include/session.php");
$req_user="admin";
    
$req_user_edu $database->getUserEducation($req_user);
    
$cv_description $req_user_edu['cvdescr'];
    
$cv_date $req_user_edu['cvdate'];
    
$cv_title $req_user_edu['cvtitle'];
    
$institution_name $req_user_edu['institution_name'];
echo 
"<br />";    
var_dump($req_user_edu);
echo 
"<br /><hr />";
print (
$req_user_edu['0']."<>".$cv_title);
?> 
now the output displpays the following:
Code:
Notice: Undefined index: cvdescr in /var/www/WORK/cv/test.php on line 5 Notice: Undefined index: cvdate in /var/www/WORK/cv/test.php on line 6 Notice: Undefined index: cvtitle in /var/www/WORK/cv/test.php on line 7 Notice: Undefined index: institution_name in /var/www/WORK/cv/test.php on line 8 
array(2) { [0]=> array(12) { [0]=> string(5) "test1" ["cvtitle"]=> string(5) "test1" [1]=> string(10) "2012-01-26" ["cvdate"]=> string(10) "2012-01-26" [2]=> string(101) "CV big, very big description. What I want, What is my experience, kinda like asmall motivation letter" ["cvdescr"]=> string(101) "CV big, very big description. What I want, What is my experience, kinda like asmall motivation letter" [3]=> string(39) "University1" ["institution_name"]=> string(39) "Vasile Goldis University, Arad, Romania" [4]=> string(10) "octomber 1" ["from_to"]=> string(10) "octomber 1" [5]=> string(136) "accounting, informatics, stock exchange, law, all kind of shitty stuff, that meant to build a better man out of me. Well was not working" ["description"]=> string(136) "accounting, informatics, stock exchange, law, all kind of shitty stuff, that meant to build a better man out of me. Well was not working" } [1]=> array(12) { [0]=> string(5) "test1" ["cvtitle"]=> string(5) "test1" [1]=> string(10) "2012-01-26" ["cvdate"]=> string(10) "2012-01-26" [2]=> string(101) "CV big, very big description. What I want, What is my experience, kinda like asmall motivation letter" ["cvdescr"]=> string(101) "CV big, very big description. What I want, What is my experience, kinda like asmall motivation letter" [3]=> string(23) "University2" ["institution_name"]=> string(23) "Aurel Vlaicu University" [4]=> string(10) "october 20" ["from_to"]=> string(10) "october 20" [5]=> string(648) "Informatics, maintaining company's network hardware (switches/firewalls and servers installation/configuration/maintaining of Linux systems (servers and workstations) Backup responsible for the entire network MySQL database administration, running on Linux and Windows maintaining Solaris with Oracle servers firewall, VPN, and other network related tasks mail servers, DNS, DHCP, apache, proxy maintenance and administration maintenance and administration of Windows 2008 server Active Directory and DHCP security of the network (regular penetration testing) PHP small projects for the department BASH Scripting maintain VMWare Server 2" ["description"]=> string(648) "Informatics, maintaining company's network hardware (switches/firewalls and servers installation/configuration/maintaining of Linux systems (servers and workstations) Backup responsible for the entire network MySQL database administration, running on Linux and Windows maintaining Solaris with Oracle servers firewall, VPN, and other network related tasks mail servers, DNS, DHCP, apache, proxy maintenance and administration maintenance and administration of Windows 2008 server Active Directory and DHCP security of the network (regular penetration testing) PHP small projects for the department BASH Scripting maintain VMWare Server 2" } } 
Array<>
can anyone tell me why i can't get individual array elements neither by name or id?

Thanks in advanced

Last edited by sqn; 01-26-2012 at 07:03 AM. Reason: it got solved
 
Old 01-26-2012, 06:56 AM   #2
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 241Reputation: 241Reputation: 241
$dbarray is array of arrays, eg to access cvdescr key of first element:
PHP Code:
$req_user_edu $database->getUserEducation($req_user);
$cv_description $req_user_edu[0]['cvdescr']; 
 
Old 01-26-2012, 07:02 AM   #3
sqn
Member
 
Registered: Apr 2002
Distribution: Ubuntu, Arch, freeBSD, Slackware
Posts: 210

Original Poster
Rep: Reputation: 30
thanks a lot Cedrik i've missed that out.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
need help with writing array elements into a file jayran Linux - Newbie 22 12-16-2009 07:21 AM
print array elements in one line bharatbsharma Programming 1 10-29-2007 08:58 AM
Simultaneous writes into different elements of an array estratos Programming 7 12-15-2006 06:36 AM
Passing Array Elements to functions melikai Programming 4 10-31-2006 10:27 PM
Renaming array elements in bash bryan.out.there Programming 2 05-31-2006 11:44 PM


All times are GMT -5. The time now is 06:41 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration