[php/mysql] Toplist

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
Hoi ik heb een toplist gemaakt (geprobeerd) en het werkt het enige is dat het niet goed geshowd word.
De link replayen zichzelf ofzo. Het is gewoon de bedoeling dat je in elke <td> 3 links ziet en niet meer.
Zoals je ziet heb ik hieronder de bron geplaatst :

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<table border="1" cellpadding="0" cellspacing="0" width="100%">
  <tr><?php

include "config.php";

$query=mysql_query("SELECT * FROM accounts ORDER BY hits_in DESC LIMIT 0,3");
while ($show =@ mysql_fetch_array($query)) {
$rank++;
 $body1 .="<a title=\"$show[hits_in] In | $show[hits_out] Out | Description : $show[description]\" href=\"$show[siteurl]\" target=\"_blank\" onmouseover=\"window.status='[$show[hits_in] In] [$show[hits_out] Out] [$show[description]]'; return true\" onmouseout=\"window.status=''; return true\">$show[title]</a><br>";
}

print "<td width=\"25%\">$body1</td>";

$query2=mysql_query("SELECT * FROM accounts ORDER BY hits_in DESC LIMIT 4,6");
while ($show2 =@ mysql_fetch_array($query2)) {
$rank++;
 $body2 .="<a title=\"$show2[hits_in] In | $show2[hits_out] Out | Description : $show2[description]\" href=\"$show2[siteurl]\" target=\"_blank\" onmouseover=\"window.status='[$show2[hits_in] In] [$show2[hits_out] Out] [$show2[description]]'; return true\" onmouseout=\"window.status=''; return true\">$show2[title]</a><br>";
}
print "<td width=\"25%\">$body2</td>";

$query3=mysql_query("SELECT * FROM accounts ORDER BY hits_in DESC LIMIT 7,9");
while ($show3 =@ mysql_fetch_array($query3)) {
$rank++;
 $body3 .="<a title=\"$show3[hits_in] In | $show3[hits_out] Out | Description : $show3[description]\" href=\"$show3[siteurl]\" target=\"_blank\" onmouseover=\"window.status='[$show3[hits_in] In] [$show3[hits_out] Out] [$show3[description]]'; return true\" onmouseout=\"window.status=''; return true\">$show3[title]</a><br>";
}
print "<td width=\"25%\">$body3</td>";

$query4=mysql_query("SELECT * FROM accounts ORDER BY hits_in DESC LIMIT 10,12");
while ($show4 =@ mysql_fetch_array($query4)) {
$rank++;
 $body4 .="<a title=\"$show4[hits_in] In | $show4[hits_out] Out | Description : $show4[description]\" href=\"$show4[siteurl]\" target=\"_blank\" onmouseover=\"window.status='[$show4[hits_in] In] [$show4[hits_out] Out] [$show4[description]]'; return true\" onmouseout=\"window.status=''; return true\">$show4[title]</a><br>";
}
print "<td width=\"25%\">$body4</td>";

?>
</tr></table>

Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
o ja foutje hier is een voorbeeld van de mislukte output:

http://www.msnshit.com/le/

Acties:
  • 0 Henk 'm!

  • Sjaaky
  • Registratie: Oktober 2000
  • Laatst online: 13:29
check http://www.mysql.com/doc/en/SELECT.html en dan specifiek LIMIT.
Verder is dit het vrij omslachtig en trager om voor zoiets 4 queries uit te voeren ipv 1.

Acties:
  • 0 Henk 'm!

  • Michali
  • Registratie: Juli 2002
  • Laatst online: 29-05 22:54
doe dan gewoon iets als

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<table>
<tr>
<td>
<?php

include "config.php";

$query=mysql_query("SELECT * FROM accounts ORDER BY hits_in");
$count = 0;

while ( $show =@ mysql_fetch_array($query)) 
{
   print "<a title=\"$show[hits_in] In | $show[hits_out] Out | Description : $show [description]\" href=\"$show[siteurl]\" target=\"_blank\" onmouseover=\"window.status='[$show[hits_in] In] [$show[hits_out] Out] [$show[description]]'; return true\" onmouseout=\"window.status=''; return true\">$show[title]</a><br>";
   $count++;
   if ($count==3)
   {
      print "</td><td>";
      $count=0;
   }
}

if ($count > 0)
   print "</td>";

?>
</tr>
</table>


was ff snel zal wel niet helemaal kloppen

[ Voor 41% gewijzigd door Michali op 05-03-2003 19:49 ]

Noushka's Magnificent Dream | Unity


Acties:
  • 0 Henk 'm!

  • Boomerang
  • Registratie: November 2000
  • Niet online
Verder snap ik niet wat @mysql_fetch_array voor nut heeft, maja zal wel aan mij liggen :)

Het beste kun je IMHO het volgende doen voor je query:

PHP:
1
2
3
4
5
6
$query = mysql_query("SELECT * FROM accounts ORDER BY hits_in");
if($query) {
 // Wat wil je doen als Query gelukt is, en eventueel...
} 
else { // Als query niet gelukt is..
}


Waarom zou je fouten onderdrukken, als je niet precies weet wat de oorzaak is ?

edit:

Euhm.. shit |:( je hebt helemaal gelijk Nielsz, maar je begrijpt neem ik aan wel wat ik bedoel ? Het beste is nog steeds om een eigen error functie voor MySQL te bouwen.

[ Voor 22% gewijzigd door Boomerang op 05-03-2003 20:21 ]


Acties:
  • 0 Henk 'm!

  • Nielsz
  • Registratie: Maart 2001
  • Niet online
Euh, tja een if na een die werkt niet zo goed he ;)
Pagina: 1