Iets uit de database halen

Gestart doorJordyvc18 reacties30 weergaven

19 berichten · pagina 1 van 2

Jordyvc

Lid · Topicstarter

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

Ik heb al heel wat gezocht enz.. maar hoe kan ik iets uit de database halen en dat het werkt?
Want ik wil dat hij "naam" uit "product" haalt en sorteert op "id" en alleen de naam van het hoogste id echoet. Maar ik heb het opgezocht, en zelf in een boek gekeken die ik vorige jaar heb gekocht. En alles wat ik doe het werkt gewoon niet? Er komt niets te staan.
Kan iemand mij hier mee helpen aub?

Mvg,
Jordyvc
0
Berichten
15.446
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
wat is je code tot nu toe dan? Het is niet de bedoeling om je hier een complete code te gaan geven maar dat we je helpen met wat je al hebt smile
0
Jordyvc

Lid · Topicstarter

Berichten
6.037
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Marjolein schreef:
wat is je code tot nu toe dan? Het is niet de bedoeling om je hier een complete code te gaan geven maar dat we je helpen met wat je al hebt smile
$titel = mysql_query("SELECT naam FROM product " . mysql_real_escape_string($_GET[naam]) . " ORDER BY id DESC LIMIT 1") or die(mysql_error());


en den de echo:

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


IK weet dat de die op niets trekt. Maar die verander ik in de afwerking van het script!
0
Berichten
15.446
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
waarom staat " . mysql_real_escape_string($_GET[naam]) . " in je query, je haalt de naam toch al op?
0
Jordyvc

Lid · Topicstarter

Berichten
6.037
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Marjolein schreef:
waarom staat " . mysql_real_escape_string($_GET[naam]) . " in je query, je haalt de naam toch al op?
Omdat ik het niet weet bloos Daarom vraag ik aan jullie raad hypocrite
toevoeging op 4 juni 2012, 18:28:01:

$titel = mysql_query("SELECT naam FROM product ORDER BY id DESC LIMIT 1") or die(mysql_error());


toevoeging op 4 juni 2012, 18:28:29:
En nu blijft heel mijn pagina wit? redface
0
Jvdw

Lid

Berichten
4.321
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Haal die or die ding is weg
0
Jordyvc

Lid · Topicstarter

Berichten
6.037
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Jvdw schreef:
Haal die or die ding is weg
En mijn fouten afhandeling dan? En het blijft hetzelfde

toevoeging op 4 juni 2012, 18:53:49:
Nu krijg ik dit:
Resource id #5
0
Jvdw

Lid

Berichten
4.321
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php

$sql[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM product ORDER BY id DESC LIMIT 1"[/COLOR][COLOR= #007700]);[/COLOR]
    [COLOR= #0000BB]$blub[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_object"]mysql_fetch_object[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$blub[/COLOR][COLOR= #007700]->[/COLOR]naam[COLOR= #007700];[/COLOR]

?>


Werkt dit?

toevoeging op 4 juni 2012, 19:06:45:
Fouthandeling kanje zelf toevoegenyummie
0
Jordyvc

Lid · Topicstarter

Berichten
6.037
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Jvdw schreef:
[COLOR= #0000BB]<?php

$sql[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM product ORDER BY id DESC LIMIT 1"[/COLOR][COLOR= #007700]);[/COLOR]
    [COLOR= #0000BB]$blub[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_object"]mysql_fetch_object[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$blub[/COLOR][COLOR= #007700]->[/COLOR]naam[COLOR= #007700];[/COLOR]

?>
Werkt dit?

toevoeging op 4 juni 2012, 19:06:45:
Fouthandeling kanje zelf toevoegenyummie
Maar ik wil de naam eruit halen?
0
Jvdw

Lid

Berichten
4.321
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ja test is, war zou er fout aan zijn
0
Berichten
3.074
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Jvdw schreef:
[COLOR= #0000BB]<?php

$sql[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM product ORDER BY id DESC LIMIT 1"[/COLOR][COLOR= #007700]);[/COLOR]
    [COLOR= #0000BB]$blub[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_object"]mysql_fetch_object[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$blub[/COLOR][COLOR= #007700]->[/COLOR]naam[COLOR= #007700];[/COLOR]

?>
Werkt dit?

toevoeging op 4 juni 2012, 19:06:45:
Fouthandeling kanje zelf toevoegenyummie
Even off-topic, waarom mysql_fetch_object()? Ik zou in dit geval mysql_fetch_assoc(), omdat de resterende code niet object geörienteerd is. mysql_fetch_assoc() is ook sneller.
0
Jvdw

Lid

Berichten
4.321
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Joeey schreef:
Eerdere citaten tonen
Jvdw schreef:
[COLOR= #0000BB]<?php

$sql[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM product ORDER BY id DESC LIMIT 1"[/COLOR][COLOR= #007700]);[/COLOR]
    [COLOR= #0000BB]$blub[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_object"]mysql_fetch_object[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$blub[/COLOR][COLOR= #007700]->[/COLOR]naam[COLOR= #007700];[/COLOR]

?>
Werkt dit?

toevoeging op 4 juni 2012, 19:06:45:
Fouthandeling kanje zelf toevoegenyummie
Even off-topic, waarom mysql_fetch_object()? Ik zou in dit geval mysql_fetch_assoc(), omdat de resterende code niet object geörienteerd is. mysql_fetch_assoc() is ook sneller.

Weetik veel, ik heb een script gekocht en daar ging het zo. Dus als k iets bijscript doe ik het ookzobiggrin
0
Jordyvc

Lid · Topicstarter

Berichten
6.037
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Nu komt er array te staan?

toevoeging op 4 juni 2012, 19:21:42:
Zo moeilijk kan dat nu toch niet zijn? sadley
0
Jvdw

Lid

Berichten
4.321
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Jordyvc schreef:
Nu komt er array te staan?
toevoeging op 4 juni 2012, 19:21:42:
Zo moeilijk kan dat nu toch niet zijn? sadley
Staat er letterlijk array?
0
Jordyvc

Lid · Topicstarter

Berichten
6.037
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Jvdw schreef:
Eerdere citaten tonen
Jordyvc schreef:
Nu komt er array te staan?
toevoeging op 4 juni 2012, 19:21:42:
Zo moeilijk kan dat nu toch niet zijn? sadley
Staat er letterlijk array?
Ja
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