473,396 Members | 1,936 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.

How to increase a DIV ID counter within PHP

8
I'm back with another question about a rotating Marquee.
I have a marquee that rotates information through a window on my web page.
With your help here I have figured out a bunch and have it working, Almost.
I have to read data into a <DIV> statement and Echo out a table structure. then save that file that is a page of filled in data areas. I finally did that.
But, to have the marquee show different photos and information it reads the data with in the various <Div>'s.
Now my problem is I need to increase the DIV ID# by one each time the data is read through the DO WHILE statement is working.
the output is like this.....

<div id="billboard0" class="billcontent">the data area I have working</div>
<div id="billboard0" class="billcontent">the data area that I have working now</div>

Do you see the ID="billboard0"
I need to increase the ID by 1 starting at number 0
To This.....
<div id="billboard0" class="billcontent">the data area I have working</div>
<div id="billboard1" class="billcontent">the data area I have working now</div>
<div id="billboard2" class="billcontent">the data area I have working</div>
<div id="billboard3" class="billcontent">the data area I have working now</div>

thanks for any help
Jan 22 '08 #1
6 2316
MarkoKlacar
296 Expert 100+
Hi,

Wll the obvious answer would be to have a counter wehn you create you <DIV>'s.
Not sure how you code for doing this looks but it should be a start if I understood the question correctly.

MK
Jan 22 '08 #2
Markus
6,050 Expert 4TB
Just a psuedo code:
[php]
function buildDivs($_amount)
{
for( $_i = 0; $_i <= $_amount; ++$_i)
{
echo "<div id=\"$_i\">Div id = $_i</div>";
}
}

echo buildDivs(10);
[/php]

Just to help you with the ideology with incrementing..

If you post the code you were helped with before (we're not psychic) we could help you again :)
Jan 22 '08 #3
CDFTim
8
I can not post the code from before because its all jumbled up with all the echo's.
But I do appreciate this and will try it out. I figured that I would have to do it this way, but knew I would not know where to start.

Here is a Newbie question. I try to read code out of books and articles and would like to know what exactly do these mean.

Something like this ....
Expand|Select|Wrap|Line Numbers
  1. $this ->template_dir = Template_dir;
  2. $page -> display('index.pl');
  3. $result = $this -> db -> getone($queryString);
What does the "->" mean?

how about this.....
Expand|Select|Wrap|Line Numbers
  1. if (DB :: isError($result))
------- This has two COLONS together in the line.
What do the two colons together mean?

And when is it that you use two == signs together ? I have seen statements with a combinatin of single and double = signs in the same statement.

and this one.....
Expand|Select|Wrap|Line Numbers
  1. if (!($userfile_type =="image/pjpeg" OR $userfile_type == "image/jpeg" OR $userfile_type == "image/gif" OR $userfile_type == "image/pjpg" OR $userfile_type == "image/jpg"))
I found this one and used it. I had added to it and now it works for me. All those OR's may not be needed. But since it works I do not want to play with it.
However, what does that .... if ( ! ($userfile etc etc mean ??? The exclamation point.?

Thanks for your help. and I will be grading this test ..........
Jan 23 '08 #4
Markus
6,050 Expert 4TB
I can not post the code from before because its all jumbled up with all the echo's.
But I do appreciate this and will try it out. I figured that I would have to do it this way, but knew I would not know where to start.

Here is a Newbie question. I try to read code out of books and articles and would like to know what exactly do these mean.

Something like this ....
Expand|Select|Wrap|Line Numbers
  1. $this ->template_dir = Template_dir;
  2. $page -> display('index.pl');
  3. $result = $this -> db -> getone($queryString);
What does the "->" mean?

how about this.....
Expand|Select|Wrap|Line Numbers
  1. if (DB :: isError($result))
------- This has two COLONS together in the line.
What do the two colons together mean?

And when is it that you use two == signs together ? I have seen statements with a combinatin of single and double = signs in the same statement.

and this one.....
Expand|Select|Wrap|Line Numbers
  1. if (!($userfile_type =="image/pjpeg" OR $userfile_type == "image/jpeg" OR $userfile_type == "image/gif" OR $userfile_type == "image/pjpg" OR $userfile_type == "image/jpg"))
I found this one and used it. I had added to it and now it works for me. All those OR's may not be needed. But since it works I do not want to play with it.
However, what does that .... if ( ! ($userfile etc etc mean ??? The exclamation point.?

Thanks for your help. and I will be grading this test ..........
To the last point you ask, if statements return TRUE or FALSE.

[php]
$x = 0;
$y = 0;
if($x == $y){ // if x is equal to y -- returns true
// do code
}
/* if you wanted to check whether something returned false, you wou;d add an exclamation mark: */

function somefunction(){
return false;
}

if(!$somefunction){
echo "function returned false!";
} else {
echo "function returned true";
}
[/php]
Sorry, i have to get going!
Jan 23 '08 #5
dlite922
1,584 Expert 1GB

What does the "->" mean?
That is used for accessing an object's functions or data members (learn classes and it will make sense)

Expand|Select|Wrap|Line Numbers
  1. if (DB :: isError($result))
  2.  
------- This has two COLONS together in the line.
What do the two colons together mean?
:: is like -> but for accessing public static members or functions.

in your example DB is a class, isError() is a public method of that class.

And when is it that you use two == signs together ? I have seen statements with a combinatin of single and double = signs in the same statement.
== is a comparison operator. checks if something is equal to something else

= is an assignment operator. takes the value of the right hand and puts it into the left hand value.


and this one.....
Expand|Select|Wrap|Line Numbers
  1.  
  2. if (!($userfile_type =="image/pjpeg" OR $userfile_type == "image/jpeg" OR $userfile_type == "image/gif" OR $userfile_type == "image/pjpg" OR $userfile_type == "image/jpg"))
  3.  
  4.  
I found this one and used it. I had added to it and now it works for me. All those OR's may not be needed. But since it works I do not want to play with it.
However, what does that .... if ( ! ($userfile etc etc mean ??? The exclamation point.?
The if statement checks to see if the variable $userfile_type is any of the PHP defined image types, jpg, or gif basically, but PHP defines those multiple ways, hence you have 5 comparison.

! means the opposite. it negates the value after it example: "!True" equals false.

OR (also written as two bars || ) means any of those matches.
[PHP]
if (a == b || a ==c)
{
// this executes if a equals b OR a == c. obviously if a equals b, it doesn't bother comparing it with C (the logic shortcut).
}
[/PHP]


All of the above answers are readily available from google and php.net.

Try to figure this logic out just for your practice:

[PHP]

function checkGoogle($Q)
{
return $found;
}

if(checkGoogle($YourQ) == TRUE)
{
echo "Good Job!";
}
else
{
echo "Ask the people at TSDN";
}


[/PHP]
Jan 23 '08 #6
CDFTim
8
Ok now I am back working on my <DIV> and as you recall from above I want to increase the DIV id=Name0 by one each time the Do.. While loop works its way through.
However....... Instead of ECHO-ing out each HTML line I used dreamweaver and inserted the Database item encased in a PhP tag into the HTML table where it should show up.
So it looks like this....
Expand|Select|Wrap|Line Numbers
  1. <?php  Do {  ?>
  2. <div id="billboard0" class="billcontent">
  3. <td><table width="176" border="0" cellspacing="0" cellpadding="0">
  4.     <tr>
  5.  <td width="104" class="rotatorprice"><?php echo $row_mlsdata1['price']; ?>
  6.       </td>
  7. <td width="72" nowrap class="rotatorinfotext"><b>MLS#:</b><?php echo $row_mlsdata1['mlsnumber']; ?>
  8.        </td>
  9.             </tr>
  10.              </table>       </td>
  11. </div>
  12.  <?php } while ($row_mlsdata1 = mysql_fetch_assoc($mlsdata1)); ?>
  13.  
So with each do while loop I need the id name to increase by one...
<div id="billboard1" class="billcontent">the data area I have working now</div>
<div id="billboard2" class="billcontent">the data area I have working</div>
<div id="billboard3" class="billcontent">the data area I have working now</div>


I tried to use what you showed be above and try to place the Variable into the Div id name. But probably am not doing it correctly.
Expand|Select|Wrap|Line Numbers
  1.     <?php do { 
  2.  
  3. function buildDivs($_amount)
  4.  {
  5. for( $_i = 0; $_i <= $_amount; ++$_i)
  6.  }
  7.  echo buildDivs(10);
  8.  ?>
  9.    <div id=\"billboard\"<?php $_i ?>\" class="billcontent">;
  10. <table border="0" cellspacing="0" cellpadding="1">
  11.               <tr>
  12.                 <td bgcolor="#000000"><img src="/images/listings/<?php echo $row_mlsdata1['picture']; ?>" width=174 height=130 border="0"></td>
  13.                 </tr>
  14.               </table>     
  15. </Div>
  16. <?php } while ($row_mlsdata1 = mysql_fetch_assoc($mlsdata1)); ?>
  17.  
  18.  
But this does not work.....
Jan 24 '08 #7

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

Similar topics

6
by: Ben | last post by:
Hi all, This has been asked in the past in different ways. I'm still a bit confused about setting up counters. I'm quite new to php. I've read few tutorials about writing counters using cookie and...
4
by: Shane | last post by:
:) I am following a tutorial for php (hudzilla.org) absolutely loving it however I am having trouble with the counter example <?php // your content here... $filename = 'counter.txt'; // our...
3
by: Ronan Viernes | last post by:
Hi, I have created a python script (see below) to count the maximum number of threads per process (by starting new threads continuously until it breaks). ###### #testThread.py import...
11
by: TomCat | last post by:
Hello, can anyone send me a link or even some sample of script that counts visits to a website ? Thanks, TomCat
4
by: Ian Davies | last post by:
Hello I have seen some tutorials to put a update a counter field in a record. I have the counter field in a table that also has a field for a path to file. I display the records in a table on...
12
by: devospice | last post by:
Hi, I'm trying to create a download counter for individual files on a web site and I'm not sure how to do this. Right now I'm using Webalizer to just read the log files and see how many times...
1
by: JuAn2226 | last post by:
hi i'm having trouble with my code If lblNumberArray(i) = lbltmpNumber Then EndTime = Now lblEnd(i).Caption = Format(EndTime, "hh:mm:ss") StartTime = lblTime(i) Timeduration =...
9
by: Pygmalion | last post by:
I have found dozen of useful PHP counters on the web. However, nobody is working for my web pages, since administrator does not want to enable the possibility that PHP could be called from HTML. ...
3
by: DavidPr | last post by:
I made a website for a group of people and they want a visitor counter on it. I don't like hit counters because if the site is dead everyone will know it. But, it's their website. I did an...
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
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
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
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.