Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 12th, 2003, 02:24 AM
Friend of Wrox
Join Date: Sep 2003
Location: Mentiri, Muara, Brunei.
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default Data retrieval using MySQL

Hello friends,

  I have database in MySQL. I want to retrieve data from a table.

$link_id=mysql_connect("localhost","username","pas sword");
$res=mysql_query("select * from table name");
    echo $query_data['username'];

it is producing errors "parse error. expecting "'" or "'" and

How can i find whether the query returns any records and how can i move to EOF. Is there any function like BOF and EOF in PHP.

Thanx in advance

Reply With Quote
  #2 (permalink)  
Old November 12th, 2003, 02:59 AM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts

In PHP the data retrieved from a database table is stored in, I would guess, temporary RAM memory as an array and not in an actual physical file on the hard disk. The 'EOF' & 'BOF' sounds C-ish to me. I've only seen anything like that in PHP when working with file functions.

When you use mysql_fetch_array() the function assembles and returns an array based on the query that you requested, assuming that your query was formatted properly and you have a valid connection to the database. If the optional second argument (a constant) is left off the array will contain both numeric and associative indices. The numeric indices will correspond to the field order as they appear in your table using the wildcard selector (*) or the order that they appear in your query when you specify the field names explicitly. The associative indices will be the names of the fields themselves.

Using mysql_fetch_array in addition with the while loop will iterate through all of the results found in the specified query begining with the first row set (beginning of array, invisible array pointer set to zero) and ending when the last row has been reached.

    echo $query_data['username'];

This would expect a field named 'username' in your selected database table.

You can try something like this to see everything being brought back by mysql_fetch_array

    echo "<pre>";
    echo print_r($query_data);
    echo "</pre>";

This will print out a human-readable summary of how the array is structured like so:

    [0] => "value"

The parse errors that you are getting are errors in the way that you've written your PHP syntax. The interpreter is choking because you have forgotten a quotation, or forgot to escape one, or something along those lines, or perhaps left off a semi-colon.

Tell me a little more about how you have your table set-up and I can better demonstrate to you how to retrieve data from it.

Are you able to verify your mysql connection?

: )

Smiling Souls
Reply With Quote
  #3 (permalink)  
Old November 12th, 2003, 11:38 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts

Where's the parse error you're getting? Is it a PHP error, or a MySQL error? What line is it on?

The code snippet you posted LOOKS okay, except that your table name should be one word. The query "SELECT * FROM table name" is NOT technically valid, but I assume that "table name" is just a place holder for your real table name.

When you talk about BOF and EOF, I assume you're asking how to move to the beginning or end of your query result set. You can do that using mysql_data_seek()

Take care,

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Date retrieval Neal Excel VBA 1 February 1st, 2007 06:43 AM
For XML data retrieval fancorning4 SQL Server 2000 2 May 18th, 2006 10:33 AM
XML Retrieval Help t3projects BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 0 October 11th, 2005 03:24 PM
Need help with JSP data retrieval crashpoint Java Databases 1 August 3rd, 2005 01:00 AM
Automatically retrieval info from MySql Master_D Pro PHP 1 June 5th, 2004 05:08 PM

All times are GMT -4. The time now is 11:21 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.