1

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

2
  • why use $name = odbc_result($rs, 1);you should use array instead of string.if you not ,The last value will cover the previous value Commented Dec 12, 2017 at 10:44
  • @long i will try to do that :-? thank you! Commented Dec 12, 2017 at 10:59

1 Answer 1

2

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 }
} ?>
Sign up to request clarification or add additional context in comments.

2 Comments

This answer is better then mine! Deleted my answer. +1
Thank you very much! It's working! Not exactly on what i was thinking, but this result is very good. Thank you again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.