Solved

php get value of specific row and column from array of db

Posted on 2013-06-08
3
1,344 Views
Last Modified: 2013-06-08
say i retrive a table select * from xxxxx

if there any simple way that say

$value = $dataRecord...; ( which i can direct specific a row and column )

like row 0 column 1 or row 0 column "title"

expert please help
0
Comment
Question by:john80988
3 Comments
 
LVL 17

Accepted Solution

by:
OmniUnlimited earned 500 total points
Comment Utility
You could simply loop through all the rows, fetching each row as an associative array, and storing that in a bigger array.

For example:

$result = mysql_query("select * from xxxxx");
$index = 0
while ($row = mysql_fetch_assoc($result)) {
    $table[$index] = $row;
    $index++;
}

Open in new window


You could then just access it using $table[<<row number>>]["column_title"].

I wouldn't recommend this if your table is very big, however.  This is a big drain on resources.

If your table is big, then I would recommend a better solution is to simply locate the element you want by modifying the query with the appropriate WHERE clause.
0
 
LVL 33

Expert Comment

by:Slick812
Comment Utility
hello, yes you can use the  PH{  mysql_data_seek( )  function to set the mySQL Result to any specific numbered Row , you should read this in the manual -
http://us2.php.net/manual/en/function.mysql-data-seek.php

some code might be like -
$result = mysql_query("");
$query = 'SELECT * FROM xxxxx';
$result = mysql_query($query);
if (mysql_data_seek($result, 4)) {// go to row 4
    $row = mysql_fetch_assoc($result),
    }
    else // if the seek Fails then there is NO row 4
    {
    echo "Cannot seek to row 4: " . mysql_error() . "\n";
    }

Open in new window

but you can get different amount of rows from a select, You may need to use the   mysql_num_rows($result) to get the Range of the amount of rows
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
Because MySQL will 're-use' empty space in it's tables, the order of rows is only predictable if you use an ORDER BY clause.  ORDER BY tells MySQL to sort the results by a particular column and return them in that order.  If your table is having additions and deletions, the data you are looking for will not necessarily be in the same numerical row each time.

It is usually best to find a different way to identify the data you want to retrieve.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now