Vraagje over Script

Gestart doorBasDev8 reacties24 weergaven

9 berichten · pagina 1 van 1

BasDev

Lid · Topicstarter

Berichten
2.692
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hey,

Ik weet niet hoe ik hier zeg maar laat zien wat hij uit de database haalt:

[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$WEETIKNIETWAT[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]rij[/COLOR][COLOR= #007700]];[/COLOR] ?>


[COLOR= #0000BB]<?php
$table[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"topics"[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// naam van je mysql table[/COLOR]
[COLOR= #0000BB]$max[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]5[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// aantal items per pagina



// find out how many rows are in the table [/COLOR]
[COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"SELECT COUNT(*) FROM topics WHERE forumnaam = "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$searchname[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$result[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$r[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_row"]mysql_fetch_row[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$result[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$numrows[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$r[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700]];[/COLOR]

[COLOR= #FF8000]// find out total pages[/COLOR]
[COLOR= #0000BB]$totalpages[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/ceil"]ceil[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$numrows[/COLOR] / [COLOR= #0000BB]$max[/COLOR][COLOR= #007700]);[/COLOR]

[COLOR= #FF8000]// get the current page or set a default[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]currentpage[/COLOR][COLOR= #007700]]) &&[/COLOR] [URL="http://www.php.net/is_numeric"]is_numeric[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]currentpage[/COLOR][COLOR= #007700]])) {[/COLOR]
   [COLOR= #FF8000]// cast var as int[/COLOR]
   [COLOR= #0000BB]$currentpage[/COLOR] [COLOR= #007700]= (int)[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]currentpage[/COLOR][COLOR= #007700]];
}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
   [COLOR= #FF8000]// default page num[/COLOR]
   [COLOR= #0000BB]$currentpage[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700];
}[/COLOR] [COLOR= #FF8000]// end if

// if current page is greater than total pages...[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$currentpage[/COLOR] [COLOR= #007700]>[/COLOR] [COLOR= #0000BB]$totalpages[/COLOR][COLOR= #007700]) {[/COLOR]
   [COLOR= #FF8000]// set current page to last page[/COLOR]
   [COLOR= #0000BB]$currentpage[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$totalpages[/COLOR][COLOR= #007700];
}[/COLOR] [COLOR= #FF8000]// end if
// if current page is less than first page...[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$currentpage[/COLOR] [COLOR= #007700]<[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700]) {[/COLOR]
   [COLOR= #FF8000]// set current page to first page[/COLOR]
   [COLOR= #0000BB]$currentpage[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700];
}[/COLOR] [COLOR= #FF8000]// end if

// the offset of the list, based on current page [/COLOR]
[COLOR= #0000BB]$offset[/COLOR] [COLOR= #007700]= ([/COLOR][COLOR= #0000BB]$currentpage[/COLOR] [COLOR= #007700]-[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700]) *[/COLOR] [COLOR= #0000BB]$rowsperpage[/COLOR][COLOR= #007700];[/COLOR]

[COLOR= #FF8000]/******  build the pagination links ******/
// range of num links to show[/COLOR]
[COLOR= #0000BB]$range[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]3[/COLOR][COLOR= #007700];[/COLOR]

[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<ul id="pagination-digg">"[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #FF8000]// if not on page 1, dont show back links[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$currentpage[/COLOR] [COLOR= #007700]>[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700]) {[/COLOR]
   [COLOR= #FF8000]// get previous page num[/COLOR]
   [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]" <li class="next"><a href=forums2?name="[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$searchname[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]"&currentpage=1>«« Eerste pagina</a><li> "[/COLOR][COLOR= #007700];[/COLOR]
   [COLOR= #0000BB]$prevpage[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$currentpage[/COLOR] [COLOR= #007700]-[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700];[/COLOR]
   [COLOR= #FF8000]// show < link to go back to 1 page[/COLOR]
   [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]" <li class="next"><a href=forums2?name="[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$searchname[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]"&currentpage=$prevpage>« Vorige</a><li> "[/COLOR][COLOR= #007700];
}[/COLOR] [COLOR= #FF8000]// end if 

// loop to show links to range of pages around current page[/COLOR]
[URL="http://www.php.net/for"]for[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$x[/COLOR] [COLOR= #007700]= ([/COLOR][COLOR= #0000BB]$currentpage[/COLOR] [COLOR= #007700]-[/COLOR] [COLOR= #0000BB]$range[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #0000BB]$x[/COLOR] [COLOR= #007700]< (([/COLOR][COLOR= #0000BB]$currentpage[/COLOR] [COLOR= #007700]+[/COLOR] [COLOR= #0000BB]$range[/COLOR][COLOR= #007700]) +[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #0000BB]$x[/COLOR][COLOR= #007700]++) {[/COLOR]
   [COLOR= #FF8000]// if its a valid page number...[/COLOR]
   [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700](([/COLOR][COLOR= #0000BB]$x[/COLOR] [COLOR= #007700]>[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700]) && ([/COLOR][COLOR= #0000BB]$x[/COLOR] [COLOR= #007700]<=[/COLOR] [COLOR= #0000BB]$totalpages[/COLOR][COLOR= #007700])) {[/COLOR]
      [COLOR= #FF8000]// if were on current page...[/COLOR]
      [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$x[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]$currentpage[/COLOR][COLOR= #007700]) {[/COLOR]
         [COLOR= #FF8000]// highlight it but dont make a link[/COLOR]
         [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]" <li class="active">$x</li> "[/COLOR][COLOR= #007700];[/COLOR]
      [COLOR= #FF8000]// if not current page...[/COLOR]
      [COLOR= #007700]}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
         [COLOR= #FF8000]// make it a link[/COLOR]
         [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]" <li><a href=forums2?name="[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$searchname[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]"&currentpage=$x>$x</a><li> "[/COLOR][COLOR= #007700];
      }[/COLOR] [COLOR= #FF8000]// end else[/COLOR]
   [COLOR= #007700]}[/COLOR] [COLOR= #FF8000]// end if [/COLOR]
[COLOR= #007700]}[/COLOR] [COLOR= #FF8000]// end for
                 
// if not on last page, show forward and last page links        [/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$currentpage[/COLOR] [COLOR= #007700]!=[/COLOR] [COLOR= #0000BB]$totalpages[/COLOR][COLOR= #007700]) {[/COLOR]
   [COLOR= #FF8000]// get next page[/COLOR]
   [COLOR= #0000BB]$nextpage[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$currentpage[/COLOR] [COLOR= #007700]+[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700];[/COLOR]
    [COLOR= #FF8000]// echo forward link for next page [/COLOR]
   [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]" <li class="next"><a href=forums2?name="[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$searchname[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]"&currentpage=$nextpage>Volgende »</a></li> "[/COLOR][COLOR= #007700];[/COLOR]
   
   [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]" <li class="next"><a href=forums2?name="[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$searchname[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]"&currentpage=$totalpages>Laatste pagina »»</a></li> "[/COLOR][COLOR= #007700];
}[/COLOR] [COLOR= #FF8000]// end if
/****** end build pagination links ******/[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"</ul>"[/COLOR][COLOR= #007700];[/COLOR]
?>
0
Berichten
3.788
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
voeg onder result hetvolgende in:

[COLOR= #0000BB]<?php
$ding[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_object"]mysql_fetch_object[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$result[/COLOR][COLOR= #007700]);[/COLOR]
?>


En dan kan je het echooen met:

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$ding[/COLOR][COLOR= #007700]->[/COLOR]kolomnaam[COLOR= #007700];[/COLOR]
?>
0
Berichten
13.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
// find out how many rows are in the table 
$sql = "SELECT COUNT(*) FROM topics WHERE forumnaam = ".$searchname."";
$result = mysql_query($sql);
$r = mysql_fetch_row($result);
$numrows = $r[0];


dat?

maak er dit van

// find out how many rows are in the table 
$sql = "SELECT COUNT(1) FROM topics WHERE forumnaam = ".$searchname."";
$result = mysql_query($sql);
$numrows = mysql_result($result, 0);
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Eleky schreef:
voeg onder result hetvolgende in:
[COLOR= #0000BB]<?php
$ding[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_object"]mysql_fetch_object[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$result[/COLOR][COLOR= #007700]);[/COLOR]
?>


En dan kan je het echooen met:

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$ding[/COLOR][COLOR= #007700]->[/COLOR]kolomnaam[COLOR= #007700];[/COLOR]
?>


WTF @ Object gebruiken. Das echt de slechtse manier
0
Berichten
3.788
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
wat is er mis met fetch object?
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Eleky schreef:
wat is er mis met fetch object?
Dat objecten fetchen echt meer tijd kost. Gebruik dan mysql_fetch_assoc()
0
Berichten
3.788
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
het kan aan mij liggen, maar dan vind ik fetch_object makkelijker, dan hoef je er alleen maar -> achter te zetten, inplaats van tussen die haakjes...
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Eleky schreef:
het kan aan mij liggen, maar dan vind ik fetch_object makkelijker, dan hoef je er alleen maar -> achter te zetten, inplaats van tussen die haakjes...
Makkelijker is niet altijd beter wink
0
Berichten
3.788
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
tja...
Maar ik heb persoonlijk nooit het verschil gesnapt, maar we verpesten nu een topic
Afbeelding

Ik maak wel ff een ander topic!
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren