473,378 Members | 1,619 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,378 software developers and data experts.

mysql_fetch_assoc query

1
Hi there,

Can anyone help?

Why is the following code displaying "P1P2P3..." etc, instead of "P1 , P2, P3 ,.." etc. ?

Thanks

Paul

Expand|Select|Wrap|Line Numbers
  1. <!--Conect to database-->
  2. <?php include "connects/patientconn.php"; ?>
  3.  
  4. <?php
  5.  
  6. $query = "SELECT `Patient I.D.` FROM `patient`";
  7.  
  8. $result = mysql_query($query);
  9.  
  10. while($patient = mysql_fetch_assoc($result))
  11. {
  12. $pt = implode(" , ", $patient);
  13. echo $pt;
  14. }
  15. ?>
Aug 13 '12 #1
4 1644
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code.

The reason is that mysql_fetch_assoc only returns one row. Not all of them.
Aug 13 '12 #2
you have to use and looping method in it........

Since mysql_fetch_assoc is an array function of php...
it will return u a no of rows in ur tables.

using 'for loop' will be a better option for u.
Sep 4 '12 #3
use it:
foreach($pt as $val)
{
echo $val
}
Sep 4 '12 #4
johny10151981
1,059 1GB
if you dont know what would be the index of arrays then I would suggest you to use mysql_fetch_row.
here is an example of what could happen.
Expand|Select|Wrap|Line Numbers
  1. $Query="SELECT SUM(Price+Tax), CustomerName FROM tblsometable Group By CustomerName"
in this case it is bit confusing for SUM(Price+Tax)

but on array you would get like this:
Expand|Select|Wrap|Line Numbers
  1. $array['SUM(Price+Tax)'];
  2.  
you can also fix this issue with naming the column like below:
Expand|Select|Wrap|Line Numbers
  1. $Query="SELECT SUM(Price+Tax) as Price, CustomerName FROM tblsometable Group By CustomerName"
  2.  
and all in all you can use integer base indexing by calling the function mysql_fetch_row
Sep 5 '12 #5

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

Similar topics

2
by: jaysonsch | last post by:
Hello! I am having some problems with a database query that I am trying to do. I am trying to develop a way to search a database for an entry and then edit the existing values. Upon submit, the...
9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
3
by: Harvey | last post by:
Hi, I try to write an asp query form that lets client search any text-string and display all pages in my web server that contain the text. I have IIS 6.0 on a server 2003. The MSDN site says...
14
by: Dave Thomas | last post by:
If I have a table set up like this: Name | VARCHAR Email | VARCHAR Age | TINYINT | NULL (Default: NULL) And I want the user to enter his or her name, email, and age - but AGE is optional. ...
0
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list...
15
by: Richard Hollenbeck | last post by:
I tried to ask this question before on the 14th of January but I never got a reply. I'm still struggling with the problem. I'll try to rephrase the question: I have a crosstab query with rows...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
3
by: Bill Hutchison | last post by:
I have a query that returns different results (3508 rows for snapshot, 6288 for dynaset) and that is the only thing I change to get the different results. When I try to make a table from the...
3
by: pbd22 | last post by:
Hi. I need some help with structuring my query strings. I have a form with a search bar and some links. Each link is a search type (such as "community"). The HREF for the link's anchor looks...
4
by: Stan | last post by:
I am using MS Office Access 2003 (11.5614). My basic question is can I run a query of a query datasheet. I want to use more that one criteria and can not get that query to work. I thought I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.