Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7196533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:47:44+00:00 2026-05-28T20:47:44+00:00

How can I echo out value after the while loop. If I do the

  • 0

How can I echo out value after the while loop. If I do the echo in below code its says Undefined index.

$sql_cast = "SELECT *
            FROM
              title_cast
              INNER JOIN title ON (title_cast.id_title = title.id)
              INNER JOIN `cast` ON (title_cast.id_cast = `cast`.id)
            WHERE
              title_cast.id_title = '1'";
$result_cast = mysql_query($sql_cast) or die('log error with' .mysql_error());
$cast = array();
while ($row = mysql_fetch_assoc($result_cast)) {
                $id = $row['id'];
                $name = $row['name'];
                $img = $row['photo_localurl'];
                $poster = str_replace("./", "lib/", $img);

                $cast[] = array('id' => $id, 'name' => $name, 'img' => $poster);
                //$cast[] = $row;
                }
                //var_dump($cast);
                echo $cast['id'] . " " . $cast['name'] . " " . $cast['poster']."<br />";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:47:45+00:00Added an answer on May 28, 2026 at 8:47 pm

    Within the while loop, you set the cast array content using $cast[] syntax. This will create a numerical index, starting at 0, then 1 and so on, so you’re creating an array that looks like this:

    $cast = array(
        0 => array('id' => $id, 'name' => $name, 'img' => $poster),
        1 => array('id' => $id, 'name' => $name, 'img' => $poster)
    );
    

    You need to include the numerical key of the array that you want to echo. For example, if you want to echo the first row:

    echo $cast[0]['id']; // Echo the id of the first result
    

    If you want to echo ALL of the rows, use foreach:

    foreach($cast as $row) {
        echo $row['id'];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't figure out why... This works: <?php if($_POST['test']) echo posted; ?> <form method=POST
My JavaScript knowledge is shallow, so I can't figure this out after some significant
Is there any way so that i can echo password when asked for in
I'm talking about the performance increase here. From all I know you can echo
how can i know version of echo command as specified in the man page
Can i do like this: <a href=# id=thelink onclick=window.parent.OpenVote(<? echo $_GET['id']; ?>, '<? echo
echo date(W,strtotime('2010-01-01')); This outputs 53. I would expect it to output 1. Can anyone
I understand that echo is slightly faster, and print can be used as a
Can you cast a List<int> to List<string> somehow? I know I could loop through
i want to echo out everything from a particular query. If echo $res I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.