Jump to content

trying to make a div parent of all rows pulled from database


alexandre
Go to solution Solved by Barand,

Recommended Posts

i am not sure how i should proceed , as far as i went on this , it turned out that i am unable to make a div go underneath all the rows diplayed so it can serve as body for the ranking section.  

  echo "<div class='rankingtrue2'>
					<div class='ranking_wrapper'>
					<table class='rankingtable'>
	            <tr>
	               <td>username</td><td>last donation</td><td>total donated</td><td>total_received</td>
	            </tr>
	            <tr>
	                <td class='remain1'>" . $result_row['users_name']. "</td>
	                <td class='remain2'>" . $result_row['donation']. "</td>
	                <td class='remain3'>" . $result_row['total_donated']. "</td>
                  <td class='remain4'>" . $result_row['total_received']. "</td>
	            </tr>
	        </table>
					</div>
				 </div><br><br>";
}
}

this is an example of the grid formatting, now whatever i try the divs are acting only on a single row. if anyone have an idea how to do that i would appreciate.

image_2022-11-06_173958711.png

Link to comment
Share on other sites

  • Solution

At the moment you appear to have something like this

start loop {
    <div>
        <div>
            <table>
                <tr>
                    headings
                </tr>
                <tr>
                    data 
                </tr>
            </table>
        </div>
    </div>}    
} end loop

It sound like what you want is this

<div>
    <div>
        <table>
            <tr>
                headings
            </tr>
            
start loop {
                <tr>
                    data 
                </tr>
} end loop

        </table>
    </div>
</div>}    

 

Link to comment
Share on other sites

18 minutes ago, Barand said:

At the moment you appear to have something like this

start loop {
    <div>
        <div>
            <table>
                <tr>
                    headings
                </tr>
                <tr>
                    data 
                </tr>
            </table>
        </div>
    </div>}    
} end loop

It sound like what you want is this

<div>
    <div>
        <table>
            <tr>
                headings
            </tr>
            
start loop {
                <tr>
                    data 
                </tr>
} end loop

        </table>
    </div>
</div>}    

 

yes i was indeed trying to open and close a div around the while loop but without any success . this seems more like what i need and will try it right away. 

i just havve one more question, do i echo just once or both when i open the div and when i close it ?

Link to comment
Share on other sites

it worked , the div is under the ranking but i cant give it a height it will stay the size of the row, i tried to set the height and max height but it wont move, could it be needing a css property to expand it over a certain limit or am i missing something? 

 i also want to keep the repetitive headings , i believe this way it is adding a  bit of a separation and readability between the records and their meanings.

 

image_2022-11-06_182859911.png

Link to comment
Share on other sites

And I think you only need the one div to wrap the entire table in.  And yes - use the <th> tags for your headings and then don't echo them out any more.

//  Begin table
echo "
	<div class='tbl_box'>
	<table class='rankingtable'>
	<tr>
		<th>username</td>
		<th>last donation</th>
		<th>total donated</th>
		<th>total_received</th>
	</tr>
	";
// data rows into table
while($result_row ->fetch())
{
	echo "
		<tr>
		<td class='remain1'>{$result_row['users_name']}</td>
		<td class='remain2'>{$result_row['donation']}</td>
		<td class='remain3'>{$result_row['total_donated']}</td>
		<td class='remain4'>{$result_row['total_received']}</td>
		</tr>
		";
}
// end the table and div
echo "
	</table>
	</div>
	";

Note the use of {} to wrap your row data fields instead of what you were doing.

as for the height of your headings row: That' s simply some Css that you could add for that row. Or simply add a <br> tag to the heading text

Link to comment
Share on other sites

14 minutes ago, ginerjm said:

And I think you only need the one div to wrap the entire table in.  And yes - use the <th> tags for your headings and then don't echo them out any more.

//  Begin table
echo "
	<div class='tbl_box'>
	<table class='rankingtable'>
	<tr>
		<th>username</td>
		<th>last donation</th>
		<th>total donated</th>
		<th>total_received</th>
	</tr>
	";
// data rows into table
while($result_row ->fetch())
{
	echo "
		<tr>
		<td class='remain1'>{$result_row['users_name']}</td>
		<td class='remain2'>{$result_row['donation']}</td>
		<td class='remain3'>{$result_row['total_donated']}</td>
		<td class='remain4'>{$result_row['total_received']}</td>
		</tr>
		";
}
// end the table and div
echo "
	</table>
	</div>
	";

Note the use of {} to wrap your row data fields instead of what you were doing.

as for the height of your headings row: That' s simply some Css that you could add for that row. Or simply add a <br> tag to the heading text

i tried all the properties i know in css to try and make the div expand but there is nothing that makes it move, just as if it was again affecting a single row.

and for the headings i want to keep them repetitive do you think it is affecting the wrapping div if i leave the headings inside the loop and just put the table around the loop with the needed divs? (the other divs are simply for adding some borders to the design).

also i didnt know that i could use brackets to isolate a variable in a string, if i understood right , thank you for the advice it seems like a good practice .

Link to comment
Share on other sites

3 minutes ago, ginerjm said:

What does this mean?  I thought we were talking about a row?

You want to output a set of headings for ever data row in your report/screen?  Kinda messy to me.

no , i wanted to make a div serve as body like kind of background for the whole table, so it doesnt look like a set of rows floating in the void

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.