Hi
I'm struggling with a problem that I haven't been able to find the answer to. Essentially I have a DB that contains some values that help in the construction of the page when it is served. I have it working but I'd like to improve because the maintenance cost is high.
So...
After data is selected from the db I place it in a series of arrays
//Put Data into an array
while ($Row = mysql_fetch_array($linksData))
{
$adid[] = $Row[adid];
$adcategory[] = $Row[adcategory];
$addivid[] = $Row[addivid];
$adname[] = $Row[adname];
}
Then for each element on the page before it is served the first time - I force set a unique variable value - in this case "26" which corresponds to the row that contained the relevant data in the db and helps me identfiy these values in the arrays. The php is then parsed and everything works well.
An example of the php script is below - as you can see a javascript function uses text maintained in the db.
<div id="ISP1"
style="position:absolute;
left:328px; top:43.433px;
width:6px;
height:6px;
z-index:2;
background-color:#fff;
border:solid #000 1px"
set="<?php $var = 26 ?>"
OnMouseOver=writeText(event,'<?php echo " $adcategory[$var] $adname[$var] " ?>','title');
.......
</div>
My question is about making this better because the risk is quite high - you have to ensure that the variable number really does correspond to the data, and any mistake is just annoying.
Bearing in mind that the database also contains the Div ID value (in this case ISP1) the approach that I would rather take - and I don't know how to do this - is something like this:
loop at all elements on the page
When the div-id = $addivid
find the value in the array that this div id corresponds to and point $var to it
then echo " $adcategory[$var]"
endloop.
OK you can probably tell that I have an SQL backround - hence the looping bit - but any better method is welcome.
Chris
use an element's ID to identify a record in an array
Moderator: General Moderators
-
chrisdcosta
- Forum Newbie
- Posts: 2
- Joined: Fri Nov 28, 2008 3:36 am
-
chrisdcosta
- Forum Newbie
- Posts: 2
- Joined: Fri Nov 28, 2008 3:36 am
Re: use an element's ID to identify a record in an array
Anyone out there to answer this?
Re: use an element's ID to identify a record in an array
I'm kinda lost. What does all this accomplish?