i'm new pdo, i'm using advised senior users in website. i'm trying data table using pdo, using while, can data "organized".
my query working, reason can't dump it.
heres code:
$sql = $conn->query("select id, nivel, tipo, titulo, texto, ativa account.quests_faq ativa='yes' order nivel desc"); while($row = $conn->fetch(pdo::fetch_assoc)){ if ($tipo=='main'){ echo '<li><a href="index.php?s=quest_info&id='$row['id']'"><font color="green">nivel '$row['nivel']' - '$row['titulo']'</font></a></li><br>'; }else{ echo '<li><a href="index.php?s=quest_info&id='$row['id']'"><font color="red">nivel '$row['nivel']' - '$row['titulo']'</font></a></li><br>'; } } so, in resume. have table titles, text , id. want data , echo it.
hope can me, sorry newb doubt.
edit 1:
$username = 'sssss'; $password = 'sssss'; $conn = new pdo('mysql:host=xxxxxxxx;dbname=account', $username, $password); $sql = "select id, nivel, tipo, titulo, texto, ativa account.quests_faq ativa='yes' order nivel desc"; $stmt = $conn->query($sql); while($row = $stmt->fetch(pdo::fetch_assoc)){ echo '<li><a href="index.php?s=quest_info&id='.$row['id'].'"><font color="green">nivel '.$row['nivel'].' - '.$row['titulo'].'</font></a></li><br>'; }else{ echo '<li><a href="index.php?s=quest_info&id='.$row['id'].'"><font color="red">nivel '.$row['nivel'].' - '.$row['titulo'].'</font></a></li><br>'; } }
well, advise given wrong.
not use learn.
have learn before using it.
there many tutorials on pdo around (all of them crappy ones though) @ least can learn proper syntax there
$sql = "select id, nivel, tipo, titulo, texto, ativa account.quests_faq ativa='yes' order nivel desc"; // string contains sql query. so, variable named $sql $stmt = $conn->query($sql); // in next line getting statement object function query() // why variable called $stmt while($row = $stmt->fetch(pdo::fetch_assoc)){ // , can start iterating statement. // statement, carl. not connection database // called $conn, if idea also have enable error reporting pdo.
and yes, said in other answer, php syntax wrong. supposed learn too, instead of banging random lines of code , asking others fix you.
start less complex syntax, echoing 1 single variable without decoration. , ask 1 question per post. pdo part got answer
Comments
Post a Comment