PDA

View Full Version : 2 questions on displaying tables using do{}while


Psychoman
08-17-2004, 05:32 PM
Alright, I have two issues that I ran into last night after I thought that I would finally finnish my admin page.

1) Is that I have a <tr> that I want to display only once at the beginning of the table, then display another <tr> that will be repeating untill there are no mysql rows in the database. the catch is that i want the second <tr> to have a variation of the first one and not repeat the same information on the first display.

ex.
<tr1>
<tr2>
<variaton of tr1>
<tr2>
<variaton of tr1>
<tr2>
<ending tr>

2) My <tr>'s have radio buttons that have 3 options per <tr> they all have the same name, so when two radio buttons are pressed on diffrent <tr>'s the second cancels the first. How could I keep the name so that i can update the tables using an array, yet group them by 3's?

Hope these questions where easy to follow, I tried my best to make them clear.
Ray

raf
08-17-2004, 06:08 PM
i didn't understand it.

can you hardcode the desired output + the inut (recordset) so we can join the dots?

Psychoman
08-17-2004, 06:11 PM
Sure thing raf, I'll do it in just a sec

Psychoman
08-17-2004, 06:32 PM
The attached file is a php with the extension changed to .txt, I comented the table for the first question so you see what I mean. The second table just shows you my radio button dilema.

Thanks,
Ray

Psychoman
08-17-2004, 07:09 PM
actually, you can forget about the first one, I managed to get my client to like something better (in my opinion anyways :D ) and that I can code. However, i do still have that problem with the radio buttons, so if you could help me with that i'd apreciate it

As5a5sIn5
08-17-2004, 07:57 PM
Im not completely sure what your asking...but i think what you need to do is for each different <tr> with the radio buttons make a new do...while becuz each radio set must have a different name="dif_radio"

Psychoman
08-17-2004, 08:25 PM
So your saying I would need to have a do{}while for the buttons with a dynamic name and then pass the variable to an array?

raf
08-18-2004, 12:27 AM
i still don't understand what you try to achieve. (by the way, by hardcode output, i means write the source like it would be in your browser. The output of your php script. the pure html that is sent to the browser)

Psychoman
08-18-2004, 12:48 AM
You don't seize to teach me something new everyday raf :) sorry about that. Really there was no point in the way she wanted it, so what I ended up doing was

$vary = 1;
if ($myrow = mysql_fetch_array($result)) {
do {
if ($vary == 1){
$vary = 2;
?>
<tr>
<td width="171" bgcolor="#333333"><div
// Table Content
</tr>
<?
} else {
$vary = 1;
?>
<tr bgcolor="#666666">
// Table Content
</tr>
<?
}
} while ($myrow = mysql_fetch_array($result));
However, for the radio buttons let me see if I can try making it clearer

I have a repetitive table, it dynamically loads all the data from mysql. in each loop, the table recreates a set of 3 radio buttons


<input name="qtype[<?php echo $myrow["id"]; ?>]" type="radio" value="blank">
<span class="style5">Blank<br>
<input name="qtype[<?php echo $myrow["id"]; ?>]" type="radio" value="checkbox">
Checkbox<br>
<input name="qtype[<?php echo $myrow["id"]; ?>]" type="radio" value="radio">
Radio Buttons

My problem is, since they are named the same trought the table, I can only select one for all of my rows. This won't work because the whole table's function is to update data.

does this help any or should I try a diffret approach to my problem?

As5a5sIn5
08-18-2004, 12:52 AM
Really there was no point in the way she wanted it, so what I ended up doing was

When you say she who are you referring to? :D

Psychoman
08-18-2004, 12:56 AM
My psychotic client :D (If only she could hear me now.....)

sad69
08-18-2004, 01:01 AM
My psychotic client :D (If only she could hear me now.....)
They're all psychotic, IMO anyway.. :D

Sadiq.

raf
08-18-2004, 01:08 AM
My problem is, since they are named the same trought the table, I can only select one for all of my rows. This won't work because the whole table's function is to update data.

I think i see your point.

Each radiobuttion (with that same name) appears multiple times. Once for each table, so you don't know on which row the user clicked.

But the number of tables is fixed right? Inside each iteration, a fixed number of tables is created, right?
So why not make it a multidimensional array, by adding something in front of the id. Like

name="thename[1][theid]"

which then refers to table 1. or simply

name="table1_thename[theid]"

Psychoman
08-18-2004, 01:22 AM
the tables arent fixed, it only displays selected ones by id that the admin would define from a previous page, I think that may still work though.... Shouldnt it?

raf
08-18-2004, 01:27 AM
i don't know.

if the tables are selected on a previous page, then i'd assume that you have some sort of posted value or some sort of value for each included table. So you could use that value then as part of all that tables formfields, and thus make them unique. but this would then allow you to group them after this page is posted.

Psychoman
08-18-2004, 02:05 AM
perfect, because I selected them by id :) It's funny, I post questions so often youd think I ask for everything I do, but in reality I work on code all the time, when I get stuck, I post and work on something else till I get an answer. Thanks to you I've moved along really nicely the last couple of days :) thanks a million :D

raf
08-18-2004, 07:34 AM
You're welcome. The bill is in the mail :D