php - SQL Query succeeds but no information -
okay code works pretty far, goes through, problem when try , print unordered list , it's contents nothing. when view source code have <ul> </ul>
. there's space, surely happening.
this code, have commented what's happening obvious:
$uname = mysqli_real_escape_string($link, $_session['username']); //get username ready $sql = mysqli_query($link, "select * users username = '" . $uname . "'"); //sql query result if(!$sql) { echo "error retrieving user id. please try again. mysql error: " . mysqli_error($link); } elseif($row = mysqli_fetch_assoc($sql)) { $uid = $row['userid']; //obtain userid } else { echo "error: " . mysqli_error($link) . "<br />" . $uname . " / " . $sql . " / " . $uid; } mysqli_free_result($sql); $sql = mysqli_query($link, "select * auditions"); //get auditions table if(!$sql) { echo "error retrieving auditions. please try again later. error: " . mysqli_error($link); } elseif($row = mysqli_fetch_assoc($sql)) { if(mysqli_num_rows($sql)==0) { echo "sorry, there no open auditions. please try @ later date."; } else { echo "<ul>"; while($row = mysqli_fetch_assoc($sql)) { echo "<li><a href='auditions.php?id=" . $row['audid'] . "'>" . $row['audname'] . "</a></li>"; } echo "</ul>"; } } else { echo "error: " . mysqli_error($link); }
where going wrong? thing doesn't pick results , i've put data table there entries! otherwise there aren't any. i've reversed shows message if there aren't 0 entries , works. doing wrong guys?
thanks in advance.
you fetching result twice. instead, fetch result in while
loop:
<?php $sql = mysqli_query($link, "select * auditions"); //get auditions table if(!$sql) { echo "error retrieving auditions. please try again later. error: " . mysqli_error($link); } else{ if(mysqli_num_rows($sql)==0) { echo "sorry, there no open auditions. please try @ later date."; } else { echo "<ul>"; while($row = mysqli_fetch_assoc($sql)) { echo "<li><a href='auditions.php?id=" . $row['audid'] . "'>" . $row['audname'] . "</a></li>"; } echo "</ul>"; } } ?>
Comments
Post a Comment