Reputation: 19
I'm working on my own project for a music site and i'm blocked on a situation. Right now i'm working on the playlist and i want to echo from php
(i'm working with odbc
connection) on html, but it's not putting all the data, only the first row, and i want all the data from database
to be echo in the playlist.
I tried to make an echo statement in php
which to send row by row with html code.
This is my PHP:
<?php
error_reporting(6);
include("connect.php");
include("checklogin.php");
$username = $_SESSION['username'];
//echo $username;
$sql="select name from [YourTube].[dbo].[yt_url]
where username='$user_check'";
$rs=odbc_exec($conn,$sql);
//echo $sql;
while(odbc_fetch_row($rs)){
$name = odbc_result($rs, 1);
//print("$name\n");
}
?>
And i have tried to put something like this in php>>
<?php if($rs) { ?>
<li class="list_item selected">
<div class="title" action="../php/songs.php"><?php echo
odbc_result($rs, 1)?></div>
</li>
<?php } ?>
And the result is just the first row from database
, but if i print $name it's showing all the rows.
The html code for playlist:
<div class="list_wrapper">
<ul class="list">
<li class="list_item selected">
<div class="info">
<div class="title" action="../php/songs.php"><?php echo
odbc_result($rs, 1)?></div>
</div>
</li>
</ul>
</div>
And like i said, this code on html
it's showing only one row in playlist, not all of them. And i'm thinking to do something like echo from php
in html code for every row something like this:
<li class="list_item selected">
<div class="info">
<div class="title" action="../php/songs.php"><?php echo
odbc_result($rs, 1)?></div>
</div>
</li>
Can someone help me with this? I'm working on this thing for some days and i can't figure out how to do it.
Thank you in advance! Bogdan
Upvotes: 1
Views: 132
Reputation: 72289
You have to apply while()
inside if()
like below:-
<?php if($rs) {
while(odbc_fetch_row($rs)){
?>
<li class="list_item selected">
<div class="title" action="../php/songs.php"><?php echo odbc_result($rs, 1)?></div>
</li>
<?php }
} ?>
Upvotes: 2