Jump to content

a simple SELECT....


desjardins2010

Recommended Posts

sorry bout that, here is the code

 

 

 

<?php

 

 

if (!$link = mysql_connect('localhost', 'root', '')) {

    echo 'Could not connect to mysql';

    exit;

}

 

if (!mysql_select_db('tutorial')) {

    echo 'Could not select database';

    exit;

}

 

$sql    = "SELECT * FROM players ORDER BY exper DESC LIMIT 5;

 

 

 

$result = mysql_query($sql, $link);

 

if (!$result) {

    echo "DB Error, could not query the database\n";

    echo 'MySQL Error: ' . mysql_error();

    exit;

}

 

?>

<H2>TOP PLAYERS BY EXPERIENCE</H2><BR>

<?php

 

while ($row = mysql_fetch_assoc($result)) {

 

echo "<table border=\"1\" align=\"left\">";

echo "<tr>{$row['name']}</tr>";

 

 

 

}

 

mysql_free_result($result);

 

?>

 

Now it should be putting out the names of the players with the top 5 highest experience but it's returning an error..

 

Parse error: parse error in C:\wamp\www\test.php on line 23

 

Link to comment
Share on other sites

Ahhh shoots ok yes that would be it..

 

that worked now however the output is all in a row I have tried this

 

while ($row = mysql_fetch_assoc($result)) {

 

echo "<table border=\"1\" align=\"left\">";

echo "<tr>{$row['name']}</tr>"."<BR>"; // notice the <BR> but that didn't do it

 

that gave me this

 

solidsouljasonharrylawrencetom

Link to comment
Share on other sites

I dunno I don't get it makes sence to me but getting this error:

 

Notice: Use of undefined constant count - assumed 'count' in E:\WAMP\www\index.php on line 5

 

 

code is here

 

<?php

 

 

if (!$link = mysql_connect('localhost', 'root', '')) {

    echo 'Could not connect to mysql';

    exit;

}

 

if (!mysql_select_db('tutorial')) {

    echo 'Could not select database';

    exit;

}

 

$sql    = "SELECT * FROM players ORDER BY exper DESC LIMIT 5";

 

 

 

$result = mysql_query($sql, $link);

 

if (!$result) {

    echo "DB Error, could not query the database\n";

    echo 'MySQL Error: ' . mysql_error();

    exit;

}

 

?>

<H2>TOP PLAYERS BY EXPERIENCE</H2><BR>

<?php

 

while ($row = mysql_fetch_assoc($result)) {

 

echo "<table border=\"1\" align=\"left\">";

  echo "<tr><td>{$row['name']}</td></tr>";

}

 

echo "</table>";

 

 

 

mysql_free_result($result);

 

?>

Link to comment
Share on other sites

<H2>TOP PLAYERS BY EXPERIENCE</H2><BR>
<?php

while ($row = mysql_fetch_assoc($result)) {

echo "<table border=\"1\" align=\"left\">";
   echo "<tr><th>Player</th><th>Experience</th></tr><tr align=\"center\"><td>john doe</td><td>894</td></tr>";
}

echo "</table>";

 

so this is working however not given me the results I was hoping for.. what this is doing is drawing a new row for each what I'm looking for is simply a table with two bold headers one saying PLAYER the other saying EXPERIENCE and then each record in a col under it

 

any ideas?

Link to comment
Share on other sites

"<tr><th>Player</th><th>Experience</th></tr><tr align=\"center\"><td>john doe</td><td>894</td></tr>"

 

this is drawing out exactly what I want.. problem is I want the next record to just add itself to the table in DESC order of experience

 

right now it's drawing that out for each record as you said it will do this during a while loop

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.