Als ik deze code gebruik, dan werkt het gewoon.

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("test", $con);

$result = mysql_query("SELECT * FROM top");

echo "<table border='1'>
<tr>
<th> ID </th>
<th> Test </th>
<th> Num </th>
<th> Num1 </th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['test'] . "</td>";
echo "<td>" . $row['num'] . "</td>";
echo "<td>" . $row['num1'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysql_close($con);
?>

Maar als ik er order by bijzet werkt het niet meer.

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("test", $con);

$result = mysql_query("SELECT * FROM top ORDER BY num1");

echo "<table border='1'>
<tr>
<th> ID </th>
<th> Test </th>
<th> Num </th>
<th> Num1 </th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['test'] . "</td>";
echo "<td>" . $row['num'] . "</td>";
echo "<td>" . $row['num1'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysql_close($con);
?>

Owja ik krijg dan deze error:


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Documents and Settings\filip\Bureaublad\TWlan\htdocs\linkex\top100.php on line 20
SELECT *
FROM top
ORDER BY num1

Wat is num1? Jouw foutmelding zegt overigens iets over "out", een veld dat niet bestaat ;-)
num1 moet een veldnaam zijn en geen nummer.
num1 is een veldnaam en daarin staat een nummer in.
Bestaat de kolom num1 wel?
De syntax klopt nochtans... maar bedoel je niet $num1?
Ja num1 bestaat.
Want ik kan het wel uitlezen maar er niet op ordenen.
Is num1 wel een INT, of een variant daarop?
Dus geen VARCHAR of TEXT o.i.d.?

Kan je ons een structuur-dump van die tabel geven?
--
-- Table structure for table `top`
--

CREATE TABLE `top` (
`num1` int(255) NOT NULL,
`id` int(255) NOT NULL auto_increment,
`test` text collate latin1_general_ci NOT NULL,
`num` int(255) NOT NULL,
UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=4 ;

Reageren