I have a problem when I try to extract from table (modele) all data from ‘marca’ (marca contains nokia, samsung, etc)
so I try to use $_GET but is is not working. I can select a line from table just with $_GET id but this does not help me, because I want to make categories selectable from links so sql inject like localhost/article.php?marca=nokia (must appear just nokia phones) I think is the best way.
For now I am using code wich shows me last 5 posts sorted by id but it is not working correctly because it show nokia, samsung, htc, nokia, other, nokia.
<?php require 'SQL.php';
$id = isset($_GET['id'])?(int)$_GET['id']:0; // daca $_GET['id'] exista, folosestel ca integer, altfel trucul sentinel, de obicei id incepe cu 1, deci 0 va functiona
if ($id!=0):
// Vom procesa daca exista doar 1 inregisrare in baza de date
$query = 'SELECT marca FROM modele WHERE id='. $id .' LIMIT 1'; // voi folosi 1, nemaiavand nevoie de alti pasi pentru lookup in sql
else:$query = 'SELECT marca FROM modele ORDER BY id DESC LIMIT 5';
endif;
$result = mysql_query($query);
// now loop through the results
while($linie = mysql_fetch_array($result))
{
// le voi utiliza dupa bunul plac
echo ''.$linie["marca"].'<br />';
}
?>
to work properly it must show me only nokia, nokia, nokia what’s missing?
If is another way, please let me know!
No, using the following query:
you are displaying all
marcafrommodeleyou should addwhereclause, e.g.You can retrieve the
marcaname from GET using$_GET["marca"].http://www.w3schools.com/php/php_get.asp
Read also about sql injection, cause I fell that you will get there.