vinsux Posted March 11, 2013 Share Posted March 11, 2013 hi there, i just wanna ask a question.. i'm making a poll using php right now.. may i ask if it's possible to set the width of a <td> in a table from the values from the database?.. also how can i count the total value of numbers in a database. in my database, i have a number of votes from different names, how can i count them all? because i need it to get the percentage of the votes.. please help me thanks and god bless.. Quote Link to comment https://forums.phpfreaks.com/topic/275507-question-please/ Share on other sites More sharing options...
vinsux Posted March 11, 2013 Author Share Posted March 11, 2013 i already found out the solution on counting the values, i only need the solution on how to set the width of a table from the value from the database.. Quote Link to comment https://forums.phpfreaks.com/topic/275507-question-please/#findComment-1417976 Share on other sites More sharing options...
AyKay47 Posted March 11, 2013 Share Posted March 11, 2013 I'm sure it's possible. Can you give a better description/example of what exactly you want to do? Quote Link to comment https://forums.phpfreaks.com/topic/275507-question-please/#findComment-1417979 Share on other sites More sharing options...
Psycho Posted March 11, 2013 Share Posted March 11, 2013 (edited) Your question is a littlee confusing because the answer seems painfully obvious. If you have a value from the database, just set the width to what you want. I have no idea how you plan to set the width based upon the value from the database. Do you want the value to be set to the actual value from the database or calculated based on that DB value? Also, you can set the value in the actual HTML or within the Style sheet. <table style="width: <?php echo $valueFromDB; ?>px"> Edited March 11, 2013 by Psycho Quote Link to comment https://forums.phpfreaks.com/topic/275507-question-please/#findComment-1417980 Share on other sites More sharing options...
vinsux Posted March 11, 2013 Author Share Posted March 11, 2013 i tried this one //sql parts $percentage = $votes / 100 * $total; echo "<td class = result style='width:echo $percentage;%'>".$votes."</td>"; but it's not working Quote Link to comment https://forums.phpfreaks.com/topic/275507-question-please/#findComment-1417982 Share on other sites More sharing options...
AyKay47 Posted March 11, 2013 Share Posted March 11, 2013 (edited) //sql parts $percentage = $votes / 100 * $total; echo "<td class='result' style='width:{$percentage}%'>{$votes}</td>"; Edited March 11, 2013 by AyKay47 Quote Link to comment https://forums.phpfreaks.com/topic/275507-question-please/#findComment-1417984 Share on other sites More sharing options...
vinsux Posted March 11, 2013 Author Share Posted March 11, 2013 Your question is a littlee confusing because the answer seems painfully obvious. If you have a value from the database, just set the width to what you want. I have no idea how you plan to set the width based upon the value from the database. Do you want the value to be set to the actual value from the database or calculated based on that DB value? Also, you can set the value in the actual HTML or within the Style sheet. <table style="width: <?php echo $valueFromDB; ?>px"> ^ that sample code is what i'm looking for, but i tried that code and it's not working... sorry for my bad english.. Quote Link to comment https://forums.phpfreaks.com/topic/275507-question-please/#findComment-1417985 Share on other sites More sharing options...
Solution vinsux Posted March 11, 2013 Author Solution Share Posted March 11, 2013 //sql parts $percentage = $votes / 100 * $total; echo "<td class='result' style='width:{$percentage}%'>{$votes}</td>"; gotcha!.. thanks a lot bro and also PsyCho... Quote Link to comment https://forums.phpfreaks.com/topic/275507-question-please/#findComment-1417988 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.