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

Some looping issues.

Heya.

I have a loop which generates a table code for a specific number of times.
What I'm having problems with is to echo a variable inside the loop.

The loop runs 10 times, and there are 10 text messages sent to the page, so my problem is how do I get each of the looped tables to echo one of the text messages each time?

Like loop 0 echoes text message 0, loop 1 echoes text message 1 and so on.

This is the code for the table loops.
Expand|Select|Wrap|Line Numbers
  1. for ($fields=0; $fields<=9; $fields++)
  2. {
  3. echo "$titlesArr[titles]";
  4. echo    "
  5.     <tr>
  6.         <td height='35' class='boe_menu_raquo'>
  7.     <span class='boe_menu_raquo_label'> &raquo; </span>
  8.     </td> <td class='boe_link_text'>
  9.     <a href='$url1$number$part$number$number$fields'>$number.$fields — $title </a>
  10.     </td> <td>&nbsp;</td>
  11.       </tr>
  12.     ";
  13. }
$title is the text messages, though at this point, nothing appears there.
Apr 3 '10 #1
4 1401
Hello,

You have to take two dimensional array for title. And need to change this line
echo "$titlesArr[titles]"; by echo $titlesArr[$fields][titles];

Hope this will help you..

Thanks & Regards,
Mayur Bhayani
Apr 5 '10 #2
Thank you, Mayur Bhayani .

This works perfectly for me!
I'm glad, now I learned something new ^^.


Topic SOLVED
Apr 5 '10 #3
Markus
6,050 Expert 4TB
Hello, PHPstarter.

A quick side-note: when you're accessing an index of an array that has a string for its key, be sure to wrap that string in quotes! Turn on error_reporting() to see why.

For example:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $members = array(
  4.     array(
  5.         'name' => 'Markus',
  6.         'role' => 'Moderator'
  7.     ),
  8.     array(
  9.         'name' => 'Atli',
  10.         'role' => 'Moderator'
  11.     )
  12. );
  13. $mem_count = count($members);
  14.  
  15. for ($i = 0; $i < $mem_count; ++$i) {
  16.     printf('Member <em>%s</em> has role <em>%s</em><br />',
  17.            $members[$i]['name'], $members[$i]['role']); 
  18.            // Notice "name" and "role" here are quoted.
  19. }
  20.  
Apr 6 '10 #4
Thanks for clearing that up.
I've seen examples with and without single quotes inside the string, so I was not really sure about it.

:)
Apr 6 '10 #5

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

Similar topics

16
by: Michele Simionato | last post by:
I have read with interest the recent thread about closures. The funny thing is that the authors are arguing one against the other but I actually agree with all of them and I have a proposal that...
3
by: fdsl ysnh | last post by:
--- python-list-request@python.orgдµÀ: > Send Python-list mailing list submissions to > python-list@python.org > > To subscribe or unsubscribe via the World Wide Web, > visit >...
4
by: simon_s_li | last post by:
Hi, I have a list (i..e <UL> <LI>) where each <LI> contains a <DIV> and text in it. Example: <UL> <LI> <DIV> text here 1</DIV>
15
by: Claudio Grondi | last post by:
Let's consider a test source code given at the very end of this posting. The question is if Python allows somehow access to the bytes of the representation of a long integer or integer in...
2
by: randy1200 | last post by:
My hope is that somebody has a thought on this, or can point to toward an article that's useful. I have the following: DataSet ds = new DataSet(); ds.ReadXml("MyData.xml"); Each MainTable...
4
by: musosdev | last post by:
Hi I need to extend the contents of the src element of the <link relcss tags in the <headsection of my masterpage. From code, how can I access the <link elements within the <head? Cheers
20
by: Ifoel | last post by:
Hi all, Sorry im beginer in vb. I want making programm looping character or number. Just say i have numbers from 100 to 10000. just sample: Private Sub Timer1_Timer() if check1.value= 1...
4
by: wbosw | last post by:
I'm trying to take a word (stEAdy) and find the index positions of the uppercase characters(2,3) in the word. I have them stored in an array (positionarray). Then I reverse the word and set all...
1
by: gwenky | last post by:
Hello, so I was working this out yesterday and I am working on a function (w/o using arrays) that moves through the digits of a user inputted number and finds max/min ...this is the max option and it...
15
by: colemanj4 | last post by:
Here is what I have so far, it loops while the PW is incorrect, or until cancel is selected. I want it to lock the tables for adds, deletes, and edits when cancel is selected, and if the PW is...
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: 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
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.