PDA

View Full Version : php help needed, urgent :)


Don-Dad
06-06-2006, 06:01 AM
Ok I have this bit of code

<script type="text/javascript">
//Start Ajax tabs script for UL with id="maintab" Separate multiple ids each with a comma.
startajaxtabs("maintab")
</script>

I have a piece of data that pulls from a database and it looks this

$row[id]

I need to replace maintab with the $row[id] and be able to add multiple instances
startajaxtabs("$row[id]","$row[id]","$row[id]")

The $row[id] is a unique number

I have another piece of code

print "<ul id='$row[id]' class='shadetabs'>\n"; the id='$row[id]' will be unique for a list of 15 items

this part has to have those number

startajaxtabs("$row[id]","$row[id]","$row[id]")

Make sense?

Please help [-o<

vertygo
06-06-2006, 06:35 AM
so is $row[id] an array and you just want to iterate and echo out each array element ?

Sounds like you could just add a loop in there to do that ? But I'm thinking I'm not reading that quite right ?

Don-Dad
06-06-2006, 01:22 PM
Not an array (I'm not a programmer so forgive me if I'm wrong about that)

$row[id] is the unique identifier for each record. I need that ID number placed in that bit of code "id","id", etc...

ian
06-06-2006, 01:55 PM
No, what you need is an array. Well you could automate it a bit and Have it automatically number the tabs for you and then create the array by itself.


<? php

$rowID = array();

$rowID[1] = "First Thing"
$rowID[2] = "Second Thing"
$rowID[3] = "Third Thing"

?>


Then this would make the output for you without you having to do each tab.


for($i=0;$i<=count($RowID);$i++) {
print "<UL id='$RowID[i]' class='shadetabs'>\n";
}

or

$i = 0;
while ($i <= count($RowID)) {
print "<UL id='$RowID[i]' class='shadetabs'>\n";
$i++;
}


On 2 hours sleep I think that will work...

Don-Dad
06-06-2006, 02:46 PM
Thanks for the reply,

but does this have to be hand coded


<? php

$rowID = array();

$rowID[1] = "First Thing"
$rowID[2] = "Second Thing"
$rowID[3] = "Third Thing"

?>
I'm pulling all the information from a database

so not sure how I would get that done, I have 1,000's of records

I had a script working but it seemed buggy in IE so I was trying to try this new script, I may just scrap it if I can't gt it working today.

Don-Dad
06-06-2006, 02:56 PM
I think I'm scrapping this script. I was getting all gung ho on using some ajax but I think I'm doing myself a disservice by excluding those who have javascript turned off and that could lead to loss of income.

vertygo
06-06-2006, 05:38 PM
Heh I hope you don't use alot of CJ merchants then.. cause after march next year.. ALL JS links.. no HTML anymore.

Don-Dad
06-06-2006, 05:57 PM
Yeah, that whole CJ thing is a debacle. I'm still thinking this through, I like the ajax, just neat to me and I think if used correctly, user friendly, I just hate to think I am losing potential sales. Though things can't get much worse than they are now :)

I'm doing a little indoor painting and thinking about this, lucky grandma came over to take the youngest with her, kind of a birthday present, though I don;t call painting a "good" present :twisted:

Anonymous
06-19-2006, 05:43 AM
Hi,

I don't know much about Ajax but I do know soething about PHP.

It looks to me link you are trying to cross the boundary between PHP and Javascript.

I will have to sugest someting general as I do no have a clue how the function startajaxtabs("maintab") is defined in Javascript.

I also do not know how many different instances of $row('id') there are in PHP.

It is also confusing to see $row[id] rather than $row[$id] or $row['id'].

Furthermore (from memory) there should be a semicolon after the definition of startajaxtabs ie

<script language="javascript">
<!--
startajaxtabs("maintab");
-->
</script>

Also you will need a unique identifer witin the Javascript this must be generated within PHP.

I will assume as someone else here has that this code is accessed as a class in html.

So here goes.

<?php
// First extablish how many instances there are of data elements.

// It could be set to a literal value $total=15;

// This could be someting like

$total = count(rowdata[]);

// Depending on where you data is coming from.

// Now generate the Javascript function definition.

echo('<script type="text/javascript">' . "\n");
echo('startajaxtabs(' );

for($count=1; $count<=$total; $count++)
{
echo('"row' . $count . '"');
if ($count<<$total) echo(',');
}

echo(");\n");
echo("</script>\n");

?>

then later in the generation of the html page you would refer to the definitions this way -

<?php

for($count=0; $count<=$total; $count++)
{
echo('<UL id="'. 'row' . $count . '" class="shadetabs">' . "\n");
}

?>


Obviously there is more to it than this but I cannot offer more sugestions without seeing how PHP is accessing the database and an example of an output page.

PS: Just visiting your site as I read about it in the news.

jeffus
06-24-2006, 05:53 AM
Best bet - go to the DOS command prompt and enter: Format C:\ and when it asks if you are sure, answer "Yes".

Works every time! :wink: