473,394 Members | 2,090 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,394 software developers and data experts.

simple php question: mysql_fetch_row display array contents

I am trying to do something in PHP that I thought would be fairly easy
but has become rather troublesome.

I'm trying to retrieve a list of numbers from a MySQL database and
display the contents in a comma delimited string if there is more than
one element. My problem is that the first element of the array is
displaying but not any of the others and I can't figure out why.
$count_lot = 0;
while ($row = mysql_fetch_row($sql_lot_num_result))
{
$lot_num_array[$count_lot] = $row[$count_lot];
echo "<p>\$lot_num_array[$count_lot] is:
$lot_num_array[$count_lot]<br />";
echo "\$count_lot is: $count_lot</p>";

$count_lot++;
}

// if there is more than 1 element in the array then separate them
with a comma and space
if ($count_lot == 1)
{
$lot_num_string = "$lot_num_array[0]";
}
else
{
$lot_num_string = implode(", ", $lot_num_array);
}

echo "<p>\$lot_num_string is: $lot_num_string</p>";

---

The result is:

$lot_num_array[0] is: 0111
$count_lot is: 0

$lot_num_array[1] is:
$count_lot is: 1

$lot_num_array[2] is:
$count_lot is: 2

$lot_num_string is: 0111, ,

---

Why is only the first element displaying but not the rest?

Tony W.
tonyw(no_spam)@liquidationworld.com
Jul 16 '05 #1
2 3948
On Mon, 18 Aug 2003 09:44:31 -0700, Tony W. wrote:
I am trying to do something in PHP that I thought would be fairly easy but
has become rather troublesome.

<snip!>

There are a bunch of potential problems with your code, but I am too beat
right now to clarify. Sorry. I probably shouldn't even have responded at
all. I know I would find it annoying if someone responded to *me* with
this sort of answer...

i'll post a real answer later...
--
Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Johns Hopkins University | Baltimore, MD
Website | http://www.wse.jhu.edu/newtnotes/

Jul 16 '05 #2

On 18-Aug-2003, to***@liquidationworld.com (Tony W.) wrote:
I'm trying to retrieve a list of numbers from a MySQL database and
display the contents in a comma delimited string if there is more than
one element. My problem is that the first element of the array is
displaying but not any of the others and I can't figure out why.
$count_lot = 0;
while ($row = mysql_fetch_row($sql_lot_num_result))
{
$lot_num_array[$count_lot] = $row[$count_lot];
The index to $row should be the column name or index, but not $count_lot
echo "<p>\$lot_num_array[$count_lot] is:
$lot_num_array[$count_lot]<br />";
echo "\$count_lot is: $count_lot</p>";

$count_lot++;
}

(snip)
--
Tom Thackrey
www.creative-light.com
Jul 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: 1 | last post by:
hi all i need to have a page on a clients site that has a competition question that changes weekly. they need to be able to change the question through some kind of admin page (i was going to...
5
by: ritchie | last post by:
Hi, I am writing to ask if anyone can see why my array is not being sorted correctly? It's an array of 4 elements(ints 1,2,3,4) but after calling the selection sort it comes back sorted as...
9
by: niclane | last post by:
Hi, I was reading section 5.5 of Ritchie and Kernighan and saw the following: " ..... char amessage = "now is the time"; char *pmessage = "now is the time";
0
by: 42 | last post by:
I implemented a simple class inherited from Page to create a page template. It simply wraps some trivial html around the inherited page, and puts the inherited page into a form. The problem I...
9
by: Sender | last post by:
I have created a Windows Form with TextBox with multiline property True. I have created three buttons. Button1, Button2, Button3. I want to display the contents of first line of textbox when some...
2
by: Len via DotNetMonster.com | last post by:
I have to set up a 2d array(13, 4) containing a deck of playing cards. What I am wondering is how to correctly set up the array in the first place, and then how do you access the information once...
12
by: Martien van Wanrooij | last post by:
I have been using for a while a class to create photo albums. Shortly, an array of photo's is declared, initially they are shown as thumbnails, by clicking on a thumbnail a larger photo is shown...
2
by: applegreenss | last post by:
Is it possible to take the contents of a MySQL DB Table, and somehow put the data into a syntax-correct data file format like a delimited ..txt file, and using PHP parse it as a local c:\ file...
5
by: L C | last post by:
Hello, Could someone point in the correct direction with regards to displaying my data in "nicer" format. I have figured out ( with the tutorials on the web, and the O'Reilly PHP & MySQL book)...
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: 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?
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.