Solved

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

Posted on 2013-06-08
3
1,467 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 17

Accepted Solution

by:
OmniUnlimited earned 500 total points
ID: 39232420
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 34

Expert Comment

by:Slick812
ID: 39232433
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 83

Expert Comment

by:Dave Baldwin
ID: 39232464
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

736 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