Vecteevs Posted May 20, 2010 Report Share Posted May 20, 2010 Sveiki! Man tāda neliela problēma, nezinu kā parādītu datus manā gadījumā bonusus katram lietotājam savus. Man sanāk parādīt visus punktus. Īsti nezinu kas jādara lai parādītu katram lietotājam savus.. <?php $host="localhost"; // Host name $username="root"; // Mysql username $password="xxxx"; // Mysql password $db_name="test"; // Database name $tbl_name="members"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); ?> <table width="82" border="1" cellspacing="1" cellpadding="0"> <tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td>Bonusi:</td> <td width="25" align="center"><? echo $rows['bonus']; ?></td> </tr> <?php } ?> </table> </td> </tr> </table> <?php mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted May 20, 2010 Report Share Posted May 20, 2010 Kādi lauki tajā tabulā un kādi paraugdati? Quote Link to comment Share on other sites More sharing options...
Vecteevs Posted May 20, 2010 Author Report Share Posted May 20, 2010 man no visas tabulas vajag izmantot tikai username un bonus visu es saliku ka username = username nu pie ielogošanās ja tā tu domāji. Un ar bonusiem ir tā: bonus = bonus Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted May 20, 2010 Report Share Posted May 20, 2010 tabulā ir: peteris 2 janis 3 anna 5 peteris 3 janis 1 ? select user, sum(bonus) AS bonus from tabula group by user Quote Link to comment Share on other sites More sharing options...
Vecteevs Posted May 20, 2010 Author Report Share Posted May 20, 2010 jā, tā ir, bet kā tad man visam jāizskatās? šis te- select user, sum(bonus) AS bonus from tabula group by user jāieliek te- $sql="SELECT * FROM $tbl_name"; Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted May 20, 2010 Report Share Posted May 20, 2010 Jā. un jāaizvieto ar taviem tabulas un lauku nosaukumiem (kurus tā arī nepateici). Quote Link to comment Share on other sites More sharing options...
Vecteevs Posted May 20, 2010 Author Report Share Posted May 20, 2010 tagad man izskatās šādi un ideja ir tāda ka jāparāda šādi: Bonusi: (te punkti kuri ir piešķirti) datubāze: Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted May 20, 2010 Report Share Posted May 20, 2010 SELECT bonus FROM $table_name WHERE id = $lietotaja_id Quote Link to comment Share on other sites More sharing options...
Vecteevs Posted May 20, 2010 Author Report Share Posted May 20, 2010 (edited) hmm, kas nav. Nerāda tos punktus. Testējot vai būs viss okey izdarīju šādi $sql="SELECT bonus FROM $table_name WHERE id = 1 "; viss kods: http://paste.php.lv/894b0c98702bb0d9caa9e9232d227be5?lang=php Edited May 20, 2010 by Vecteevs Quote Link to comment Share on other sites More sharing options...
php newbie Posted May 20, 2010 Report Share Posted May 20, 2010 12 rindiņā $tbl_name nevis $table_name Quote Link to comment Share on other sites More sharing options...
Chapman Posted May 21, 2010 Report Share Posted May 21, 2010 pēc C++ spriezot &query = ("SELECT * FROM $tbl_name ORDER BY NAME") Quote Link to comment 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.