[MySQL] data selecteren

Gestart doorOne2xs9 reacties11 weergaven

10 berichten · pagina 1 van 1

One2xs

Bot · Topicstarter

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Hoi,

Stel ik voer dit in:

SELECT a, b, c, d, e FROM table


Dan wil ik alle data uit table hebben met veldnaam a, b, c, d en e.
En als ik

SELECT * FROM table


doe, wil ik alle velden hebben uit table

Hoe doe ik dit?

Ik zat zelf te denken aan explode op de komma en dan met foreach er doorheen lopen?
Maar geen flauw idee hóe precies.

Groet,

Jesse
0
Berichten
35.796
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
Ben ik de enige die er niks van snapt? biggrin
0
Berichten
6.144
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
@ Lennard: Nee, ik snap dr ook niks van.

Kan je het misschien wat beter uitleggen?
0
One2xs

Bot · Topicstarter

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Stel, ik voer ergens in een script SELECT * FROM tabelnaam in, dan wil ik als resultaat ALLE velden uit tabelnaam met ALLE data die erin staat

dus als ik doe

SELECT password FROM users

wil ik dat ik alle wachtwoorden krijg van leden
wachtwoord1

wachtwoord2

etc..

En als ik dit doe
SELECT username, password FROM users
wil ik het zo:

naam1 - wachtwoord1

naam2 - wachtwoord2

naam3 - wachtwoord3

en als ik SELECT * FROM users
doe, wil ik dus alle velden uit de tabel users, met daarin alle data, dus net zoals phpMyAdmin het heeft zegmaar..

Dat met wachtwoord is maar een voorbeeld hoor emo.
0
Berichten
6.144
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php
$lQuery[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM tabel"[/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR]lQuery[COLOR= #007700]) {[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Er is een fout opgetreden: [/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]();
}[/COLOR]

[URL="http://www.php.net/while"]while[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$lFetch[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$lQuery[/COLOR][COLOR= #007700])) {[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$lFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]kolom[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]<br />[/COLOR][COLOR= #007700];
}[/COLOR]
?>
0
One2xs

Bot · Topicstarter

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Dan haalt hij alleen kolom op?
Ik wil dat hij ALLE kolommen ophaalt, de kolommen die hij moet weergeven moet dynamisch zijn.
dat moet bepaald worden a.d.h. van SELECT xxx FROM tabelnaam
0
Berichten
35.796
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
Zoiets bedoel je?

[COLOR= #0000BB]<?php
$q[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM dinges"[/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<table>[/COLOR][COLOR= #007700];[/COLOR]

[URL="http://www.php.net/while"]while[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$row[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$q[/COLOR][COLOR= #007700]))
{[/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]$showed[/COLOR][COLOR= #007700]))
    {[/COLOR]
        
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<tr>[/COLOR][COLOR= #007700];[/COLOR]
        
        [URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$row[/COLOR] [COLOR= #007700]as[/COLOR] [COLOR= #0000BB]$key[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #0000BB]$value[/COLOR][COLOR= #007700])
        {[/COLOR]
            
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<td>[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$key[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]</td>[/COLOR][COLOR= #007700];
            
        }[/COLOR]
        
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]</tr>[/COLOR][COLOR= #007700];[/COLOR]
        
        [COLOR= #0000BB]$showed[/COLOR] [COLOR= #007700]=[/COLOR] true[COLOR= #007700];
    
    }[/COLOR]
    
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<tr>[/COLOR][COLOR= #007700];[/COLOR]
    
    [URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$row[/COLOR] [COLOR= #007700]as[/COLOR] [COLOR= #0000BB]$value[/COLOR][COLOR= #007700])
    {[/COLOR]
        
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<td>[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$value[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]</td>[/COLOR][COLOR= #007700];
        
    }[/COLOR]
    
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]</tr>[/COLOR][COLOR= #007700];
    
}[/COLOR]

[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]</table>[/COLOR][COLOR= #007700];[/COLOR]
0
One2xs

Bot · Topicstarter

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
denk het wel ja, ben nu aan het testen.. Alleen de rest van mn script werkt ook niet echt lekker dus emo
toevoeging op 3 april 2012, 10:58:42:
Het werkt, bedankt biggrin.
0
Berichten
35.796
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
Nice, succes ermee smile
0
One2xs

Bot · Topicstarter

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Bedankt shiny
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