Forum Moderators: coopster

Message Too Old, No Replies

Please help on this array

         

bobnew32

8:10 pm on Aug 7, 2003 (gmt 0)

10+ Year Member



Ok I have like 30 rows of info, where only 1 field needs to be in table. The table goes by threes,

<tr><td>Row1</td> <td>Row2</td> <td>Row3</td></tr>

Then it would notice three entries are up and do the next three,

<tr><td>Row4</td> <td>Row5</td> <td>Row6</td></tr>
Then again,:
<tr><td>Row7</td> <td>Row8</td> <td>Row9</td></tr>

Until all the entries are used up. I am not good at arrays at all, and would not know at all how to accomplish this. But the sql would be "Select * from screen_saver where category_id=1 order by name desc". Thanks for your help.

jatar_k

8:39 pm on Aug 7, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if you only need 1 field you should maybe not select * just do

Select fieldname from screen_saver where category_id=1 order by name desc

then you can load each value into an array using mysql_fetch_array [ca.php.net]

something like
$q = "Select fieldname from screen_saver where category_id=1 order by name desc";
$result = mysql_query($q);
while ($row = mysql_fetch_array($result)) {
$rowarr[] = $row['fieldname'];
}

at this point you will need to populate your table with the data. Does the number of rows change? If so you could look at this to dynamically build a table

$current_cell = 1;
$maxcells = 4;
$counter = 0;

echo "<table>";
while (is_array($rowarr[$counter])) { //not sure if this is the best test maybe!empty or!isset
if ($current_cell == 1) echo "<tr>";
echo "<td>",$rowarr[$counter],"</td>";
if ($current_cell == 4) {
echo "</tr>";
$current_cell = 1;
} else {
$current_cell++;
}
$counter++;
}
switch ($current_cell) {
case 2:
echo "<td>&nbsp;</td>";
case 3:
echo "<td>&nbsp;</td>";
case 4:
echo "<td>&nbsp;</td>";
echo "</tr>";
break;
}
echo "</table>";

HTH

bobnew32

8:56 pm on Aug 7, 2003 (gmt 0)

10+ Year Member



Ok, im sorry I posted the total wrong sql statement. It should be "Select * from check_mark" . Now, the table with a 3 tds for every tr is going to hold check marks. Im sorry if that messed up the coding for that.

jatar_k

8:58 pm on Aug 7, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



np
echo "<td>",$rowarr[$counter],"</td>";

that is the cell content line, you can replace the stuff in bold with whatever you like. Presently, it just outputs the content of the array.

bobnew32

2:22 am on Aug 8, 2003 (gmt 0)

10+ Year Member



Then what is the purpose of $rowarr[] = $row['fieldname'];?

bobnew32

2:34 am on Aug 8, 2003 (gmt 0)

10+ Year Member



I have retyped my post to be a little more specific:


Ok I have like 30 rows of info, where only 3 field needs to be in table. The table goes by threes in 2's in <td>s before it needs to start a new tr.

<tr><td>Row1</td> <td>Row2</td> <td>Row3</td></tr>

Then it would notice three entries are up and do the next three,

<tr><td>Row4</td> <td>Row5</td> <td>Row6</td></tr>
Then again,:
<tr><td>Row7</td> <td>Row8</td> <td>Row9</td></tr>

Until all the entries are used up. I am not good at arrays at all, and would not know at all how to accomplish this. But the sql would be "Select * from check_mark order by name.

Here is one example of a td:

<INPUT type=checkbox value= $value
name=$call_name>$name

So for each row inside a td will be this information. Thanks alot for any who decide to help me.