Renlok Posted October 21, 2006 Share Posted October 21, 2006 If you have a database with a number of values in it and then if you take them from the database with php how would you have it so you have a table showing each value in the database, showing number that each particular value has been entered.Thanks for any help. Quote Link to comment Share on other sites More sharing options...
obsidian Posted October 21, 2006 Share Posted October 21, 2006 you lost me with the part about "showing number that each particular value has been entered", but i'm guessing you simply mean echoing them in chronological order. first off, you need to have an id column that is auto_incremented that you can then reference to see what order they are in. once that is in place, just do the following:[code]<?php$sql = mysql_query("SELECT * FROM myTableName ORDER BY id");echo "<table>\n";if (mysql_num_rows($sql) > 0) { while ($x = mysql_fetch_array($sql)) { echo "<tr>\n"; echo "<td>$x[id]</td>\n"; echo "<td>$x[value]</td>\n"; echo "</tr>\n"; }} else { echo "<tr><td>No records returned</td></tr>\n";}echo "</table>\n";?>[/code] Quote Link to comment Share on other sites More sharing options...
Renlok Posted October 21, 2006 Author Share Posted October 21, 2006 oh no i now how to do that, sorry for not making it clear with "showing number that each particular value has been entered"Ok urm heres an example of what i what it to do:The Database table:ID ¦ Name1 ¦ John2 ¦ Mike3 ¦ Joe4 ¦ Mike5 ¦ John6 ¦ JohnThat should then show:Rank ¦ Name ¦ Enties--------------------------1 ¦ John ¦ 32 ¦ Mike ¦ 23 ¦ Joe ¦ 1Hope thats clearer Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 21, 2006 Share Posted October 21, 2006 [code]<?php<?php$sql = mysql_query("SELECT COUNT('ID') as Number, Name FROM myTableName GROUP BY Name ORDER BY number DESC");echo "<table>\n";if (mysql_num_rows($sql) > 0) { echo "<tr>\n"; echo "<td>Rank</td>\n"; echo "<td>Name</td>\n"; echo "<td>Entries</td>\n"; echo "</tr>\n"; $count = 0; while ($x = mysql_fetch_array($sql)) { $count++; echo "<tr>\n"; echo "<td>$count</td>\n"; echo "<td>$x[Name]</td>\n"; echo "<td>$x[Number]</td>\n"; echo "</tr>\n"; }} else { echo "<tr><td>No records returned</td></tr>\n";}echo "</table>\n";?>?>[/code] Quote Link to comment Share on other sites More sharing options...
Renlok Posted October 21, 2006 Author Share Posted October 21, 2006 ok i changed the code to work with my page[code]<?php # line 115 $sql = mysqli_query("SELECT COUNT('ID') as Number, searchterm FROM search GROUP BY searchterm ORDER BY number"); echo "<table>\n"; # line 120 if (mysqli_num_rows($sql) > 0) { echo "<tr>\n"; echo "<td>Rank</td>\n"; echo "<td>Search Term</td>\n"; echo "<td>Entries</td>\n"; # line 125 echo "</tr>\n"; $count = 0; while ($x = mysqli_fetch_array($sql)) { $count++; echo "<tr>\n"; echo "<td>$count</td>\n"; echo "<td>$x[Searchterm]</td>\n"; echo "<td>$x[Number]</td>\n"; echo "</tr>\n"; } } else { echo "<tr><td>No records returned</td></tr>\n"; } echo "</table>\n"; ?> # line 140</center> <?php mysqli_free_result($result); $db->close(); ?> # line 145[/code]comes out with the errors[quote]Warning: mysqli_query() expects at least 2 parameters, 1 given in /home/renlok/public_html/topsearch.php on line 119Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /home/renlok/public_html/topsearch.php on line 121No records returnedWarning: mysqli_free_result() expects parameter 1 to be mysqli_result, null given in /home/renlok/public_html/topsearch.php on line 143[/quote] Quote Link to comment Share on other sites More sharing options...
Renlok Posted October 22, 2006 Author Share Posted October 22, 2006 ??? anyone have anything? Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted October 22, 2006 Share Posted October 22, 2006 obviously your missing a parameter in your query.when using mysqli your first parameter must be your mysqli connection.example:[code=php:0]$link = mysqli_connect("localhost", "user", "password", "db");$result = mysqli_query($link, "SELECT blah FROM table");[/code]hope this helps. 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.