473,395 Members | 1,675 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Need help to get more than row at the same time

34
Hi can anyone help me, I need to fetch more than 1 row at the same time. I've used print_r(mysql_fetch_array($result)); but I only get 1 row is there away of of getting more then 1 row.
kind regards
Zawadi
Jul 23 '07 #1
9 1435
nathj
938 Expert 512MB
Hi can anyone help me, I need to fetch more than 1 row at the same time. I've used print_r(mysql_fetch_array($result)); but I only get 1 row is there away of of getting more then 1 row.
kind regards
Zawadi
Hi,

Try something like this:
Expand|Select|Wrap|Line Numbers
  1. while ($row = mysql_fetch_array($result, MYSQL_BOTH))
  2.         {
  3.             if ($row)
  4.             {
  5.                  echo $row;
  6.             }
  7.         }
  8.  
This should print each row in the result of the query. If this only ever returns 1 row of data then perhaps that's all that was returned? Check the SQL

Cheers
nathj
Jul 23 '07 #2
Zarwadi
34
Hi,

Try something like this:
Expand|Select|Wrap|Line Numbers
  1. while ($row = mysql_fetch_array($result, MYSQL_BOTH))
  2.         {
  3.             if ($row)
  4.             {
  5.                  echo $row;
  6.             }
  7.         }
  8.  
This should print each row in the result of the query. If this only ever returns 1 row of data then perhaps that's all that was returned? Check the SQL

Cheers
nathj
Thanks this really did help, but the output is Array Array Array. How do i get the data from the arrays.
Thanks for your reply
zar
Jul 23 '07 #3
mwasif
802 Expert 512MB
MYSQL_BOTH is the default value of mysql_fetch_array(). Try the below code

[PHP]while ($row = mysql_fetch_array($result))
{
echo $row["your_column_name_here"];
}[/PHP]
Jul 23 '07 #4
Zarwadi
34
Thanks but I must be doing something wrong all I'm getting is the column data in a string and what i need is all the rows i'm calling set in an array. I know i have 3 rows of data and I need them to look like this, but all 3 rows.

Array
(
[0] => 1
[id] => 1
[1] => test
[name] => test
[2] => 86
[subtotal] => 86
[3] => t541
[identnum] => t541
[4] => 1
[itemqut] => 1
[5] => Vinyl camera case
[itemproduct] => Vinyl camera case
[6] => None
[itemsize] => None
[7] => 57.00
[itemprice] => 57.00
)
but I'm only getting 1 row,

if you can help I would be very greatful
kind regards
Zar
Jul 23 '07 #5
mwasif
802 Expert 512MB
Please post your code.
Jul 23 '07 #6
Zarwadi
34
this line tells database which rows to look at the one with same username $glog is a var of the user name sent by the user.
$query = "SELECT * FROM theOrder WHERE name ='$glog'";

this is the query
$result = mysql_query($query);

the number of rows from the query
$numR = mysql_num_rows($result);

the array data this is good but it only gives me the 1st row, and like i said there are 3 row using the same user name and i need all 3 rows set out in a array
print_r(mysql_fetch_array($result));

Could you tell what I have done wrong

kind regards
Zar
Jul 23 '07 #7
mwasif
802 Expert 512MB
Did you use while() as nathj suggested? Look at the below code.
[PHP]$query = "SELECT * FROM theOrder WHERE name ='$glog'";

$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
print_r($row);
}[/PHP]
Jul 23 '07 #8
Zarwadi
34
Thank you, thank you thank, I must have done something stupid your my savior

Zar
Jul 23 '07 #9
nathj
938 Expert 512MB
One final point, if I may. Check out the article on building a data abstraction layer. It'll really help with this sort of stuff and it will properly modularise all your code for you making it easier to maintain and re-use.

Cheers
nathj
Jul 24 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with...
11
by: Mark | last post by:
Hi, For the last 2 years I've been developing vehicle tracking/telemetric software for a company as a self employed individual. The project is quiet big, and is going to be there flagship...
3
by: Bob.Henkel | last post by:
I write this to tell you why we won't use postgresql even though we wish we could at a large company. Don't get me wrong I love postgresql in many ways and for many reasons , but fact is fact. If...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
48
by: Chad Z. Hower aka Kudzu | last post by:
A few of you may recognize me from the recent posts I have made about Indy <http://www.indyproject.org/indy.html> Those of you coming to .net from the Delphi world know truly how unique and...
7
by: Jack Addington | last post by:
I've got a fairly simple application implementation that over time is going to get a lot bigger. I'm really trying to implement it in a way that will facilitate the growth. I am first writing a...
0
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need ...
5
by: MJ | last post by:
Hello, I need some suggestions on how to do this. I am reading through a large iis loge. For each line, I get three datapoints (sessionID, Time, Stage). I need to store these values into some...
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.